From be8d510958ce25382a6c18034266b0b9f172a56b Mon Sep 17 00:00:00 2001 From: Soniya Vyas Date: Mon, 17 Aug 2020 17:23:30 +0530 Subject: [PATCH] Use of single interface for creating image Within scenario manager, we had two methods for creating image those are as follows: 1. _image_create() - private interface which creates image 2. glance_image_create() - public interface which uses the above method eventually to create image Hence, let's have single method for single work. Thus, we need to replace '_image_create()' with 'image_create()'. Implements: blueprint tempest-scenario-manager-stable Signed-off by: Soniya Vyas Change-Id: I33e6abd416bbe5964a279f7969615ffd2974b4dd --- tempest/scenario/manager.py | 68 ++++++++----------- .../scenario/test_encrypted_cinder_volumes.py | 2 +- tempest/scenario/test_minimum_basic.py | 2 +- 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py index a80b77d90d..5d51d15c6f 100644 --- a/tempest/scenario/manager.py +++ b/tempest/scenario/manager.py @@ -502,36 +502,7 @@ class ScenarioTest(tempest.test.BaseTestCase): linux_client.validate_authentication() return linux_client - def _image_create(self, name, fmt, path, - disk_format=None, properties=None): - if properties is None: - properties = {} - name = data_utils.rand_name('%s-' % name) - params = { - 'name': name, - 'container_format': fmt, - 'disk_format': disk_format or fmt, - } - if CONF.image_feature_enabled.api_v1: - params['is_public'] = 'False' - params['properties'] = properties - params = {'headers': common_image.image_meta_to_headers(**params)} - else: - params['visibility'] = 'private' - # Additional properties are flattened out in the v2 API. - params.update(properties) - body = self.image_client.create_image(**params) - image = body['image'] if 'image' in body else body - self.addCleanup(self.image_client.delete_image, image['id']) - self.assertEqual("queued", image['status']) - with open(path, 'rb') as image_file: - if CONF.image_feature_enabled.api_v1: - self.image_client.update_image(image['id'], data=image_file) - else: - self.image_client.store_image_file(image['id'], image_file) - return image['id'] - - def glance_image_create(self): + def image_create(self, name='scenario-img'): img_path = CONF.scenario.img_file if not os.path.exists(img_path): # TODO(kopecmartin): replace LOG.warning for rasing @@ -553,14 +524,35 @@ class ScenarioTest(tempest.test.BaseTestCase): "properties: %s", img_path, img_container_format, img_disk_format, img_properties) - image = self._image_create('scenario-img', - img_container_format, - img_path, - disk_format=img_disk_format, - properties=img_properties) - LOG.debug("image:%s", image) - - return image + if img_properties is None: + img_properties = {} + name = data_utils.rand_name('%s-' % name) + params = { + 'name': name, + 'container_format': img_container_format, + 'disk_format': img_disk_format or img_container_format, + } + if CONF.image_feature_enabled.api_v1: + params['is_public'] = 'False' + if img_properties: + params['properties'] = img_properties + params = {'headers': common_image.image_meta_to_headers(**params)} + else: + params['visibility'] = 'private' + # Additional properties are flattened out in the v2 API. + if img_properties: + params.update(img_properties) + body = self.image_client.create_image(**params) + image = body['image'] if 'image' in body else body + self.addCleanup(self.image_client.delete_image, image['id']) + self.assertEqual("queued", image['status']) + with open(img_path, 'rb') as image_file: + if CONF.image_feature_enabled.api_v1: + self.image_client.update_image(image['id'], data=image_file) + else: + self.image_client.store_image_file(image['id'], image_file) + LOG.debug("image:%s", image['id']) + return image['id'] def _log_console_output(self, servers=None, client=None): if not CONF.compute_feature_enabled.console_output: diff --git a/tempest/scenario/test_encrypted_cinder_volumes.py b/tempest/scenario/test_encrypted_cinder_volumes.py index 008d1aeef3..fc93a5efa5 100644 --- a/tempest/scenario/test_encrypted_cinder_volumes.py +++ b/tempest/scenario/test_encrypted_cinder_volumes.py @@ -44,7 +44,7 @@ class TestEncryptedCinderVolumes(manager.EncryptionScenarioTest): raise cls.skipException('Encrypted volume attach is not supported') def launch_instance(self): - image = self.glance_image_create() + image = self.image_create() keypair = self.create_keypair() return self.create_server(image_id=image, key_name=keypair['name']) diff --git a/tempest/scenario/test_minimum_basic.py b/tempest/scenario/test_minimum_basic.py index 4cd860d9f1..fe42583d2a 100644 --- a/tempest/scenario/test_minimum_basic.py +++ b/tempest/scenario/test_minimum_basic.py @@ -106,7 +106,7 @@ class TestMinimumBasicScenario(manager.ScenarioTest): @decorators.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8') @utils.services('compute', 'volume', 'image', 'network') def test_minimum_basic_scenario(self): - image = self.glance_image_create() + image = self.image_create() keypair = self.create_keypair() server = self.create_server(image_id=image, key_name=keypair['name'])