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

Python broker.run函数代码示例

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

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



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

示例1: setup

    def setup(self):
        """Add all roles to users."""
        threads = self.workers
        roles_dict = {}

        def publish(queue):
            for context_role in self.config:
                role = self._get_role_object(context_role)
                roles_dict[role.id] = role.name
                LOG.debug("Adding role %(role_name)s having ID %(role_id)s "
                          "to all users using %(threads)s threads"
                          % {"role_name": role.name,
                             "role_id": role.id,
                             "threads": threads})
                for user in self.context["users"]:
                    if "roles" not in user:
                        user["roles"] = self._get_user_role_ids(
                            user["id"],
                            user["tenant_id"])
                        user["assigned_roles"] = []
                    if role.id not in user["roles"]:
                        args = (role.id, user["id"], user["tenant_id"])
                        queue.append(args)
                        user["assigned_roles"].append(role.id)

        broker.run(publish, self._get_consumer("add_role"), threads)
        self.context["roles"] = roles_dict
开发者ID:jacobwagner,项目名称:rally,代码行数:27,代码来源:roles.py


示例2: _create_containers

    def _create_containers(self, context, containers_per_tenant, threads):
        """Create containers and store results in Rally context.

        :param context: dict, Rally context environment
        :param containers_per_tenant: int, number of containers to create
                                      per tenant
        :param threads: int, number of threads to use for broker pattern

        :returns: list of tuples containing (account, container)
        """
        containers = []

        def publish(queue):
            for user, tenant_id in (rutils.iterate_per_tenants(
                    context.get("users", []))):
                context["tenants"][tenant_id]["containers"] = []
                for i in range(containers_per_tenant):
                    args = (user, context["tenants"][tenant_id]["containers"])
                    queue.append(args)

        def consume(cache, args):
            user, tenant_containers = args
            if user["id"] not in cache:
                cache[user["id"]] = swift_utils.SwiftScenario({"user": user})
            container_name = cache[user["id"]]._create_container()
            tenant_containers.append({"user": user,
                                      "container": container_name,
                                      "objects": []})
            containers.append((user["tenant_id"], container_name))

        broker.run(publish, consume, threads)

        return containers
开发者ID:Pigueiras,项目名称:rally,代码行数:33,代码来源:utils.py


示例3: setup

    def setup(self):
        """Creates custom image(s) with preinstalled applications.

        When admin is present creates one public image that is usable
        from all the tenants and users. Otherwise create one image
        per user and tenant.
        """

        if "admin" in self.context:
            # NOTE(pboldin): Create by first user and make it public by
            #                the admin
            user = self.context["users"][0]
            tenant = self.context["tenants"][user["tenant_id"]]

            nics = None
            if "networks" in tenant:
                nics = [{"net-id": tenant["networks"][0]["id"]}]

            custom_image = self.create_one_image(user, nics=nics)
            self.make_image_public(custom_image)

            for tenant in self.context["tenants"].values():
                tenant["custom_image"] = custom_image
        else:
            def publish(queue):
                users = self.context.get("users", [])
                for user, tenant_id in utils.iterate_per_tenants(users):
                    queue.append((user, tenant_id))

            def consume(cache, args):
                user, tenant_id = args
                tenant = self.context["tenants"][tenant_id]
                tenant["custom_image"] = self.create_one_image(user)

            broker.run(publish, consume, self.config["workers"])
开发者ID:Vaidyanath,项目名称:rally,代码行数:35,代码来源:custom_image.py


示例4: _create_tenants

    def _create_tenants(self):
        threads = self.config["resource_management_workers"]

        tenants = collections.deque()

        def publish(queue):
            for i in range(self.config["tenants"]):
                args = (self.config["project_domain"], self.task["uuid"], i)
                queue.append(args)

        def consume(cache, args):
            domain, task_id, i = args
            if "client" not in cache:
                clients = osclients.Clients(self.credential)
                cache["client"] = keystone.wrap(clients.keystone())
            tenant = cache["client"].create_project(
                self.generate_random_name(), domain)
            tenant_dict = {"id": tenant.id, "name": tenant.name, "users": []}
            tenants.append(tenant_dict)

        # NOTE(msdubov): consume() will fill the tenants list in the closure.
        broker.run(publish, consume, threads)
        tenants_dict = {}
        for t in tenants:
            tenants_dict[t["id"]] = t

        return tenants_dict
开发者ID:GibeomOh,项目名称:rally,代码行数:27,代码来源:users.py


示例5: _delete_objects

    def _delete_objects(self, context, threads):
        """Delete objects created by Swift context and update Rally context.

        :param context: dict, Rally context environment
        :param threads: int, number of threads to use for broker pattern
        """
        def publish(queue):
            for tenant_id in context["tenants"]:
                containers = context["tenants"][tenant_id]["containers"]
                for container in containers:
                    for object_name in container["objects"][:]:
                        args = object_name, container
                        queue.append(args)

        def consume(cache, args):
            object_name, container = args
            user = container["user"]
            if user["id"] not in cache:
                cache[user["id"]] = swift_utils.SwiftScenario(
                    {"user": user, "task": context.get("task", {})})
            cache[user["id"]]._delete_object(container["container"],
                                             object_name)
            container["objects"].remove(object_name)

        broker.run(publish, consume, threads)
开发者ID:NaliniKrishna,项目名称:Rally,代码行数:25,代码来源:utils.py


示例6: _delete_users

    def _delete_users(self):
        threads = self.config["resource_management_workers"]

        def publish(queue):
            for user in self.context["users"]:
                queue.append(user["id"])

        broker.run(publish, self._get_consumer_for_deletion("delete_user"),
                   threads)
        self.context["users"] = []
开发者ID:GibeomOh,项目名称:rally,代码行数:10,代码来源:users.py


示例7: _delete_tenants

    def _delete_tenants(self):
        threads = self.config["resource_management_workers"]

        def publish(queue):
            for tenant_id in self.context["tenants"]:
                queue.append(tenant_id)

        broker.run(publish, self._get_consumer_for_deletion("delete_project"),
                   threads)
        self.context["tenants"] = {}
开发者ID:jacobwagner,项目名称:rally,代码行数:10,代码来源:users.py


示例8: _delete_envs

    def _delete_envs(self):
        threads = self.config["resource_management_workers"]

        def publish(queue):
            queue.extend(self.context["fuel"]["environments"])

        def consume(cache, env_id):
            self.fscenario._delete_environment(env_id)

        broker.run(publish, consume, threads)
        self.context["fuel"] = {}
开发者ID:Pigueiras,项目名称:rally,代码行数:11,代码来源:fuel.py


示例9: cleanup

    def cleanup(self):
        """Remove all roles from users."""
        threads = self.workers

        def publish(queue):
            for role_id in self.context["roles"]:
                LOG.debug("Removing role %s from all users" % (role_id))
                for user in self.context["users"]:
                    args = (role_id, user["id"], user["tenant_id"])
                    queue.append(args)

        broker.run(publish, self._get_consumer("remove_role"), threads)
开发者ID:NaliniKrishna,项目名称:Rally,代码行数:12,代码来源:roles.py


示例10: test_run

    def test_run(self):
        def publish(queue):
            queue.append(1)
            queue.append(2)
            queue.append(3)

        consumed = set()

        def consume(cache, item):
            consumed.add(item)

        consumer_count = 2
        broker.run(publish, consume, consumer_count)
        self.assertEqual(set([1, 2, 3]), consumed)
开发者ID:NeCTAR-RC,项目名称:rally,代码行数:14,代码来源:test_broker.py


示例11: _create_users

    def _create_users(self):
        # NOTE(msdubov): This should be called after _create_tenants().
        threads = self.config["resource_management_workers"]
        users_per_tenant = self.config["users_per_tenant"]
        default_role = cfg.CONF.openstack.keystone_default_role

        users = collections.deque()

        def publish(queue):
            for tenant_id in self.context["tenants"]:
                for user_id in range(users_per_tenant):
                    username = self.generate_random_name()
                    password = str(uuid.uuid4())
                    args = (username, password, self.config["project_domain"],
                            self.config["user_domain"], tenant_id)
                    queue.append(args)

        def consume(cache, args):
            username, password, project_dom, user_dom, tenant_id = args
            if "client" not in cache:
                clients = osclients.Clients(self.credential)
                cache["client"] = identity.Identity(
                    clients, name_generator=self.generate_random_name)
            client = cache["client"]
            user = client.create_user(username, password=password,
                                      project_id=tenant_id,
                                      domain_name=user_dom,
                                      default_role=default_role)
            user_credential = credential.OpenStackCredential(
                auth_url=self.credential["auth_url"],
                username=user.name,
                password=password,
                tenant_name=self.context["tenants"][tenant_id]["name"],
                permission=consts.EndpointPermission.USER,
                project_domain_name=project_dom,
                user_domain_name=user_dom,
                endpoint_type=self.credential["endpoint_type"],
                https_insecure=self.credential["https_insecure"],
                https_cacert=self.credential["https_cacert"],
                region_name=self.credential["region_name"],
                profiler_hmac_key=self.credential["profiler_hmac_key"],
                profiler_conn_str=self.credential["profiler_conn_str"])
            users.append({"id": user.id,
                          "credential": user_credential,
                          "tenant_id": tenant_id})

        # NOTE(msdubov): consume() will fill the users list in the closure.
        broker.run(publish, consume, threads)
        return list(users)
开发者ID:jacobwagner,项目名称:rally,代码行数:49,代码来源:users.py


示例12: _delete_users

    def _delete_users(self):
        threads = self.config["resource_management_workers"]

        def publish(queue):
            for user in self.context["users"]:
                queue.append(user["id"])

        def consume(cache, user_id):
            if "client" not in cache:
                clients = osclients.Clients(self.endpoint)
                cache["client"] = keystone.wrap(clients.keystone())
            cache["client"].delete_user(user_id)

        broker.run(publish, consume, threads)
        self.context["users"] = []
开发者ID:vishnu-kumar,项目名称:PeformanceFramework,代码行数:15,代码来源:users.py


示例13: _delete_tenants

    def _delete_tenants(self):
        threads = self.config["resource_management_workers"]

        self._remove_associated_networks()

        def publish(queue):
            for tenant_id in self.context["tenants"]:
                queue.append(tenant_id)

        def consume(cache, tenant_id):
            if "client" not in cache:
                clients = osclients.Clients(self.endpoint)
                cache["client"] = keystone.wrap(clients.keystone())
            cache["client"].delete_project(tenant_id)

        broker.run(publish, consume, threads)
        self.context["tenants"] = {}
开发者ID:vishnu-kumar,项目名称:PeformanceFramework,代码行数:17,代码来源:users.py


示例14: _create_users

    def _create_users(self):
        # NOTE(msdubov): This should be called after _create_tenants().
        threads = self.config["resource_management_workers"]
        users_per_tenant = self.config["users_per_tenant"]
        default_role = cfg.CONF.users_context.keystone_default_role

        users = collections.deque()

        def publish(queue):
            for tenant_id in self.context["tenants"]:
                for user_id in range(users_per_tenant):
                    username = self.generate_random_name()
                    password = str(uuid.uuid4())
                    args = (username, password, self.config["project_domain"],
                            self.config["user_domain"], tenant_id)
                    queue.append(args)

        def consume(cache, args):
            username, password, project_dom, user_dom, tenant_id = args
            if "client" not in cache:
                clients = osclients.Clients(self.credential)
                cache["client"] = keystone.wrap(clients.keystone())
            client = cache["client"]
            user = client.create_user(
                username, password,
                "%[email protected]" % username,
                tenant_id, user_dom,
                default_role=default_role)
            user_credential = objects.Credential(
                client.auth_url, user.name, password,
                self.context["tenants"][tenant_id]["name"],
                consts.EndpointPermission.USER, client.region_name,
                project_domain_name=project_dom, user_domain_name=user_dom,
                endpoint_type=self.credential.endpoint_type,
                https_insecure=self.credential.insecure,
                https_cacert=self.credential.cacert)
            users.append({"id": user.id,
                          "credential": user_credential,
                          "tenant_id": tenant_id})

        # NOTE(msdubov): consume() will fill the users list in the closure.
        broker.run(publish, consume, threads)
        return list(users)
开发者ID:gluke77,项目名称:rally,代码行数:43,代码来源:users.py


示例15: _create_objects

    def _create_objects(self, context, objects_per_container, object_size,
                        threads):
        """Create objects and store results in Rally context.

        :param context: dict, Rally context environment
        :param objects_per_container: int, number of objects to create
                                      per container
        :param object_size: int, size of created swift objects in byte
        :param threads: int, number of threads to use for broker pattern

        :returns: list of tuples containing (account, container, object)
        """
        objects = []

        with tempfile.TemporaryFile() as dummy_file:
            # set dummy file to specified object size
            dummy_file.truncate(object_size)

            def publish(queue):
                for tenant_id in context["tenants"]:
                    containers = context["tenants"][tenant_id]["containers"]
                    for container in containers:
                        for i in range(objects_per_container):
                            queue.append(container)

            def consume(cache, container):
                user = container["user"]
                if user["id"] not in cache:
                    cache[user["id"]] = swift_utils.SwiftScenario(
                        {"user": user})
                dummy_file.seek(0)
                object_name = cache[user["id"]]._upload_object(
                    container["container"],
                    dummy_file)[1]
                container["objects"].append(object_name)
                objects.append((user["tenant_id"], container["container"],
                                object_name))

            broker.run(publish, consume, threads)

        return objects
开发者ID:Pigueiras,项目名称:rally,代码行数:41,代码来源:utils.py


示例16: _create_envs

    def _create_envs(self):
        threads = self.config["resource_management_workers"]

        envs = collections.deque()

        def publish(queue):
            kwargs = {"release_id": self.config["release_id"],
                      "network_provider": self.config["network_provider"],
                      "deployment_mode": self.config["deployment_mode"],
                      "net_segment_type": self.config["net_segment_type"]}

            for i in range(self.config["environments"]):
                queue.append(kwargs)

        def consume(cache, kwargs):
            env_id = self.fscenario._create_environment(**kwargs)
            envs.append(env_id)

        broker.run(publish, consume, threads)

        return list(envs)
开发者ID:Pigueiras,项目名称:rally,代码行数:21,代码来源:fuel.py


示例17: _delete_containers

    def _delete_containers(self, context, threads):
        """Delete containers created by Swift context and update Rally context.

        :param context: dict, Rally context environment
        :param threads: int, number of threads to use for broker pattern
        """
        def publish(queue):
            for tenant_id in context["tenants"]:
                containers = context["tenants"][tenant_id]["containers"]
                for container in containers[:]:
                    args = container, containers
                    queue.append(args)

        def consume(cache, args):
            container, tenant_containers = args
            user = container["user"]
            if user["id"] not in cache:
                cache[user["id"]] = swift_utils.SwiftScenario({"user": user})
            cache[user["id"]]._delete_container(container["container"])
            tenant_containers.remove(container)

        broker.run(publish, consume, threads)
开发者ID:Pigueiras,项目名称:rally,代码行数:22,代码来源:utils.py


示例18: cleanup

    def cleanup(self):
        """Delete created custom image(s)."""

        if "admin" in self.context:
            user = self.context["users"][0]
            tenant = self.context["tenants"][user["tenant_id"]]
            if "custom_image" in tenant:
                self.delete_one_image(user, tenant["custom_image"])
                tenant.pop("custom_image")
        else:
            def publish(queue):
                users = self.context.get("users", [])
                for user, tenant_id in utils.iterate_per_tenants(users):
                    queue.append((user, tenant_id))

            def consume(cache, args):
                user, tenant_id = args
                tenant = self.context["tenants"][tenant_id]
                if "custom_image" in tenant:
                    self.delete_one_image(user, tenant["custom_image"])
                    tenant.pop("custom_image")

            broker.run(publish, consume, self.config["workers"])
开发者ID:Vaidyanath,项目名称:rally,代码行数:23,代码来源:custom_image.py


示例19: exterminate

    def exterminate(self):
        """Delete all resources for passed users, admin and resource_mgr."""

        broker.run(self._gen_publisher(), self._gen_consumer(),
                   consumers_count=self.manager_cls._threads)
开发者ID:aarefiev22,项目名称:rally,代码行数:5,代码来源:manager.py


示例20: test_task_samples_are_valid

    def test_task_samples_are_valid(self):
        rally = utils.Rally(force_new_db=True)

        # let's use pre-created users to make TestTaskSamples quicker
        rapi = api.API(config_file=rally.config_filename)
        deployment = rapi.deployment._get("MAIN")
        admin_cred = deployment.get_credentials_for("openstack")["admin"]

        ctx = {
            "env": {
                "platforms": {
                    "openstack": {
                        "admin": admin_cred.to_dict(),
                        "users": []}}},
            "task": {"uuid": self.__class__.__name__,
                     "deployment_uuid": deployment["uuid"]}}
        user_ctx = users.UserGenerator(ctx)
        user_ctx.setup()
        self.addCleanup(user_ctx.cleanup)

        os_creds = deployment["config"]["openstack"]

        user = copy.copy(os_creds["admin"])
        user["username"] = ctx["users"][0]["credential"].username
        user["password"] = ctx["users"][0]["credential"].password
        if "project_name" in os_creds["admin"]:
            # it is Keystone
            user["project_name"] = ctx["users"][0]["credential"].tenant_name
        else:
            user["tenant_name"] = ctx["users"][0]["credential"].tenant_name
        os_creds["users"] = [user]

        rally("deployment destroy MAIN", write_report=False)
        deployment_cfg = os.path.join(rally.tmp_dir, "new_deployment.json")
        with open(deployment_cfg, "w") as f:
            f.write(json.dumps({"openstack": os_creds}))
        rally("deployment create --name MAIN --filename %s" % deployment_cfg,
              write_report=False)

        # NOTE(andreykurilin): mock building credential to share one cache of
        #   clients(it will allow to avoid hundreds of redundant
        #   authentications) between validations of different samples
        deployment = rapi.deployment._get("MAIN")
        original_get_credentials_for = deployment.get_credentials_for
        creds_cache = {}

        def get_credentials_for(platform):
            if platform not in creds_cache:
                creds_cache[platform] = original_get_credentials_for(
                    platform)
            return creds_cache[platform]

        deployment.get_credentials_for = get_credentials_for

        deployment_patcher = mock.patch("rally.api.objects.Deployment.get")
        m_deployment = deployment_patcher.start()
        m_deployment.return_value = deployment
        self.addCleanup(deployment_patcher.stop)

        # store all failures and print them at once
        failed_samples = {}

        def publisher(queue):
            """List all samples and render task configs"""
            samples_path = os.path.join(
                os.path.dirname(rally_module.__file__), os.pardir,
                "samples", "tasks")

            for dirname, dirnames, filenames in os.walk(samples_path):
                # NOTE(rvasilets): Skip by suggest of boris-42 because in
                # future we don't what to maintain this dir
                if dirname.find("tempest-do-not-run-against-production") != -1:
                    continue
                for filename in filenames:
                    full_path = os.path.join(dirname, filename)

                    # NOTE(hughsaunders): Skip non config files
                    # (bug https://bugs.launchpad.net/rally/+bug/1314369)
                    if os.path.splitext(filename)[1] != ".json":
                        continue
                    with open(full_path) as task_file:
                        input_task = task_file.read()
                        rendered_task = rapi.task.render_template(
                            task_template=input_task)
                        queue.append((full_path, rendered_task))

        def consumer(_cache, sample):
            """Validate one sample"""
            full_path, rendered_task = sample
            task_config = yaml.safe_load(rendered_task)
            try:
                rapi.task.validate(deployment="MAIN",
                                   config=task_config)
            except Exception as e:
                if not self._skip(six.text_type(e)):
                    failed_samples[full_path] = traceback.format_exc()

        broker.run(publisher, consumer, self.NUMBER_OF_THREADS)

        if failed_samples:
#.........这里部分代码省略.........
开发者ID:jacobwagner,项目名称:rally,代码行数:101,代码来源:test_task_samples.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python db.deployment_create函数代码示例发布时间:2022-05-26
下一篇:
Python envutils.get_global函数代码示例发布时间: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