def _delete_image(self, image): """Deletes given image. Returns when the image is actually deleted. :param image: Image object """ self.clients("glance").images.delete(image.id) wrapper = glance_wrapper.wrap(self._clients.glance, self) utils.wait_for_status( image, ["deleted", "pending_delete"], check_deletion=True, update_resource=wrapper.get_image, timeout=CONF.openstack.glance_image_delete_timeout, check_interval=CONF.openstack.glance_image_delete_poll_interval)
def _create_image(self, container_format, image_location, disk_format, **kwargs): """Create a new image. :param container_format: container format of image. Acceptable formats: ami, ari, aki, bare, and ovf :param image_location: image file location :param disk_format: disk format of image. Acceptable formats: ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, and iso :param kwargs: optional parameters to create image :returns: image object """ if not kwargs.get("name"): kwargs["name"] = self.generate_random_name() client = glance_wrapper.wrap(self._clients.glance, self) return client.create_image(container_format, image_location, disk_format, **kwargs)
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 """ resp, img = volume.upload_to_image(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 = bench_utils.wait_for_status( volume, ready_statuses=["available"], update_resource=bench_utils.get_from_manager(), timeout=CONF.openstack.cinder_volume_create_timeout, check_interval=CONF.openstack.cinder_volume_create_poll_interval ) image_id = img["os-volume_upload_image"]["image_id"] image = self.clients("glance").images.get(image_id) wrapper = glance_wrapper.wrap(self._clients.glance, self) image = bench_utils.wait_for_status( image, ready_statuses=["active"], update_resource=wrapper.get_image, timeout=CONF.openstack.glance_image_create_timeout, check_interval=CONF.openstack.glance_image_create_poll_interval ) return image
def setUp(self): super(GlanceV1WrapperTestCase, self).setUp() self.client = mock.MagicMock() self.client.choose_version.return_value = "1" self.owner = mock.Mock() self.wrapped_client = glance_wrapper.wrap(self.client, self.owner)
def test_wrap(self, version, expected_class): client = mock.MagicMock() client.choose_version.return_value = version self.assertIsInstance(glance_wrapper.wrap(client, mock.Mock()), expected_class)