added glance functional test for image-conversion config

This commit is contained in:
Hernan Garcia
2021-05-26 07:10:45 -05:00
parent 90a61f621b
commit e67b0ea1e1
3 changed files with 49 additions and 6 deletions

View File

@@ -550,7 +550,8 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
backend=None,
disk_format='qcow2',
visibility='public',
container_format='bare')
container_format='bare',
force_import=False)
def test_create_image_pass_directory(self):
glance_mock = mock.MagicMock()
@@ -574,7 +575,8 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
backend=None,
disk_format='qcow2',
visibility='public',
container_format='bare')
container_format='bare',
force_import=False)
self.gettempdir.assert_not_called()
def test_create_ssh_key(self):

View File

@@ -67,6 +67,32 @@ class GlanceTest(test_utils.OpenStackBaseTest):
{'image_format': {'disk_formats': ['qcow2']}},
['glance-api'])
def test_412_image_conversion(self):
"""Check image-conversion config.
When image-conversion config is enabled glance will convert images
to raw format, this is only performed for interoperable image import
docs.openstack.org/glance/train/admin/interoperable-image-import.html
image conversion is done at server-side for better image handling
"""
current_release = openstack_utils.get_os_release()
bionic_stein = openstack_utils.get_os_release('bionic_stein')
if current_release < bionic_stein:
self.skipTest('image-conversion config is supported since '
'bionic_stein or newer versions')
with self.config_change({'image-conversion': 'false'},
{'image-conversion': 'true'}):
image_url = openstack_utils.find_cirros_image(arch='x86_64')
image = openstack_utils.create_image(
self.glance_client,
image_url,
'cirros-test-import',
force_import=True)
disk_format = self.glance_client.images.get(image.id).disk_format
self.assertEqual('raw', disk_format)
def test_900_restart_on_config_change(self):
"""Checking restart happens on config change."""
# Config file affected by juju set config change

View File

@@ -2407,7 +2407,7 @@ def delete_volume_backup(cinder, vol_backup_id):
def upload_image_to_glance(glance, local_path, image_name, disk_format='qcow2',
visibility='public', container_format='bare',
backend=None):
backend=None, force_import=False):
"""Upload the given image to glance and apply the given label.
:param glance: Authenticated glanceclient
@@ -2424,6 +2424,9 @@ def upload_image_to_glance(glance, local_path, image_name, disk_format='qcow2',
format that also contains metadata about the
actual virtual machine.
:type container_format: str
:param force_import: Force the use of glance image import
instead of direct upload
:type force_import: boolean
:returns: glance image pointer
:rtype: glanceclient.common.utils.RequestIdProxy
"""
@@ -2433,7 +2436,15 @@ def upload_image_to_glance(glance, local_path, image_name, disk_format='qcow2',
disk_format=disk_format,
visibility=visibility,
container_format=container_format)
glance.images.upload(image.id, open(local_path, 'rb'), backend=backend)
if force_import:
logging.info('Forcing image import')
glance.images.stage(image.id, open(local_path, 'rb'))
glance.images.image_import(
image.id, method='glance-direct', backend=backend)
else:
glance.images.upload(
image.id, open(local_path, 'rb'), backend=backend)
resource_reaches_status(
glance.images,
@@ -2446,7 +2457,8 @@ def upload_image_to_glance(glance, local_path, image_name, disk_format='qcow2',
def create_image(glance, image_url, image_name, image_cache_dir=None, tags=[],
properties=None, backend=None, disk_format='qcow2',
visibility='public', container_format='bare'):
visibility='public', container_format='bare',
force_import=False):
"""Download the image and upload it to glance.
Download an image from image_url and upload it to glance labelling
@@ -2465,6 +2477,9 @@ def create_image(glance, image_url, image_name, image_cache_dir=None, tags=[],
:type tags: list of str
:param properties: Properties and values to add to image
:type properties: dict
:param force_import: Force the use of glance image import
instead of direct upload
:type force_import: boolean
:returns: glance image pointer
:rtype: glanceclient.common.utils.RequestIdProxy
"""
@@ -2487,7 +2502,7 @@ def create_image(glance, image_url, image_name, image_cache_dir=None, tags=[],
image = upload_image_to_glance(
glance, local_path, image_name, backend=backend,
disk_format=disk_format, visibility=visibility,
container_format=container_format)
container_format=container_format, force_import=force_import)
for tag in tags:
result = glance.image_tags.update(image.id, tag)
logging.debug(