• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python discover.itersubclasses函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中rally.common.plugin.discover.itersubclasses函数的典型用法代码示例。如果您正苦于以下问题:Python itersubclasses函数的具体用法?Python itersubclasses怎么用?Python itersubclasses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了itersubclasses函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_res_manager_special_field

    def test_res_manager_special_field(self):

        for res_mgr in discover.itersubclasses(base.ResourceManager):
            manager_name = "%s.%s" % (res_mgr.__module__, res_mgr.__name__)

            fields = filter(lambda x: not x.startswith("__"), dir(res_mgr))

            available_opts = set(
                [
                    "_admin_required",
                    "_perform_for_admin_only",
                    "_tenant_resource",
                    "_service",
                    "_resource",
                    "_order",
                    "_max_attempts",
                    "_timeout",
                    "_interval",
                    "_threads",
                    "_manager",
                    "id",
                    "is_deleted",
                    "delete",
                    "list",
                    "supports_extension",
                ]
            )

            extra_opts = set(fields) - available_opts

            self.assertFalse(
                extra_opts,
                ("ResourceManager %(name)s contains extra fields: %(opts)s." " Remove them to pass this test")
                % {"name": manager_name, "opts": ", ".join(extra_opts)},
            )
开发者ID:hayderimran7,项目名称:rally,代码行数:35,代码来源:test_resources.py


示例2: find_resource_managers

def find_resource_managers(names=None, admin_required=None):
    """Returns resource managers.

    :param names: List of names in format <service> or <service>.<resource>
                  that is used for filtering resource manager classes
    :param admin_required: None -> returns all ResourceManagers
                           True -> returns only admin ResourceManagers
                           False -> returns only non admin ResourceManagers
    """
    names = set(names or [])

    resource_managers = []
    for manager in discover.itersubclasses(base.ResourceManager):
        if admin_required is not None:
            if admin_required != manager._admin_required:
                continue

        if (manager._service in names
           or "%s.%s" % (manager._service, manager._resource) in names):
            resource_managers.append(manager)

    resource_managers.sort(key=lambda x: x._order)

    found_names = set()
    for mgr in resource_managers:
        found_names.add(mgr._service)
        found_names.add("%s.%s" % (mgr._service, mgr._resource))

    missing = names - found_names
    if missing:
        LOG.warning("Missing resource managers: %s" % ", ".join(missing))

    return resource_managers
开发者ID:rvbaz,项目名称:rally,代码行数:33,代码来源:manager.py


示例3: test_all_scenarios_have_docstrings

    def test_all_scenarios_have_docstrings(self):
        ignored_params = ["self", "scenario_obj"]
        for scenario_group in discover.itersubclasses(scenario.Scenario):
            if scenario_group.__module__.startswith("tests."):
                continue

            for method in dir(scenario_group):
                if scenario.Scenario.is_scenario(scenario_group, method):
                    scenario_inst = getattr(scenario_group, method)
                    scenario_name = scenario_group.__name__ + "." + method
                    self.assertIsNotNone(scenario_inst.__doc__,
                                         "%s doensn't have a docstring." %
                                         scenario_name)
                    doc = utils.parse_docstring(scenario_inst.__doc__)
                    short_description = doc["short_description"]
                    self.assertIsNotNone(short_description,
                                         "Docstring for %s should have "
                                         "at least a one-line description." %
                                         scenario_name)
                    self.assertFalse(short_description.startswith("Test"),
                                     "One-line description for %s "
                                     "should be declarative and not start "
                                     "with 'Test(s) ...'" % scenario_name)
                    params_count = scenario_inst.__code__.co_argcount
                    params = scenario_inst.__code__.co_varnames[:params_count]
                    documented_params = [p["name"] for p in doc["params"]]
                    for param in params:
                        if param not in ignored_params:
                            self.assertIn(param, documented_params,
                                          "Docstring for %(scenario)s should "
                                          "describe the '%(param)s' parameter "
                                          "in the :param <name>: clause." %
                                          {"scenario": scenario_name,
                                           "param": param})
开发者ID:go-bears,项目名称:rally,代码行数:34,代码来源:test_docstrings.py


示例4: list

 def list(self):
     managers_classes = discover.itersubclasses(ResourceManager)
     resources = []
     for cls in managers_classes:
         manager = cls(self.clients)
         if manager.is_available():
             resources.extend(manager.get_resources())
     return sorted(self._deduplicate(resources))
开发者ID:rvbaz,项目名称:rally,代码行数:8,代码来源:osresources.py


示例5: list

 def list(self):
     # NOTE(stpierre): any plugin can create a nova network via the
     # network wrapper, and that network's name will be created
     # according to its owner's random name generation
     # parameters. so we need to check if there are nova networks
     # whose name pattern matches those of any loaded plugin that
     # implements RandomNameGeneratorMixin
     classes = list(discover.itersubclasses(utils.RandomNameGeneratorMixin))
     return [net for net in self._manager().list()
             if utils.name_matches_object(net.label, *classes)]
开发者ID:alinbalutoiu,项目名称:rally,代码行数:10,代码来源:resources.py


示例6: test_itersubclasses_with_type

    def test_itersubclasses_with_type(self):
        class A(type):
            pass

        class B(A):
            pass

        class C(B):
            pass

        self.assertEqual([B, C], list(discover.itersubclasses(A)))
开发者ID:andreykurilin,项目名称:rally,代码行数:11,代码来源:test_discover.py


示例7: find_exception

def find_exception(response):
    """Discover a proper exception class based on response object."""
    global _exception_map
    if _exception_map is None:
        _exception_map = dict(
            (e.error_code, e) for e in discover.itersubclasses(RallyException))
    exc_class = _exception_map.get(response.status_code, RallyException)

    error_data = response.json()["error"]
    if error_data["args"]:
        return exc_class(error_data["args"])
    return exc_class(error_data["msg"])
开发者ID:andreykurilin,项目名称:rally,代码行数:12,代码来源:exceptions.py


示例8: _get_descriptions

 def _get_descriptions(self, base_cls, subclass_filter=None):
     descriptions = []
     subclasses = discover.itersubclasses(base_cls)
     if subclass_filter:
         subclasses = filter(subclass_filter, subclasses)
     for entity in subclasses:
         name = entity.get_name()
         doc = utils.parse_docstring(entity.__doc__)
         description = doc["short_description"] or ""
         descriptions.append((name, description))
     descriptions.sort(key=lambda d: d[0])
     return descriptions
开发者ID:NeCTAR-RC,项目名称:rally,代码行数:12,代码来源:info.py


示例9: test_itersubclasses_with_multiple_inheritance

    def test_itersubclasses_with_multiple_inheritance(self):
        class A(object):
            pass

        class B(A):
            pass

        class C(A):
            pass

        class D(B, C):
            pass

        self.assertEqual([B, D, C], list(discover.itersubclasses(A)))
开发者ID:andreykurilin,项目名称:rally,代码行数:14,代码来源:test_discover.py


示例10: test_itersubclasses

    def test_itersubclasses(self):
        class A(object):
            pass

        class B(A):
            pass

        class C(A):
            pass

        class D(C):
            pass

        self.assertEqual([B, C, D], list(discover.itersubclasses(A)))
开发者ID:andreykurilin,项目名称:rally,代码行数:14,代码来源:test_discover.py


示例11: get_all

    def get_all(cls, namespace=None):
        """Return all subclass plugins of plugin.

        All plugins that are not configured will be ignored.

        :param namespace: return only plugins from specified namespace.
        """
        plugins = []

        for p in discover.itersubclasses(cls):
            if issubclass(p, Plugin) and p._meta_is_inited(raise_exc=False):
                if not namespace or namespace == p.get_namespace():
                    plugins.append(getattr(p, "func_ref", p))

        return plugins
开发者ID:NaliniKrishna,项目名称:Rally,代码行数:15,代码来源:plugin.py


示例12: get_scenario_by_name

    def get_scenario_by_name(name):
        """Return benchmark scenario method by name.

        :param name: name of the benchmark scenario being searched for (either
                     a full name (e.g, 'NovaServers.boot_server') or just
                     a method name (e.g., 'boot_server')
        :returns: function object
        """
        if "." in name:
            scenario_group, scenario_name = name.split(".", 1)
            scenario_cls = Scenario.get_by_name(scenario_group)
            if Scenario.is_scenario(scenario_cls, scenario_name):
                return getattr(scenario_cls, scenario_name)
        else:
            for scenario_cls in discover.itersubclasses(Scenario):
                if Scenario.is_scenario(scenario_cls, name):
                    return getattr(scenario_cls, name)
        raise exceptions.NoSuchScenario(name=name)
开发者ID:vefimova,项目名称:rally,代码行数:18,代码来源:base.py


示例13: cleanup

def cleanup(names=None, admin_required=None, admin=None, users=None,
            api_versions=None, superclass=plugin.Plugin, task_id=None):
    """Generic cleaner.

    This method goes through all plugins. Filter those and left only plugins
    with _service from services or _resource from resources.

    Then goes through all passed users and using cleaners cleans all related
    resources.

    :param names: Use only resource managers that have names in this list.
                  There are in as _service or
                  (%s.%s % (_service, _resource)) from
    :param admin_required: If None -> return all plugins
                           If True -> return only admin plugins
                           If False -> return only non admin plugins
    :param admin: rally.deployment.credential.Credential that corresponds to
                  OpenStack admin.
    :param users: List of OpenStack users that was used during testing.
                  Every user has next structure:
                  {
                    "id": <uuid1>,
                    "tenant_id": <uuid2>,
                    "credential": <rally.deployment.credential.Credential>
                  }
    :param superclass: The plugin superclass to perform cleanup
                       for. E.g., this could be
                       ``rally.task.scenario.Scenario`` to cleanup all
                       Scenario resources.
    :param task_id: The UUID of task
    """
    resource_classes = [cls for cls in discover.itersubclasses(superclass)
                        if issubclass(cls, rutils.RandomNameGeneratorMixin)]
    if not resource_classes and issubclass(superclass,
                                           rutils.RandomNameGeneratorMixin):
        resource_classes.append(superclass)
    for manager in find_resource_managers(names, admin_required):
        LOG.debug("Cleaning up %(service)s %(resource)s objects"
                  % {"service": manager._service,
                     "resource": manager._resource})
        SeekAndDestroy(manager, admin, users,
                       api_versions=api_versions,
                       resource_classes=resource_classes,
                       task_id=task_id).exterminate()
开发者ID:andreykurilin,项目名称:rally,代码行数:44,代码来源:manager.py


示例14: _get_all_plugins_bases

    def _get_all_plugins_bases(self):
        """Return grouped and sorted all plugins bases."""
        bases = []
        bases_names = []
        for p in discover.itersubclasses(plugin.Plugin):
            base_ref = getattr(p, "base_ref", None)
            if base_ref == p:
                name = self._parse_class_name(p)
                if name in bases_names:
                    raise Exception("Two base classes with same name '%s' are "
                                    "detected." % name)
                bases_names.append(name)
                category_of_base = "Common"
                for cname, cbases in CATEGORIES.items():
                    if name in cbases:
                        category_of_base = cname

                bases.append((category_of_base, name, p))
        return sorted(bases)
开发者ID:jacobwagner,项目名称:rally,代码行数:19,代码来源:plugin_reference.py


示例15: list_benchmark_scenarios

    def list_benchmark_scenarios(scenario_cls):
        """List all scenarios in the benchmark scenario class & its subclasses.

        Returns the method names in format <Class name>.<Method name>, which
        is used in the test config.

        :param scenario_cls: the base class for searching scenarios in
        :returns: List of strings
        """
        scenario_classes = (list(discover.itersubclasses(scenario_cls)) +
                            [scenario_cls])
        benchmark_scenarios = [
            ["%s.%s" % (scenario.__name__, func)
             for func in dir(scenario) if Scenario.is_scenario(scenario, func)]
            for scenario in scenario_classes
        ]
        benchmark_scenarios_flattened = list(
            itertools.chain.from_iterable(benchmark_scenarios))
        return benchmark_scenarios_flattened
开发者ID:vefimova,项目名称:rally,代码行数:19,代码来源:base.py


示例16: list_resource_names

def list_resource_names(admin_required=None):
    """List all resource managers names.

    Returns all service names and all combination of service.resource names.

    :param admin_required: None -> returns all ResourceManagers
                           True -> returns only admin ResourceManagers
                           False -> returns only non admin ResourceManagers
    """
    res_mgrs = discover.itersubclasses(base.ResourceManager)
    if admin_required is not None:
        res_mgrs = filter(lambda cls: cls._admin_required == admin_required, res_mgrs)

    names = set()
    for cls in res_mgrs:
        names.add(cls._service)
        names.add("%s.%s" % (cls._service, cls._resource))

    return names
开发者ID:hkumarmk,项目名称:rally,代码行数:19,代码来源:manager.py


示例17: get_all

    def get_all(cls, platform=None, allow_hidden=False, name=None):
        """Return all subclass plugins of plugin.

        All plugins that are not configured will be ignored.
        :param platform: return only plugins for specific platform.
        :param name: return only plugins with specified name.
        :param allow_hidden: if False return only non hidden plugins
        """
        plugins = []

        for p in discover.itersubclasses(cls):
            if not issubclass(p, Plugin):
                continue
            if not p._meta_is_inited(raise_exc=False):
                continue
            if name and name != p.get_name():
                continue
            if platform and platform != p.get_platform():
                continue
            if not allow_hidden and p.is_hidden():
                continue
            plugins.append(p)

        return plugins
开发者ID:jacobwagner,项目名称:rally,代码行数:24,代码来源:plugin.py


示例18: test_all_scenario_groups_have_docstrings

 def test_all_scenario_groups_have_docstrings(self):
     for scenario_group in discover.itersubclasses(scenario.Scenario):
         self._assert_class_has_docstrings(scenario_group,
                                           long_description=False)
开发者ID:go-bears,项目名称:rally,代码行数:4,代码来源:test_docstrings.py


示例19: test_all_SLA_have_docstrings

 def test_all_SLA_have_docstrings(self):
     for s in discover.itersubclasses(sla.SLA):
         self._assert_class_has_docstrings(s, long_description=False)
开发者ID:go-bears,项目名称:rally,代码行数:3,代码来源:test_docstrings.py


示例20: get_by_name

 def get_by_name(name):
     """Returns Scenario class by name."""
     for scenario in discover.itersubclasses(Scenario):
         if name == scenario.__name__:
             return scenario
     raise exceptions.NoSuchScenario(name=name)
开发者ID:vefimova,项目名称:rally,代码行数:6,代码来源:base.py



注:本文中的rally.common.plugin.discover.itersubclasses函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python plugin.configure函数代码示例发布时间:2022-05-26
下一篇:
Python logging.is_debug函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap