Add glance image import web-download tests
Glance image can be imported with web-download
import method
- https://docs.openstack.org/api-ref/image/v2/index.html#interoperable-image-import
Depends-On: https://review.opendev.org/#/c/742574/
Change-Id: I6f30f6fd0e63d83a7abac4eccc2a8ad57365a7ce
diff --git a/tempest/api/image/v2/test_images.py b/tempest/api/image/v2/test_images.py
index 3e72b34..c1a7211 100644
--- a/tempest/api/image/v2/test_images.py
+++ b/tempest/api/image/v2/test_images.py
@@ -40,19 +40,16 @@
"%s skipped as image import is not available" % cls.__name__)
raise cls.skipException(skip_msg)
- @decorators.idempotent_id('32ca0c20-e16f-44ac-8590-07869c9b4cc2')
- def test_image_import(self):
- """Here we test these functionalities
+ @classmethod
+ def resource_setup(cls):
+ super(ImportImagesTest, cls).resource_setup()
+ cls.available_import_methods = cls.client.info_import()[
+ 'import-methods']['value']
+ if not cls.available_import_methods:
+ raise cls.skipException('Server does not support '
+ 'any import method')
- Create image, stage image data, import image and verify
- that import succeeded.
- """
-
- body = self.client.info_import()
- if 'glance-direct' not in body['import-methods']['value']:
- raise self.skipException('Server does not support '
- 'glance-direct import method')
-
+ def _create_image(self):
# Create image
uuid = '00000000-1111-2222-3333-444455556666'
image_name = data_utils.rand_name('image')
@@ -69,21 +66,50 @@
self.assertEqual('private', image['visibility'])
self.assertIn('status', image)
self.assertEqual('queued', image['status'])
+ return image
+ @decorators.idempotent_id('32ca0c20-e16f-44ac-8590-07869c9b4cc2')
+ def test_image_glance_direct_import(self):
+ """Test 'glance-direct' import functionalities
+
+ Create image, stage image data, import image and verify
+ that import succeeded.
+ """
+ if 'glance-direct' not in self.available_import_methods:
+ raise self.skipException('Server does not support '
+ 'glance-direct import method')
+ image = self._create_image()
# Stage image data
file_content = data_utils.random_bytes()
image_file = six.BytesIO(file_content)
self.client.stage_image_file(image['id'], image_file)
+ # Check image status is 'uploading'
+ body = self.client.show_image(image['id'])
+ self.assertEqual(image['id'], body['id'])
+ self.assertEqual('uploading', body['status'])
+ # import image from staging to backend
+ self.client.image_import(image['id'], method='glance-direct')
+ self.client.wait_for_resource_activation(image['id'])
+ @decorators.idempotent_id('f6feb7a4-b04f-4706-a011-206129f83e62')
+ def test_image_web_download_import(self):
+ """Test 'web-download' import functionalities
+
+ Create image, import image and verify that import
+ succeeded.
+ """
+ if 'web-download' not in self.available_import_methods:
+ raise self.skipException('Server does not support '
+ 'web-download import method')
+ image = self._create_image()
# Now try to get image details
body = self.client.show_image(image['id'])
self.assertEqual(image['id'], body['id'])
- self.assertEqual(image_name, body['name'])
- self.assertEqual(uuid, body['ramdisk_id'])
- self.assertEqual('uploading', body['status'])
-
- # import image from staging to backend
- self.client.image_import(image['id'])
+ self.assertEqual('queued', body['status'])
+ # import image from web to backend
+ image_uri = CONF.image.http_image
+ self.client.image_import(image['id'], method='web-download',
+ image_uri=image_uri)
self.client.wait_for_resource_activation(image['id'])
diff --git a/tempest/lib/services/image/v2/images_client.py b/tempest/lib/services/image/v2/images_client.py
index b9c5776..4713cce 100644
--- a/tempest/lib/services/image/v2/images_client.py
+++ b/tempest/lib/services/image/v2/images_client.py
@@ -198,7 +198,7 @@
def image_import(self, image_id, method='glance-direct',
all_stores_must_succeed=None, all_stores=True,
- stores=None):
+ stores=None, image_uri=None):
"""Import data from staging area to glance store.
For a full list of available parameters, please refer to the official
@@ -214,6 +214,7 @@
all available stores (incompatible with stores)
:param stores: A list of destination store names for the import. Must
be None if server does not support multistore.
+ :param image_uri: A URL to be used with the web-download method
"""
url = 'images/%s/import' % image_id
data = {
@@ -228,6 +229,8 @@
if all_stores_must_succeed is not None:
data['all_stores_must_succeed'] = all_stores_must_succeed
+ if image_uri:
+ data['method']['uri'] = image_uri
data = json.dumps(data)
headers = {'Content-Type': 'application/json'}
resp, _ = self.post(url, data, headers=headers)