Esempio n. 1
0
 def __init__(self, context=None, admin_clients=None, clients=None):
     super(GlanceBasic, self).__init__(context, admin_clients, clients)
     if hasattr(self, "_admin_clients"):
         self.admin_glance = image.Image(
             self._admin_clients,
             name_generator=self.generate_random_name,
             atomic_inst=self.atomic_actions())
     if hasattr(self, "_clients"):
         self.glance = image.Image(self._clients,
                                   name_generator=self.generate_random_name,
                                   atomic_inst=self.atomic_actions())
Esempio n. 2
0
    def _create_image(self, server):
        """Create an image from the given server

        Uses the server name to name the created image. Returns when the image
        is actually created and is in the "Active" state.

        :param server: Server object for which the image will be created

        :returns: Created image object
        """
        image_uuid = self.clients("nova").servers.create_image(server,
                                                               server.name)
        glance = image_service.Image(self._clients,
                                     atomic_inst=self.atomic_actions())
        image = glance.get_image(image_uuid)
        check_interval = CONF.benchmark.nova_server_image_create_poll_interval
        with atomic.ActionTimer(self, "glance.wait_for_image"):
            image = utils.wait_for_status(
                image,
                ready_statuses=["ACTIVE"],
                update_resource=glance.get_image,
                timeout=CONF.benchmark.nova_server_image_create_timeout,
                check_interval=check_interval
            )
        return image
Esempio n. 3
0
    def delete_one_image(self, user, custom_image):
        """Delete the image created for the user and tenant."""

        with logging.ExceptionLogger(
                LOG, "Unable to delete image %s" % custom_image.id):

            glance_service = image.Image(user["credential"].clients())
            glance_service.delete_image(custom_image.id)
Esempio n. 4
0
    def pre_process(self, resource_spec, config):
        resource_id = resource_spec.get("id")
        list_kwargs = resource_spec.get("list_kwargs", {})

        if not resource_id:
            cache_id = hash(frozenset(list_kwargs.items()))
            if cache_id not in self._cache:
                glance = image.Image(self._clients)
                self._cache[cache_id] = glance.list_images(**list_kwargs)
            images = self._cache[cache_id]
            resource_id = types._id_from_name(resource_config=resource_spec,
                                              resources=images,
                                              typename="image")
        return resource_id
Esempio n. 5
0
 def _cleanup_images(self):
     image_service = image.Image(self.clients)
     for image_obj in self._created_images:
         LOG.debug("Deleting image '%s'.", image_obj.name)
         self.clients.glance().images.delete(image_obj.id)
         task_utils.wait_for_status(
             image_obj, ["deleted", "pending_delete"],
             check_deletion=True,
             update_resource=image_service.get_image,
             timeout=conf.CONF.benchmark.glance_image_delete_timeout,
             check_interval=conf.CONF.benchmark.
             glance_image_delete_poll_interval)
         LOG.debug("Image '%s' has been deleted.", image_obj.name)
         self._remove_opt_value_from_config("compute", image_obj.id)
Esempio n. 6
0
    def _list_images(self, detailed=False, **kwargs):
        """List all images.

        :param detailed: True if the image listing
                         should contain detailed information
        :param kwargs: Optional additional arguments for image listing

        :returns: Image list
        """
        LOG.warning("Method '_delete_image' of NovaScenario class is "
                    "deprecated since Rally 0.10.0. Use GlanceUtils instead.")
        glance = image_service.Image(self._clients,
                                     atomic_inst=self.atomic_actions())
        return glance.list_images()
Esempio n. 7
0
 def _create_image(self, hadoop_version, image_url, plugin_name, user,
                   user_name):
     clients = osclients.Clients(
         user["credential"],
         api_info=self.context["config"].get("api_versions"))
     image_service = image_services.Image(
         clients, name_generator=self.generate_random_name)
     image = image_service.create_image(container_format="bare",
                                        image_location=image_url,
                                        disk_format="qcow2")
     clients.sahara().images.update_image(
         image_id=image.id, user_name=user_name, desc="")
     clients.sahara().images.update_tags(
         image_id=image.id, new_tags=[plugin_name, hadoop_version])
     return image.id
Esempio n. 8
0
    def transform(cls, clients, resource_config):
        """Transform the resource config to id.

        :param clients: openstack admin client handles
        :param resource_config: scenario config with `id`, `name` or `regex`

        :returns: id matching resource
        """
        resource_id = resource_config.get("id")
        list_kwargs = resource_config.get("list_kwargs", {})
        if not resource_id:
            images = list(image.Image(clients).list_images(**list_kwargs))
            resource_id = types._id_from_name(resource_config=resource_config,
                                              resources=images,
                                              typename="image")
        return resource_id
Esempio n. 9
0
    def _discover_image(self):
        LOG.debug("Trying to discover a public image with name matching "
                  "regular expression '%s'. Note that case insensitive "
                  "matching is performed." % conf.CONF.tempest.img_name_regex)
        image_service = image.Image(self.clients)
        images = image_service.list_images(status="active",
                                           visibility="public")
        for image_obj in images:
            if image_obj.name and re.match(conf.CONF.tempest.img_name_regex,
                                           image_obj.name, re.IGNORECASE):
                LOG.debug("The following public "
                          "image discovered: '%s'." % image_obj.name)
                return image_obj

        LOG.debug("There is no public image with name matching regular "
                  "expression '%s'." % conf.CONF.tempest.img_name_regex)
Esempio n. 10
0
    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:
            if self.context["users"]:
                # NOTE(pboldin): Create by first user and make it public by
                #                the admin
                user = self.context["users"][0]
            else:
                user = self.context["admin"]
            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)
            glance_service = image.Image(
                self.context["admin"]["credential"].clients())
            glance_service.set_visibility(custom_image.id)

            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"])
Esempio n. 11
0
    def _delete_image(self, image):
        """Delete the given image.

        Returns when the image is actually deleted.

        :param image: Image object
        """
        LOG.warning("Method '_delete_image' of NovaScenario class is "
                    "deprecated since Rally 0.10.0. Use GlanceUtils instead.")
        glance = image_service.Image(self._clients,
                                     atomic_inst=self.atomic_actions())
        glance.delete_image(image.id)
        check_interval = CONF.benchmark.nova_server_image_delete_poll_interval
        with atomic.ActionTimer(self, "glance.wait_for_delete"):
            utils.wait_for_status(
                image,
                ready_statuses=["deleted", "pending_delete"],
                check_deletion=True,
                update_resource=glance.get_image,
                timeout=CONF.benchmark.nova_server_image_delete_timeout,
                check_interval=check_interval)
Esempio n. 12
0
    def upload_volume_to_image(self,
                               volume,
                               force=False,
                               container_format="bare",
                               disk_format="raw"):
        """Upload the given volume to image.

        Returns created image.

        :param volume: volume object
        :param force: flag to indicate whether to snapshot a volume even if
                      it's attached to an instance
        :param container_format: container format of image. Acceptable
                                 formats: ami, ari, aki, bare, and ovf
        :param disk_format: disk format of image. Acceptable formats:
                            ami, ari, aki, vhd, vmdk, raw, qcow2, vdi and iso
        :returns: Returns created image object
        """
        aname = "cinder_v%s.upload_volume_to_image" % self.version
        with atomic.ActionTimer(self, aname):
            resp, img = self._get_client().volumes.upload_to_image(
                volume, force, self.generate_random_name(), container_format,
                disk_format)
            # NOTE (e0ne): upload_to_image changes volume status to uploading
            # so we need to wait until it will be available.
            volume = self._wait_available_volume(volume)

            image_id = img["os-volume_upload_image"]["image_id"]
            glance = image.Image(self._clients)

            image_inst = glance.get_image(image_id)
            image_inst = bench_utils.wait_for_status(
                image_inst,
                ready_statuses=["active"],
                update_resource=glance.get_image,
                timeout=CONF.benchmark.glance_image_create_timeout,
                check_interval=(
                    CONF.benchmark.glance_image_create_poll_interval))

            return image_inst
Esempio n. 13
0
    def _discover_or_create_image(self):
        if conf.CONF.tempest.img_name_regex:
            image_obj = self._discover_image()
            if image_obj:
                LOG.debug("Using image '%s' (ID = %s) "
                          "for the tests.", (image_obj.name, image_obj.id))
                return image_obj

        params = {
            "image_name": self.generate_random_name(),
            "disk_format": conf.CONF.tempest.img_disk_format,
            "container_format": conf.CONF.tempest.img_container_format,
            "image_location": os.path.join(self.data_dir, self.image_name),
            "visibility": "public"
        }
        LOG.debug("Creating image '%s'." % params["image_name"])
        image_service = image.Image(self.clients)
        image_obj = image_service.create_image(**params)
        LOG.debug("Image '%s' (ID = %s) has been "
                  "successfully created!", (image_obj.name, image_obj.id))
        self._created_images.append(image_obj)

        return image_obj
Esempio n. 14
0
    def setup(self):
        image_url = self.config.get("image_url")
        image_type = self.config.get("image_type")
        disk_format = self.config.get("disk_format")
        image_container = self.config.get("image_container")
        container_format = self.config.get("container_format")
        images_per_tenant = self.config.get("images_per_tenant")
        image_name = self.config.get("image_name")
        visibility = self.config.get("visibility", "private")
        min_disk = self.config.get("min_disk", 0)
        min_ram = self.config.get("min_ram", 0)
        image_args = self.config.get("image_args", {})
        is_public = image_args.get("is_public")

        if is_public:
            LOG.warning(
                _("The 'is_public' argument is deprecated "
                  "since Rally 0.10.0; specify visibility "
                  "arguments instead"))
            if "visibility" not in self.config:
                visibility = "public" if is_public else "private"

        if image_type:
            LOG.warning(
                _("The 'image_type' argument is deprecated "
                  "since Rally 0.10.0; specify disk_format "
                  "arguments instead"))
            disk_format = image_type

        if image_container:
            LOG.warning(
                _("The 'image_container' argument is deprecated "
                  "since Rally 0.10.0; specify container_format "
                  "arguments instead"))
            container_format = image_container

        if image_args:
            LOG.warning(
                _("The 'kwargs' argument is deprecated since "
                  "Rally 0.10.0; specify exact arguments instead"))

        for user, tenant_id in rutils.iterate_per_tenants(
                self.context["users"]):
            current_images = []
            clients = osclients.Clients(
                user["credential"],
                api_info=self.context["config"].get("api_versions"))
            image_service = image.Image(
                clients, name_generator=self.generate_random_name)

            for i in range(images_per_tenant):
                if image_name and i > 0:
                    cur_name = image_name + str(i)
                elif image_name:
                    cur_name = image_name
                else:
                    cur_name = self.generate_random_name()

                image_obj = image_service.create_image(
                    image_name=cur_name,
                    container_format=container_format,
                    image_location=image_url,
                    disk_format=disk_format,
                    visibility=visibility,
                    min_disk=min_disk,
                    min_ram=min_ram)
                current_images.append(image_obj.id)

            self.context["tenants"][tenant_id]["images"] = current_images
Esempio n. 15
0
    def setup(self):
        image_url = self.config.get("image_url")
        disk_format = self.config.get("disk_format")
        container_format = self.config.get("container_format")
        images_per_tenant = self.config.get("images_per_tenant")
        visibility = self.config.get("visibility", "private")
        min_disk = self.config.get("min_disk", 0)
        min_ram = self.config.get("min_ram", 0)
        image_args = self.config.get("image_args", {})

        if "image_type" in self.config:
            LOG.warning("The 'image_type' argument is deprecated since "
                        "Rally 0.10.0, use disk_format argument instead")
            if not disk_format:
                disk_format = self.config["image_type"]

        if "image_container" in self.config:
            LOG.warning("The 'image_container' argument is deprecated since "
                        "Rally 0.10.0; use container_format argument instead")
            if not container_format:
                container_format = self.config["image_container"]

        if image_args:
            LOG.warning(
                "The 'image_args' argument is deprecated since Rally 0.10.0; "
                "specify arguments in a root section of context instead")

            if "is_public" in image_args:
                if "visibility" not in self.config:
                    visibility = ("public" if image_args["is_public"]
                                  else "private")
            if "min_ram" in image_args:
                if "min_ram" not in self.config:
                    min_ram = image_args["min_ram"]

            if "min_disk" in image_args:
                if "min_disk" not in self.config:
                    min_disk = image_args["min_disk"]

        # None image_name means that image.Image will generate a random name
        image_name = None
        if "image_name" in self.config and images_per_tenant == 1:
            image_name = self.config["image_name"]

        for user, tenant_id in rutils.iterate_per_tenants(
                self.context["users"]):
            current_images = []
            clients = osclients.Clients(
                user["credential"],
                api_info=self.context["config"].get("api_versions"))
            image_service = image.Image(
                clients, name_generator=self.generate_random_name)

            for i in range(images_per_tenant):
                image_obj = image_service.create_image(
                    image_name=image_name,
                    container_format=container_format,
                    image_location=image_url,
                    disk_format=disk_format,
                    visibility=visibility,
                    min_disk=min_disk,
                    min_ram=min_ram)
                current_images.append(image_obj.id)

            self.context["tenants"][tenant_id]["images"] = current_images
Esempio n. 16
0
 def _client(self):
     return image.Image(self.admin or self.user)
Esempio n. 17
0
 def _glance(self):
     return image.Image(self.admin)
Esempio n. 18
0
 def get_service_with_fake_impl(self):
     path = "rally.plugins.openstack.services.image.image"
     with mock.patch("%s.Image.discover_impl" % path) as mock_discover:
         mock_discover.return_value = mock.MagicMock(), None
         service = image.Image(self.clients)
     return service