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
This commit is contained in:
Ghanshyam Mann 2020-07-22 21:01:26 -05:00
parent 7cff130795
commit 1425ecd42e
2 changed files with 48 additions and 19 deletions

View File

@ -40,19 +40,16 @@ class ImportImagesTest(base.BaseV2ImageTest):
"%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
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')
@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')
def _create_image(self):
# Create image
uuid = '00000000-1111-2222-3333-444455556666'
image_name = data_utils.rand_name('image')
@ -69,21 +66,50 @@ class ImportImagesTest(base.BaseV2ImageTest):
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'])

View File

@ -198,7 +198,7 @@ class ImagesClient(rest_client.RestClient):
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 @@ class ImagesClient(rest_client.RestClient):
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 @@ class ImagesClient(rest_client.RestClient):
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)