Merge "Add glance image import web-download tests"

This commit is contained in:
Zuul 2020-07-31 08:05:39 +00:00 committed by Gerrit Code Review
commit b18d7dda30
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__) "%s skipped as image import is not available" % cls.__name__)
raise cls.skipException(skip_msg) raise cls.skipException(skip_msg)
@decorators.idempotent_id('32ca0c20-e16f-44ac-8590-07869c9b4cc2') @classmethod
def test_image_import(self): def resource_setup(cls):
"""Here we test these functionalities super(ImportImagesTest, cls).resource_setup()
cls.available_import_methods = cls.client.info_import()[
Create image, stage image data, import image and verify 'import-methods']['value']
that import succeeded. if not cls.available_import_methods:
""" raise cls.skipException('Server does not support '
'any import method')
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 # Create image
uuid = '00000000-1111-2222-3333-444455556666' uuid = '00000000-1111-2222-3333-444455556666'
image_name = data_utils.rand_name('image') image_name = data_utils.rand_name('image')
@ -69,21 +66,50 @@ class ImportImagesTest(base.BaseV2ImageTest):
self.assertEqual('private', image['visibility']) self.assertEqual('private', image['visibility'])
self.assertIn('status', image) self.assertIn('status', image)
self.assertEqual('queued', image['status']) 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 # Stage image data
file_content = data_utils.random_bytes() file_content = data_utils.random_bytes()
image_file = six.BytesIO(file_content) image_file = six.BytesIO(file_content)
self.client.stage_image_file(image['id'], image_file) 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 # Now try to get image details
body = self.client.show_image(image['id']) body = self.client.show_image(image['id'])
self.assertEqual(image['id'], body['id']) self.assertEqual(image['id'], body['id'])
self.assertEqual(image_name, body['name']) self.assertEqual('queued', body['status'])
self.assertEqual(uuid, body['ramdisk_id']) # import image from web to backend
self.assertEqual('uploading', body['status']) image_uri = CONF.image.http_image
self.client.image_import(image['id'], method='web-download',
# import image from staging to backend image_uri=image_uri)
self.client.image_import(image['id'])
self.client.wait_for_resource_activation(image['id']) 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', def image_import(self, image_id, method='glance-direct',
all_stores_must_succeed=None, all_stores=True, all_stores_must_succeed=None, all_stores=True,
stores=None): stores=None, image_uri=None):
"""Import data from staging area to glance store. """Import data from staging area to glance store.
For a full list of available parameters, please refer to the official 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) all available stores (incompatible with stores)
:param stores: A list of destination store names for the import. Must :param stores: A list of destination store names for the import. Must
be None if server does not support multistore. 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 url = 'images/%s/import' % image_id
data = { data = {
@ -228,6 +229,8 @@ class ImagesClient(rest_client.RestClient):
if all_stores_must_succeed is not None: if all_stores_must_succeed is not None:
data['all_stores_must_succeed'] = all_stores_must_succeed data['all_stores_must_succeed'] = all_stores_must_succeed
if image_uri:
data['method']['uri'] = image_uri
data = json.dumps(data) data = json.dumps(data)
headers = {'Content-Type': 'application/json'} headers = {'Content-Type': 'application/json'}
resp, _ = self.post(url, data, headers=headers) resp, _ = self.post(url, data, headers=headers)