当前位置: 首页>>代码示例>>Python>>正文


Python utils.interruptable_sleep函数代码示例

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


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

示例1: _create_cluster

    def _create_cluster(self, cluster_template, node_count, **kwargs):
        """Create a cluster

        :param cluster_template: cluster_template for the cluster
        :param node_count: the cluster node count
        :param kwargs: optional additional arguments for cluster creation
        :returns: magnum cluster
        """

        name = self.generate_random_name()
        cluster = self.clients("magnum").clusters.create(
            name=name, cluster_template_id=cluster_template,
            node_count=node_count, **kwargs)

        common_utils.interruptable_sleep(
            CONF.openstack.magnum_cluster_create_prepoll_delay)
        cluster = utils.wait_for_status(
            cluster,
            ready_statuses=["CREATE_COMPLETE"],
            update_resource=utils.get_from_manager(),
            timeout=CONF.openstack.magnum_cluster_create_timeout,
            check_interval=CONF.openstack.magnum_cluster_create_poll_interval,
            id_attr="uuid"
        )
        return cluster
开发者ID:jacobwagner,项目名称:rally,代码行数:25,代码来源:utils.py

示例2: create_snapshot

    def create_snapshot(self, volume_id, force=False,
                        name=None, description=None, metadata=None):
        """Create one snapshot.

        Returns when the snapshot is actually created and is in the "Available"
        state.

        :param volume_id: volume uuid for creating snapshot
        :param force: flag to indicate whether to snapshot a volume even if
                      it's attached to an instance
        :param name: Name of the snapshot
        :param description: Description of the snapshot
        :returns: Created snapshot object
        """
        kwargs = {"force": force,
                  "name": name or self.generate_random_name(),
                  "description": description,
                  "metadata": metadata}

        snapshot = self._get_client().volume_snapshots.create(volume_id,
                                                              **kwargs)
        rutils.interruptable_sleep(
            CONF.openstack.cinder_volume_create_prepoll_delay)
        snapshot = self._wait_available_volume(snapshot)
        return snapshot
开发者ID:jacobwagner,项目名称:rally,代码行数:25,代码来源:cinder_v2.py

示例3: _create_v1rc

    def _create_v1rc(self, manifest):
        """Create rc on the specify cluster.

        :param manifest: manifest use to create the replication controller
        """
        k8s_api = self._get_k8s_api_client()
        suffix = "-"
        for i in range(5):
            suffix = suffix + random.choice(string.ascii_lowercase)
        rcname = manifest["metadata"]["name"] + suffix
        manifest["metadata"]["name"] = rcname
        resp = k8s_api.create_namespaced_replication_controller(
            body=manifest,
            namespace="default")
        expectd_status = resp.spec.replicas
        start = time.time()
        while True:
            resp = k8s_api.read_namespaced_replication_controller(
                name=rcname,
                namespace="default")
            status = resp.status.replicas
            if status == expectd_status:
                return resp
            else:
                if time.time() - start > CONF.openstack.k8s_rc_create_timeout:
                    raise exceptions.TimeoutException(
                        desired_status=expectd_status,
                        resource_name=rcname,
                        resource_type="ReplicationController",
                        resource_id=resp.metadata.uid,
                        resource_status=status,
                        timeout=CONF.openstack.k8s_rc_create_timeout)
                common_utils.interruptable_sleep(
                    CONF.openstack.k8s_rc_create_poll_interval)
开发者ID:jacobwagner,项目名称:rally,代码行数:34,代码来源:utils.py

示例4: _create_bay

    def _create_bay(self, baymodel, node_count, **kwargs):
        """Create a bay

        :param baymodel: baymodel for the bay
        :param node_count: the bay node count
        :param kwargs: optional additional arguments for bay creation
        :returns: magnum bay
        """

        name = self.generate_random_name()
        bay = self.clients("magnum").bays.create(
            name=name, baymodel_id=baymodel,
            node_count=node_count, **kwargs)

        common_utils.interruptable_sleep(
            CONF.benchmark.magnum_bay_create_prepoll_delay)
        bay = utils.wait_for_status(
            bay,
            ready_statuses=["CREATE_COMPLETE"],
            update_resource=utils.get_from_manager(),
            timeout=CONF.benchmark.magnum_bay_create_timeout,
            check_interval=CONF.benchmark.magnum_bay_create_poll_interval,
            id_attr="uuid"
        )
        return bay
开发者ID:obutenko,项目名称:rally,代码行数:25,代码来源:utils.py

示例5: _delete_single_resource

    def _delete_single_resource(self, resource):
        """Safe resource deletion with retries and timeouts.

        Send request to delete resource, in case of failures repeat it few
        times. After that pull status of resource until it's deleted.

        Writes in LOG warning with UUID of resource that wasn't deleted

        :param resource: instance of resource manager initiated with resource
                         that should be deleted.
        """

        msg_kw = {
            "uuid": resource.id(),
            "name": resource.name() or "",
            "service": resource._service,
            "resource": resource._resource
        }

        LOG.debug(
            "Deleting %(service)s %(resource)s object %(name)s (%(uuid)s)" %
            msg_kw)

        try:
            rutils.retry(resource._max_attempts, resource.delete)
        except Exception as e:
            msg_kw["reason"] = e
            LOG.warning(
                _("Resource deletion failed, max retries exceeded for "
                  "%(service)s.%(resource)s: %(uuid)s. Reason: %(reason)s")
                % msg_kw)
            if logging.is_debug():
                LOG.exception(e)
        else:
            started = time.time()
            failures_count = 0
            while time.time() - started < resource._timeout:
                try:
                    if resource.is_deleted():
                        return
                except Exception as e:
                    LOG.warning(
                        _("Seems like %s.%s.is_deleted(self) method is broken "
                          "It shouldn't raise any exceptions.")
                        % (resource.__module__, type(resource).__name__))
                    LOG.exception(e)

                    # NOTE(boris-42): Avoid LOG spamming in case of bad
                    #                 is_deleted() method
                    failures_count += 1
                    if failures_count > resource._max_attempts:
                        break

                finally:
                    rutils.interruptable_sleep(resource._interval)

            LOG.warning(_("Resource deletion failed, timeout occurred for "
                          "%(service)s.%(resource)s: %(uuid)s.")
                        % msg_kw)
开发者ID:asimonet,项目名称:rally,代码行数:59,代码来源:manager.py

示例6: run

    def run(self, number_of_actions=5, sleep_factor=1):
        """Run some sleepy atomic actions for SLA atomic action tests.

        :param number_of_actions: int number of atomic actions to create
        :param sleep_factor: int multiplier for number of seconds to sleep
        """
        for sleeptime in range(number_of_actions):
            with atomic.ActionTimer(self, "action_%d" % sleeptime):
                utils.interruptable_sleep(sleeptime * sleep_factor)
开发者ID:obutenko,项目名称:rally,代码行数:9,代码来源:dummy.py

示例7: create_volume

    def create_volume(self, size, consistencygroup_id=None,
                      snapshot_id=None, source_volid=None, name=None,
                      description=None, volume_type=None, user_id=None,
                      project_id=None, availability_zone=None,
                      metadata=None, imageRef=None, scheduler_hints=None,
                      source_replica=None, multiattach=False):
        """Creates a volume.

        :param size: Size of volume in GB
        :param consistencygroup_id: ID of the consistencygroup
        :param snapshot_id: ID of the snapshot
        :param name: Name of the volume
        :param description: Description of the volume
        :param volume_type: Type of volume
        :param user_id: User id derived from context
        :param project_id: Project id derived from context
        :param availability_zone: Availability Zone to use
        :param metadata: Optional metadata to set on volume creation
        :param imageRef: reference to an image stored in glance
        :param source_volid: ID of source volume to clone from
        :param source_replica: ID of source volume to clone replica
        :param scheduler_hints: (optional extension) arbitrary key-value pairs
                            specified by the client to help boot an instance
        :param multiattach: Allow the volume to be attached to more than
                            one instance

        :returns: Return a new volume.
        """
        kwargs = {"name": name or self.generate_random_name(),
                  "description": description,
                  "consistencygroup_id": consistencygroup_id,
                  "snapshot_id": snapshot_id,
                  "source_volid": source_volid,
                  "volume_type": volume_type,
                  "user_id": user_id,
                  "project_id": project_id,
                  "availability_zone": availability_zone,
                  "metadata": metadata,
                  "imageRef": imageRef,
                  "scheduler_hints": scheduler_hints,
                  "source_replica": source_replica,
                  "multiattach": multiattach}
        if isinstance(size, dict):
            size = random.randint(size["min"], size["max"])

        volume = (self._get_client()
                  .volumes.create(size, **kwargs))

        # NOTE(msdubov): It is reasonable to wait 5 secs before starting to
        #                check whether the volume is ready => less API calls.
        rutils.interruptable_sleep(
            CONF.openstack.cinder_volume_create_prepoll_delay)

        return self._wait_available_volume(volume)
开发者ID:jacobwagner,项目名称:rally,代码行数:54,代码来源:cinder_v2.py

示例8: delete

 def delete(self, env_id, retries=5, retry_pause=0.5):
     env = self.get(env_id)
     retry_number = 0
     while env:
         if retry_number > retries:
             raise RuntimeError(_("Can't delete environment "
                                  "id: %s ") % env_id)
         try:
             self.client.delete_by_id(env_id)
         except BaseException:
             rutils.interruptable_sleep(retry_pause)
         env = self.get(env_id)
         retry_number += 1
开发者ID:alinbalutoiu,项目名称:rally,代码行数:13,代码来源:utils.py

示例9: create_image

    def create_image(self, container_format, image_location,
                     disk_format, **kwargs):
        kw = {
            "container_format": container_format,
            "disk_format": disk_format,
        }
        kw.update(kwargs)
        if "name" not in kw:
            kw["name"] = self.owner.generate_random_name()
        if "is_public" in kw:
            LOG.warning("is_public is not supported by Glance v2, and is "
                        "deprecated in Rally v0.8.0")
            kw["visibility"] = "public" if kw.pop("is_public") else "private"

        image_location = os.path.expanduser(image_location)

        image = self.client.images.create(**kw)

        rutils.interruptable_sleep(CONF.openstack.
                                   glance_image_create_prepoll_delay)

        start = time.time()
        image = utils.wait_for_status(
            image, ["queued"],
            update_resource=self.get_image,
            timeout=CONF.openstack.glance_image_create_timeout,
            check_interval=CONF.openstack.
            glance_image_create_poll_interval)
        timeout = time.time() - start

        image_data = None
        response = None
        try:
            if os.path.isfile(image_location):
                image_data = open(image_location)
            else:
                response = requests.get(image_location, stream=True)
                image_data = response.raw
            self.client.images.upload(image.id, image_data)
        finally:
            if image_data is not None:
                image_data.close()
            if response is not None:
                response.close()

        return utils.wait_for_status(
            image, ["active"],
            update_resource=self.get_image,
            timeout=timeout,
            check_interval=CONF.openstack.
            glance_image_create_poll_interval)
开发者ID:jacobwagner,项目名称:rally,代码行数:51,代码来源:glance.py

示例10: create_image

    def create_image(self, image_name=None, container_format=None,
                     image_location=None, disk_format=None,
                     is_public=True, min_disk=0, min_ram=0,
                     properties=None):
        """Creates new image.

        :param image_name: Image name for which need to be created
        :param container_format: Container format
        :param image_location: The new image's location
        :param disk_format: Disk format
        :param is_public: The created image's public status
        :param min_disk: The min disk of created images
        :param min_ram: The min ram of created images
        :param properties: Dict of image properties
        """
        image_location = os.path.expanduser(image_location)
        image_name = image_name or self.generate_random_name()
        kwargs = {}

        try:
            if os.path.isfile(image_location):
                kwargs["data"] = open(image_location)
            else:
                kwargs["copy_from"] = image_location

            image_obj = self._clients.glance("1").images.create(
                name=image_name,
                container_format=container_format,
                disk_format=disk_format,
                is_public=is_public,
                min_disk=min_disk,
                min_ram=min_ram,
                properties=properties,
                **kwargs)

            rutils.interruptable_sleep(CONF.openstack.
                                       glance_image_create_prepoll_delay)

            image_obj = utils.wait_for_status(
                image_obj, ["active"],
                update_resource=self.get_image,
                timeout=CONF.openstack.glance_image_create_timeout,
                check_interval=CONF.openstack.glance_image_create_poll_interval
            )

        finally:
            if "data" in kwargs:
                kwargs["data"].close()

        return image_obj
开发者ID:andreykurilin,项目名称:rally,代码行数:50,代码来源:glance_v1.py

示例11: run

    def run(self, size_of_message=1, sleep=1, message=""):
        """Throws an exception.

        Dummy.dummy_exception used for testing if exceptions are processed
        properly by task engine and analyze rally results storing & displaying
        capabilities.

        :param size_of_message: int size of the exception message
        :param sleep: idle time of method (in seconds).
        :param message: message of the exception
        :raises DummyScenarioException: raise exception for test
        """
        utils.interruptable_sleep(sleep)

        message = message or "M" * size_of_message
        raise DummyScenarioException(message)
开发者ID:andreykurilin,项目名称:rally,代码行数:16,代码来源:dummy.py

示例12: create_image

    def create_image(self, container_format, image_location,
                     disk_format, **kwargs):
        kw = {
            "container_format": container_format,
            "disk_format": disk_format,
        }
        kw.update(kwargs)
        if "name" not in kw:
            kw["name"] = self.owner.generate_random_name()

        image_location = os.path.expanduser(image_location)

        image = self.client.images.create(**kw)

        rutils.interruptable_sleep(CONF.benchmark.
                                   glance_image_create_prepoll_delay)

        start = time.time()
        image = utils.wait_for_status(
            image, ["queued"],
            update_resource=self.get_image,
            timeout=CONF.benchmark.glance_image_create_timeout,
            check_interval=CONF.benchmark.
            glance_image_create_poll_interval)
        timeout = time.time() - start

        image_data = None
        response = None
        try:
            if os.path.isfile(image_location):
                image_data = open(image_location)
            else:
                response = requests.get(image_location, stream=True)
                image_data = response.raw
            self.client.images.upload(image.id, image_data)
        finally:
            if image_data is not None:
                image_data.close()
            if response is not None:
                response.close()

        return utils.wait_for_status(
            image, ["active"],
            update_resource=self.get_image,
            timeout=timeout,
            check_interval=CONF.benchmark.
            glance_image_create_poll_interval)
开发者ID:alinbalutoiu,项目名称:rally,代码行数:47,代码来源:glance.py

示例13: create_image

    def create_image(self, image_name=None, container_format=None,
                     image_location=None, disk_format=None,
                     visibility=None, min_disk=0,
                     min_ram=0, properties=None):
        """Creates new image.

        :param image_name: Image name for which need to be created
        :param container_format: Container format
        :param image_location: The new image's location
        :param disk_format: Disk format
        :param visibility: The created image's visible status.
        :param min_disk: The min disk of created images
        :param min_ram: The min ram of created images
        :param properties: Dict of image properties
        """
        image_name = image_name or self.generate_random_name()

        properties = properties or {}
        image_obj = self._clients.glance("2").images.create(
            name=image_name,
            container_format=container_format,
            disk_format=disk_format,
            visibility=visibility,
            min_disk=min_disk,
            min_ram=min_ram,
            **properties)

        rutils.interruptable_sleep(CONF.openstack.
                                   glance_image_create_prepoll_delay)

        start = time.time()
        image_obj = utils.wait_for_status(
            image_obj.id, ["queued"],
            update_resource=self.get_image,
            timeout=CONF.openstack.glance_image_create_timeout,
            check_interval=CONF.openstack.glance_image_create_poll_interval)
        timeout = time.time() - start

        self.upload_data(image_obj.id, image_location=image_location)

        image_obj = utils.wait_for_status(
            image_obj, ["active"],
            update_resource=self.get_image,
            timeout=timeout,
            check_interval=CONF.openstack.glance_image_create_poll_interval)
        return image_obj
开发者ID:andreykurilin,项目名称:rally,代码行数:46,代码来源:glance_v2.py

示例14: create_volume

    def create_volume(self, size, snapshot_id=None, source_volid=None,
                      display_name=None, display_description=None,
                      volume_type=None, user_id=None,
                      project_id=None, availability_zone=None,
                      metadata=None, imageRef=None):
        """Creates a volume.

        :param size: Size of volume in GB
        :param snapshot_id: ID of the snapshot
        :param display_name: Name of the volume
        :param display_description: Description of the volume
        :param volume_type: Type of volume
        :param user_id: User id derived from context
        :param project_id: Project id derived from context
        :param availability_zone: Availability Zone to use
        :param metadata: Optional metadata to set on volume creation
        :param imageRef: reference to an image stored in glance

        :returns: Return a new volume.
        """
        if isinstance(size, dict):
            size = random.randint(size["min"], size["max"])

        volume = self._get_client().volumes.create(
            size,
            display_name=(display_name or self.generate_random_name()),
            display_description=display_description,
            snapshot_id=snapshot_id,
            source_volid=source_volid,
            volume_type=volume_type,
            user_id=user_id,
            project_id=project_id,
            availability_zone=availability_zone,
            metadata=metadata,
            imageRef=imageRef
        )

        # NOTE(msdubov): It is reasonable to wait 5 secs before starting to
        #                check whether the volume is ready => less API calls.
        rutils.interruptable_sleep(
            CONF.openstack.cinder_volume_create_prepoll_delay)

        return self._wait_available_volume(volume)
开发者ID:andreykurilin,项目名称:rally,代码行数:43,代码来源:cinder_v1.py

示例15: setup

    def setup(self):
        new_metric = {}

        if "dimensions" in self.config:
            new_metric = {
                "dimensions": self.config["dimensions"]
            }

        for user, tenant_id in rutils.iterate_per_tenants(
                self.context["users"]):
            scenario = monasca_utils.MonascaScenario(
                context={"user": user, "task": self.context["task"]}
            )
            for i in moves.xrange(self.config["metrics_per_tenant"]):
                scenario._create_metrics(**new_metric)
                rutils.interruptable_sleep(0.001)
        rutils.interruptable_sleep(
            monasca_utils.CONF.benchmark.monasca_metric_create_prepoll_delay,
            atomic_delay=1)
开发者ID:alinbalutoiu,项目名称:rally,代码行数:19,代码来源:metrics.py


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