Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    def check_metric(self, seed, sleep_time, retries_total):
        """Check metric with seed name in Grafana datasource.

        :param seed: random metric name
        :param sleep_time: sleep time between checking metrics in seconds
        :param retries_total: total number of retries to check metric in
                              Grafana
        :return: True if metric in Grafana datasource and False otherwise
        """
        check_url = ("http://%(vip)s:%(port)s/api/datasources/proxy/:"
                     "%(datasource)s/api/v1/query?query=%(seed)s" % {
                         "vip": self._spec["monitor_vip"],
                         "port": self._spec["grafana"]["port"],
                         "datasource": self._spec["datasource_id"],
                         "seed": seed
                     })
        i = 0
        LOG.info("Check metric %s in Grafana" % seed)
        while i < retries_total:
            LOG.debug("Attempt number %s" % (i + 1))
            resp = requests.get(check_url,
                                auth=(self._spec["grafana"]["user"],
                                      self._spec["grafana"]["password"]))
            result = resp.json()
            LOG.debug("Grafana response code: %s" % resp.status_code)
            if len(result["data"]["result"]) < 1 and i + 1 >= retries_total:
                LOG.debug("No instance metrics found in Grafana")
                return False
            elif len(result["data"]["result"]) < 1:
                i += 1
                commonutils.interruptable_sleep(sleep_time)
            else:
                LOG.debug("Metric instance found in Grafana")
                return True
Ejemplo n.º 3
0
def wait_for_status(name, status, read_method, resource_type=None, **kwargs):
    """Util method for polling status until it won't be equals to `status`.

    :param name: resource name
    :param status: status waiting for
    :param read_method: method to poll
    :param resource_type: resource type for extended exceptions
    :param kwargs: additional kwargs for read_method
    """
    sleep_time = CONF.kubernetes.status_poll_interval
    retries_total = CONF.kubernetes.status_total_retries

    commonutils.interruptable_sleep(CONF.kubernetes.start_prepoll_delay)

    i = 0
    while i < retries_total:
        resp = read_method(name=name, **kwargs)
        resp_id = resp.metadata.uid
        current_status = resp.status.phase
        if resp.status.phase != status:
            i += 1
            commonutils.interruptable_sleep(sleep_time)
        else:
            return
        if i == retries_total:
            raise exceptions.TimeoutException(desired_status=status,
                                              resource_name=name,
                                              resource_type=resource_type,
                                              resource_id=resp_id or "<no id>",
                                              resource_status=current_status,
                                              timeout=(retries_total *
                                                       sleep_time))
Ejemplo n.º 4
0
    def delete_pod(self, name, namespace, sleep_time=5, retries_total=30):
        """Delete pod from namespace.

        :param name: pod's name
        :param namespace: pod's namespace
        :param sleep_time: sleep time between each two retries
        :param retries_total: total number of retries
        :returns True if delete successful and False otherwise
        """
        resp = self.api.delete_namespaced_pod(name=name,
                                              namespace=namespace,
                                              body=client.V1DeleteOptions())
        LOG.info("Pod %(name)s delete started. Status: %(status)s" % {
            "name": name,
            "status": resp.status
        })

        i = 0
        while i < retries_total:
            LOG.debug("Attempt number %s" % i)
            try:
                self.api.read_namespaced_pod_status(name=name,
                                                    namespace=namespace)
            except Exception:
                return True
            else:
                commonutils.interruptable_sleep(sleep_time)
                i += 1
        return False
Ejemplo n.º 5
0
def wait_for_not_found(name, read_method, resource_type=None, **kwargs):
    """Util method for polling status while resource exists.

    :param name: resource name
    :param read_method: method to poll
    :param resource_type: resource type for extended exceptions
    :param kwargs: additional kwargs for read_method
    """
    sleep_time = CONF.kubernetes.status_poll_interval
    retries_total = CONF.kubernetes.status_total_retries

    commonutils.interruptable_sleep(CONF.kubernetes.start_prepoll_delay)

    i = 0
    while i < retries_total:
        try:
            resp = read_method(name=name, **kwargs)
            resp_id = resp.metadata.uid
            current_status = resp.status.phase
        except rest.ApiException as ex:
            if ex.status == 404:
                return
            else:
                raise
        else:
            commonutils.interruptable_sleep(sleep_time)
            i += 1
        if i == retries_total:
            raise exceptions.TimeoutException(desired_status="Terminated",
                                              resource_name=name,
                                              resource_type=resource_type,
                                              resource_id=resp_id or "<no id>",
                                              resource_status=current_status,
                                              timeout=(retries_total *
                                                       sleep_time))
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
    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)

        image_location = os.path.expanduser(image_location)
        rutils.interruptable_sleep(CONF.benchmark.
                                   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.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._clients.glance("2").images.upload(image_obj.id, image_data)
        finally:
            if image_data is not None:
                image_data.close()
            if response is not None:
                response.close()

        image_obj = utils.wait_for_status(
            image_obj, ["active"],
            update_resource=self.get_image,
            timeout=timeout,
            check_interval=CONF.benchmark.glance_image_create_poll_interval)
        return image_obj
Ejemplo n.º 9
0
    def delete_rc(self, name, namespace, sleep_time=5, retries_total=30):
        """Delete RC from namespace and wait until it won't be terminated.

        :param name: replication controller name
        :param namespace: namespace name of defined RC
        :param sleep_time: sleep time between each two retries
        :param retries_total: total number of retries
        :returns True if delete successful and False otherwise
        """
        resp = self.api.delete_namespaced_replication_controller(
            name=name, namespace=namespace, body=client.V1DeleteOptions())
        LOG.info("RC %(name)s delete started. Status: %(status)s" % {
            "name": name,
            "status": resp.status
        })

        i = 0
        while i < retries_total:
            LOG.debug("Attempt number %s" % i)
            try:
                self.api.read_namespaced_replication_controller_status(
                    name=name, namespace=namespace)
            except Exception:
                return True
            else:
                commonutils.interruptable_sleep(sleep_time)
                i += 1
        return False
Ejemplo n.º 10
0
    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
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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
Ejemplo n.º 13
0
    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.benchmark.cinder_volume_create_prepoll_delay)
        snapshot = self._wait_available_volume(snapshot)
        return snapshot
Ejemplo n.º 14
0
    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):
        """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 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
        }
        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)
Ejemplo n.º 15
0
    def create_namespace_and_wait_active(self,
                                         name,
                                         sleep_time=5,
                                         retries_total=30):
        """Create namespace and wait until status phase won't be Active.

        :param name: namespace name
        :param sleep_time: sleep time between each two retries
        :param retries_total: total number of retries
        :return: True if create successful and False otherwise
        """
        self.create_namespace(name)

        i = 0
        LOG.debug("Wait until namespace status won't be active")
        while i < retries_total:
            LOG.debug("Attempt number %s" % i)
            try:
                resp = self.api.read_namespace(name=name)
            except Exception as ex:
                LOG.warning("Unable to read namespace status: %s" % ex.message)
                i += 1
                commonutils.interruptable_sleep(sleep_time)
            else:
                if resp.status.phase != "Active":
                    i += 1
                    commonutils.interruptable_sleep(sleep_time)
                else:
                    return True
        return False
Ejemplo n.º 16
0
    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)
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
Archivo: dummy.py Proyecto: zioc/rally
    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)
Ejemplo n.º 19
0
    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)
Ejemplo n.º 20
0
    def run(self, sleep=0):
        """Do nothing and sleep for the given number of seconds (0 by default).

        Dummy.dummy can be used for testing performance of different
        ScenarioRunners and of the ability of rally to store a large
        amount of results.

        :param sleep: idle time of method (in seconds).
        """
        utils.interruptable_sleep(sleep)
Ejemplo n.º 21
0
Archivo: dummy.py Proyecto: zioc/rally
    def run(self, sleep=0):
        """Do nothing and sleep for the given number of seconds (0 by default).

        Dummy.dummy can be used for testing performance of different
        ScenarioRunners and of the ability of rally to store a large
        amount of results.

        :param sleep: idle time of method (in seconds).
        """
        utils.interruptable_sleep(sleep)
Ejemplo n.º 22
0
    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, "rb")
            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
Ejemplo n.º 23
0
    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)
Ejemplo n.º 24
0
Archivo: dummy.py Proyecto: zioc/rally
    def run(self, actions_num=5, sleep_min=0, sleep_max=2):
        """Sleep random time in dummy actions.

        :param actions_num: int number of actions to generate
        :param sleep_min: minimal time to sleep, numeric seconds
        :param sleep_max: maximum time to sleep, numeric seconds
        """
        for idx in range(actions_num):
            duration = random.uniform(sleep_min, sleep_max)
            with atomic.ActionTimer(self, "action_%d" % idx):
                utils.interruptable_sleep(duration)
Ejemplo n.º 25
0
    def run(self, actions_num=5, sleep_min=0, sleep_max=2):
        """Sleep random time in dummy actions.

        :param actions_num: int number of actions to generate
        :param sleep_min: minimal time to sleep, numeric seconds
        :param sleep_max: maximum time to sleep, numeric seconds
        """
        for idx in range(actions_num):
            duration = random.uniform(sleep_min, sleep_max)
            with atomic.ActionTimer(self, "action_%d" % idx):
                utils.interruptable_sleep(duration)
Ejemplo n.º 26
0
Archivo: utils.py Proyecto: zioc/rally
 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
Ejemplo n.º 27
0
    def run(self, image, port, protocol, command=None, status_wait=True):
        """Create pod and clusterIP svc, check with curl job, delete then.

        :param image: pod's image
        :param port: pod's container port and svc port integer
        :param protocol: pod's container port and svc port protocol
        :param command: pod's array of strings representing command
        :param status_wait: wait for pod status if True
        """
        namespace = self.choose_namespace()
        labels = {"app": self.generate_random_name()}

        name = self.client.create_pod(image,
                                      namespace=namespace,
                                      command=command,
                                      port=port,
                                      protocol=protocol,
                                      labels=labels,
                                      status_wait=status_wait)

        self.client.create_service(name,
                                   namespace=namespace,
                                   port=port,
                                   protocol=protocol,
                                   type="ClusterIP",
                                   labels=labels)

        commonutils.interruptable_sleep(CONF.kubernetes.start_prepoll_delay)

        endpoints = self.client.get_endpoints(name, namespace=namespace)
        ips = []
        for subset in endpoints.subsets:
            addrs = [addr.ip for addr in subset.addresses]
            ports = [p.port for p in subset.ports]
            ips.extend(["%s:%s" % (a, p) for a in addrs for p in ports])

        command = ["curl"]
        command.extend(ips)
        self.client.create_job(name,
                               namespace=namespace,
                               image="appropriate/curl",
                               command=command,
                               status_wait=True)

        self.client.delete_job(name,
                               namespace=namespace,
                               status_wait=status_wait)
        self.client.delete_service(name, namespace=namespace)
        self.client.delete_pod(name,
                               namespace=namespace,
                               status_wait=status_wait)
Ejemplo n.º 28
0
    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
Ejemplo n.º 29
0
    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)
Ejemplo n.º 30
0
    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
Ejemplo n.º 31
0
    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.
        """
        kwargs = {
            "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
        }
        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.benchmark.cinder_volume_create_prepoll_delay)

        return self._wait_available_volume(volume)
Ejemplo n.º 32
0
Archivo: dummy.py Proyecto: zioc/rally
    def run(self, sleep=0.1, from_iteration=0, to_iteration=0, each=1):
        """Raise errors in some iterations.

        :param sleep: float iteration sleep time in seconds
        :param from_iteration: int iteration number which starts range
                             of failed iterations
        :param to_iteration: int iteration number which ends range of
                             failed iterations
        :param each: int cyclic number of iteration which actually raises
                     an error in selected range. For example, each=3 will
                     raise error in each 3rd iteration.
        """
        utils.interruptable_sleep(sleep)
        if from_iteration <= self.context["iteration"] <= to_iteration:
            if each and not self.context["iteration"] % each:
                raise DummyScenarioException(_("Expected failure"))
Ejemplo n.º 33
0
    def run(self, size_of_message=1, sleep=1, message=""):
        """Throw an exception.

        Dummy.dummy_exception can be used for test if exceptions are processed
        properly by ScenarioRunners and benchmark and analyze rally
        results storing process.

        :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)
Ejemplo n.º 34
0
    def run(self, sleep=0.1, from_iteration=0, to_iteration=0, each=1):
        """Raise errors in some iterations.

        :param sleep: float iteration sleep time in seconds
        :param from_iteration: int iteration number which starts range
                             of failed iterations
        :param to_iteration: int iteration number which ends range of
                             failed iterations
        :param each: int cyclic number of iteration which actually raises
                     an error in selected range. For example, each=3 will
                     raise error in each 3rd iteration.
        """
        utils.interruptable_sleep(sleep)
        if from_iteration <= self.context["iteration"] <= to_iteration:
            if each and not self.context["iteration"] % each:
                raise DummyScenarioException(_("Expected failure"))
Ejemplo n.º 35
0
    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)
Ejemplo n.º 36
0
Archivo: dummy.py Proyecto: sapcc/rally
    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)
Ejemplo n.º 37
0
Archivo: dummy.py Proyecto: zioc/rally
    def run(self, size_of_message=1, sleep=1, message=""):
        """Throw an exception.

        Dummy.dummy_exception can be used for test if exceptions are processed
        properly by ScenarioRunners and benchmark and analyze rally
        results storing process.

        :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)
Ejemplo n.º 38
0
Archivo: glance.py Proyecto: zioc/rally
    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)
Ejemplo n.º 39
0
    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
Ejemplo n.º 40
0
    def setup(self):
        self.context["kubernetes"].update({
            "namespace_choice_method": self.config["namespace_choice_method"],
            "serviceaccounts": self.config.get("with_serviceaccount") or False,
            "serviceaccount_delay": self.config.get("serviceaccount_delay") or 0
        })

        self.context["kubernetes"].setdefault("namespaces", [])
        for _ in range(self.config.get("count")):
            name = self.client.create_namespace(status_wait=False)
            self.context["kubernetes"]["namespaces"].append(name)
            if self.config.get("with_serviceaccount"):
                self.client.create_serviceaccount(name, namespace=name)
                self.client.create_secret(name, namespace=name)
                commonutils.interruptable_sleep(
                    self.context["kubernetes"]["serviceaccount_delay"]
                )
Ejemplo n.º 41
0
    def setup(self):
        new_metric = {}

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

        for user, tenant_id in self._iterate_per_tenants():
            scenario = monasca_utils.MonascaScenario(
                context={
                    "user": user,
                    "task": self.context["task"]
                })
            for i in range(self.config["metrics_per_tenant"]):
                scenario._create_metrics(**new_metric)
                rutils.interruptable_sleep(0.001)
        rutils.interruptable_sleep(
            monasca_utils.CONF.openstack.monasca_metric_create_prepoll_delay,
            atomic_delay=1)
Ejemplo n.º 42
0
    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)
Ejemplo n.º 43
0
    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)
Ejemplo n.º 44
0
 def _check_server_name(self, name, logging_vip, elasticsearch_port,
                        sleep_time, retries_total):
     request_data = {
         "query": {
             "bool": {
                 "must": [{
                     "match_phrase": {
                         "Payload": name
                     }
                 }],
                 "should": [{
                     "range": {
                         "Timestamp": {
                             "gte": "now-2m",
                             "lte": "now"
                         }
                     }
                 }],
                 "minimum_should_match":
                 1
             }
         }
     }
     LOG.info("Check server name %s in elasticsearch" % name)
     i = 0
     while i < retries_total:
         LOG.debug("Attempt number %s" % (i + 1))
         resp = requests.get("http://%(ip)s:%(port)s/_search" % {
             "ip": logging_vip,
             "port": elasticsearch_port
         },
                             data=json.dumps(request_data))
         result = resp.json()
         if result["hits"]["total"] < 1 and i + 1 >= retries_total:
             LOG.debug("No instance data found in Elasticsearch")
             self.assertGreater(result["hits"]["total"], 0)
         elif result["hits"]["total"] < 1:
             i += 1
             commonutils.interruptable_sleep(sleep_time)
         else:
             LOG.debug("Instance data found in Elasticsearch")
             self.assertGreater(result["hits"]["total"], 0)
             break
Ejemplo n.º 45
0
    def sleep_between(self, min_sleep, max_sleep, atomic_delay=0.1):
        """Call an interruptable_sleep() for a random amount of seconds.

        The exact time is chosen uniformly randomly from the interval
        [min_sleep; max_sleep). The method also updates the idle_duration
        variable to take into account the overall time spent on sleeping.

        :param min_sleep: Minimum sleep time in seconds (non-negative)
        :param max_sleep: Maximum sleep time in seconds (non-negative)
        :param atomic_delay: parameter with which  time.sleep would be called
                             int(sleep_time / atomic_delay) times.
        """
        if not 0 <= min_sleep <= max_sleep:
            raise exceptions.InvalidArgumentsException(
                "0 <= min_sleep <= max_sleep")

        sleep_time = random.uniform(min_sleep, max_sleep)
        utils.interruptable_sleep(sleep_time, atomic_delay)
        self._idle_duration += sleep_time
Ejemplo n.º 46
0
    def sleep_between(self, min_sleep, max_sleep, atomic_delay=0.1):
        """Call an interruptable_sleep() for a random amount of seconds.

        The exact time is chosen uniformly randomly from the interval
        [min_sleep; max_sleep). The method also updates the idle_duration
        variable to take into account the overall time spent on sleeping.

        :param min_sleep: Minimum sleep time in seconds (non-negative)
        :param max_sleep: Maximum sleep time in seconds (non-negative)
        :param atomic_delay: parameter with which  time.sleep would be called
                             int(sleep_time / atomic_delay) times.
        """
        if not 0 <= min_sleep <= max_sleep:
            raise exceptions.InvalidArgumentsException(
                "0 <= min_sleep <= max_sleep")

        sleep_time = random.uniform(min_sleep, max_sleep)
        utils.interruptable_sleep(sleep_time, atomic_delay)
        self._idle_duration += sleep_time
Ejemplo n.º 47
0
    def _create_v1pod(self, manifest):
        """Create a pod on the specify cluster.

        :param manifest: manifest use to create the pod
        """
        k8s_api = self._get_k8s_api_client()
        podname = manifest["metadata"]["name"] + "-"
        for i in range(5):
            podname = podname + random.choice(string.ascii_lowercase)
        manifest["metadata"]["name"] = podname

        for i in range(150):
            try:
                k8s_api.create_namespaced_pod(body=manifest,
                                              namespace="default")
                break
            except ApiException as e:
                if e.status != 403:
                    raise
            time.sleep(2)

        start = time.time()
        while True:
            resp = k8s_api.read_namespaced_pod(
                name=podname, namespace="default")

            if resp.status.conditions:
                for condition in resp.status.conditions:
                    if condition.type.lower() == "ready" and \
                       condition.status.lower() == "true":
                        return resp

            if (time.time() - start > CONF.openstack.k8s_pod_create_timeout):
                raise exceptions.TimeoutException(
                    desired_status="Ready",
                    resource_name=podname,
                    resource_type="Pod",
                    resource_id=resp.metadata.uid,
                    resource_status=resp.status,
                    timeout=CONF.openstack.k8s_pod_create_timeout)
            common_utils.interruptable_sleep(
                CONF.openstack.k8s_pod_create_poll_interval)
Ejemplo n.º 48
0
    def _create_v1pod(self, manifest):
        """Create a pod on the specify cluster.

        :param manifest: manifest use to create the pod
        """
        k8s_api = self._get_k8s_api_client()
        podname = manifest["metadata"]["name"] + "-"
        for i in range(5):
            podname = podname + random.choice(string.ascii_lowercase)
        manifest["metadata"]["name"] = podname

        for i in range(150):
            try:
                k8s_api.create_namespaced_pod(body=manifest,
                                              namespace="default")
                break
            except ApiException as e:
                if e.status != 403:
                    raise
            time.sleep(2)

        start = time.time()
        while True:
            resp = k8s_api.read_namespaced_pod(name=podname,
                                               namespace="default")

            if resp.status.conditions:
                for condition in resp.status.conditions:
                    if condition.type.lower() == "ready" and \
                       condition.status.lower() == "true":
                        return resp

            if (time.time() - start > CONF.openstack.k8s_pod_create_timeout):
                raise exceptions.TimeoutException(
                    desired_status="Ready",
                    resource_name=podname,
                    resource_type="Pod",
                    resource_id=resp.metadata.uid,
                    resource_status=resp.status,
                    timeout=CONF.openstack.k8s_pod_create_timeout)
            common_utils.interruptable_sleep(
                CONF.openstack.k8s_pod_create_poll_interval)
Ejemplo n.º 49
0
    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 "visibility" in kw:
            kw["is_public"] = kw.pop("visibility") == "public"

        image_location = os.path.expanduser(image_location)

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

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

            rutils.interruptable_sleep(CONF.openstack.
                                       glance_image_create_prepoll_delay)

            image = utils.wait_for_status(
                image, ["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 kw:
                kw["data"].close()

        return image
Ejemplo n.º 50
0
 def bar(self, sleep):
     utils.interruptable_sleep(sleep)