Skip to content

Commit

Permalink
Merge pull request #582 from hernandanielg/test-image-conversion-config
Browse files Browse the repository at this point in the history
added glance functional test for image-conversion config
  • Loading branch information
lourot committed Jun 1, 2021
2 parents a07f379 + e67b0ea commit 2dd5b96
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
6 changes: 4 additions & 2 deletions unit_tests/utilities/test_zaza_utilities_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ def test_create_image_use_tempdir(self):
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()
Expand All @@ -574,7 +575,8 @@ def test_create_image_pass_directory(self):
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):
Expand Down
26 changes: 26 additions & 0 deletions zaza/openstack/charm_tests/glance/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ def test_411_set_disk_format(self):
{'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
Expand Down
23 changes: 19 additions & 4 deletions zaza/openstack/utilities/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
"""
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
"""
Expand All @@ -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(
Expand Down

0 comments on commit 2dd5b96

Please sign in to comment.