From 66275c24964ab2f8550c2409706f6f86b7edfdba Mon Sep 17 00:00:00 2001 From: zhufl Date: Wed, 28 Mar 2018 15:32:14 +0800 Subject: [PATCH] Set max_microversion 2.35 for nova image tests 1. The compute images API is deprecated from the Microversion 2.36, so we should set max_microversion = '2.35' for compute image tests. 2. Compute image_create is not deprecated. 3. In testcases other than those in compute/images, we can simply change to use glance images_client, which will also work before microversion 2.35. ref: https://developer.openstack.org/api-ref/compute/#list-images https://developer.openstack.org/api-ref/compute/#create-image-createimage-action Implements blueprint: clear-deprecated-api Change-Id: I7a40d26449a361f0e3ec922ac41a7c522b572803 --- tempest/api/compute/base.py | 6 ++-- tempest/api/compute/images/test_images.py | 5 +++- .../compute/images/test_images_negative.py | 13 ++++++-- .../compute/images/test_images_oneserver.py | 30 ++++++++++++++----- .../images/test_images_oneserver_negative.py | 8 +++-- .../compute/images/test_list_image_filters.py | 1 + .../test_list_image_filters_negative.py | 1 + .../api/compute/images/test_list_images.py | 1 + .../compute/servers/test_servers_negative.py | 7 +++-- tempest/cmd/cleanup_service.py | 4 +-- tempest/scenario/manager.py | 8 +++-- tempest/tests/api/compute/test_base.py | 7 ++++- 12 files changed, 69 insertions(+), 22 deletions(-) diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py index d0c19737f1..8962d0e57c 100644 --- a/tempest/api/compute/base.py +++ b/tempest/api/compute/base.py @@ -344,8 +344,7 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest, # The compute image proxy APIs were deprecated in 2.35 so # use the images client directly if the API microversion being # used is >=2.36. - if api_version_utils.compare_version_header_to_response( - "OpenStack-API-Version", "compute 2.36", image.response, "lt"): + if not cls.is_requested_microversion_compatible('2.35'): client = cls.images_client else: client = cls.compute_images_client @@ -354,6 +353,9 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest, if wait_until is not None: try: + wait_until = wait_until.upper() + if not cls.is_requested_microversion_compatible('2.35'): + wait_until = wait_until.lower() waiters.wait_for_image_status(client, image_id, wait_until) except lib_exc.NotFound: if wait_until.upper() == 'ACTIVE': diff --git a/tempest/api/compute/images/test_images.py b/tempest/api/compute/images/test_images.py index 29bd6dae11..c8221c28d9 100644 --- a/tempest/api/compute/images/test_images.py +++ b/tempest/api/compute/images/test_images.py @@ -38,7 +38,10 @@ class ImagesTestJSON(base.BaseV2ComputeTest): @classmethod def setup_clients(cls): super(ImagesTestJSON, cls).setup_clients() - cls.client = cls.compute_images_client + if cls.is_requested_microversion_compatible('2.35'): + cls.client = cls.compute_images_client + else: + cls.client = cls.images_client @decorators.idempotent_id('aa06b52b-2db5-4807-b218-9441f75d74e3') def test_delete_saving_image(self): diff --git a/tempest/api/compute/images/test_images_negative.py b/tempest/api/compute/images/test_images_negative.py index e292389682..24003485a3 100644 --- a/tempest/api/compute/images/test_images_negative.py +++ b/tempest/api/compute/images/test_images_negative.py @@ -22,11 +22,11 @@ from tempest.lib import exceptions as lib_exc CONF = config.CONF -class ImagesNegativeTestJSON(base.BaseV2ComputeTest): +class ImagesNegativeTestBase(base.BaseV2ComputeTest): @classmethod def skip_checks(cls): - super(ImagesNegativeTestJSON, cls).skip_checks() + super(ImagesNegativeTestBase, cls).skip_checks() if not CONF.service_available.glance: skip_msg = ("%s skipped as glance is not available" % cls.__name__) raise cls.skipException(skip_msg) @@ -37,9 +37,12 @@ class ImagesNegativeTestJSON(base.BaseV2ComputeTest): @classmethod def setup_clients(cls): - super(ImagesNegativeTestJSON, cls).setup_clients() + super(ImagesNegativeTestBase, cls).setup_clients() cls.client = cls.compute_images_client + +class ImagesNegativeTestJSON(ImagesNegativeTestBase): + @decorators.attr(type=['negative']) @decorators.idempotent_id('6cd5a89d-5b47-46a7-93bc-3916f0d84973') def test_create_image_from_deleted_server(self): @@ -82,6 +85,10 @@ class ImagesNegativeTestJSON(base.BaseV2ComputeTest): self.assertRaises(lib_exc.NotFound, self.client.create_image, test_uuid, name=snapshot_name) + +class ImagesDeleteNegativeTestJSON(ImagesNegativeTestBase): + max_microversion = '2.35' + @decorators.attr(type=['negative']) @decorators.idempotent_id('381acb65-785a-4942-94ce-d8f8c84f1f0f') def test_delete_image_with_invalid_image_id(self): diff --git a/tempest/api/compute/images/test_images_oneserver.py b/tempest/api/compute/images/test_images_oneserver.py index 058e7e6cca..3c152c99e7 100644 --- a/tempest/api/compute/images/test_images_oneserver.py +++ b/tempest/api/compute/images/test_images_oneserver.py @@ -44,7 +44,10 @@ class ImagesOneServerTestJSON(base.BaseV2ComputeTest): @classmethod def setup_clients(cls): super(ImagesOneServerTestJSON, cls).setup_clients() - cls.client = cls.compute_images_client + if cls.is_requested_microversion_compatible('2.35'): + cls.client = cls.compute_images_client + else: + cls.client = cls.images_client def _get_default_flavor_disk_size(self, flavor_id): flavor = self.flavors_client.show_flavor(flavor_id)['flavor'] @@ -52,6 +55,13 @@ class ImagesOneServerTestJSON(base.BaseV2ComputeTest): @decorators.idempotent_id('3731d080-d4c5-4872-b41a-64d0d0021314') def test_create_delete_image(self): + if self.is_requested_microversion_compatible('2.35'): + MIN_DISK = 'minDisk' + MIN_RAM = 'minRam' + else: + MIN_DISK = 'min_disk' + MIN_RAM = 'min_ram' + # Create a new image name = data_utils.rand_name('image') meta = {'image_type': 'test'} @@ -61,17 +71,22 @@ class ImagesOneServerTestJSON(base.BaseV2ComputeTest): # Verify the image was created correctly self.assertEqual(name, image['name']) - self.assertEqual('test', image['metadata']['image_type']) + if self.is_requested_microversion_compatible('2.35'): + self.assertEqual('test', image['metadata']['image_type']) + else: + self.assertEqual('test', image['image_type']) - original_image = self.client.show_image(self.image_ref)['image'] + original_image = self.client.show_image(self.image_ref) + if self.is_requested_microversion_compatible('2.35'): + original_image = original_image['image'] # Verify minRAM is the same as the original image - self.assertEqual(image['minRam'], original_image['minRam']) + self.assertEqual(image[MIN_RAM], original_image[MIN_RAM]) # Verify minDisk is the same as the original image or the flavor size flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref) - self.assertIn(str(image['minDisk']), - (str(original_image['minDisk']), str(flavor_disk_size))) + self.assertIn(str(image[MIN_DISK]), + (str(original_image[MIN_DISK]), str(flavor_disk_size))) # Verify the image was deleted correctly self.client.delete_image(image['id']) @@ -86,7 +101,8 @@ class ImagesOneServerTestJSON(base.BaseV2ComputeTest): # will return 400(Bad Request) if we attempt to send a name which has # 4 byte utf-8 character. utf8_name = data_utils.rand_name(b'\xe2\x82\xa1'.decode('utf-8')) - body = self.client.create_image(self.server_id, name=utf8_name) + body = self.compute_images_client.create_image( + self.server_id, name=utf8_name) if api_version_utils.compare_version_header_to_response( "OpenStack-API-Version", "compute 2.45", body.response, "lt"): image_id = body['image_id'] diff --git a/tempest/api/compute/images/test_images_oneserver_negative.py b/tempest/api/compute/images/test_images_oneserver_negative.py index a2e58c9b7d..b65c7e196d 100644 --- a/tempest/api/compute/images/test_images_oneserver_negative.py +++ b/tempest/api/compute/images/test_images_oneserver_negative.py @@ -69,7 +69,10 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest): @classmethod def setup_clients(cls): super(ImagesOneServerNegativeTestJSON, cls).setup_clients() - cls.client = cls.compute_images_client + if cls.is_requested_microversion_compatible('2.35'): + cls.client = cls.compute_images_client + else: + cls.client = cls.images_client @classmethod def resource_setup(cls): @@ -119,7 +122,8 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest): # Return an error if snapshot name over 255 characters is passed snapshot_name = ('a' * 256) - self.assertRaises(lib_exc.BadRequest, self.client.create_image, + self.assertRaises(lib_exc.BadRequest, + self.compute_images_client.create_image, self.server_id, name=snapshot_name) @decorators.attr(type=['negative']) diff --git a/tempest/api/compute/images/test_list_image_filters.py b/tempest/api/compute/images/test_list_image_filters.py index d83d8df715..2ac7de3b2a 100644 --- a/tempest/api/compute/images/test_list_image_filters.py +++ b/tempest/api/compute/images/test_list_image_filters.py @@ -31,6 +31,7 @@ CONF = config.CONF class ListImageFiltersTestJSON(base.BaseV2ComputeTest): + max_microversion = '2.35' @classmethod def skip_checks(cls): diff --git a/tempest/api/compute/images/test_list_image_filters_negative.py b/tempest/api/compute/images/test_list_image_filters_negative.py index d37f8fc806..81c59f96b6 100644 --- a/tempest/api/compute/images/test_list_image_filters_negative.py +++ b/tempest/api/compute/images/test_list_image_filters_negative.py @@ -22,6 +22,7 @@ CONF = config.CONF class ListImageFiltersNegativeTestJSON(base.BaseV2ComputeTest): + max_microversion = '2.35' @classmethod def skip_checks(cls): diff --git a/tempest/api/compute/images/test_list_images.py b/tempest/api/compute/images/test_list_images.py index e2dbd72f37..cbb65bbfc9 100644 --- a/tempest/api/compute/images/test_list_images.py +++ b/tempest/api/compute/images/test_list_images.py @@ -21,6 +21,7 @@ CONF = config.CONF class ListImagesTestJSON(base.BaseV2ComputeTest): + max_microversion = '2.35' @classmethod def skip_checks(cls): diff --git a/tempest/api/compute/servers/test_servers_negative.py b/tempest/api/compute/servers/test_servers_negative.py index e944c28870..eb70440e5c 100644 --- a/tempest/api/compute/servers/test_servers_negative.py +++ b/tempest/api/compute/servers/test_servers_negative.py @@ -485,8 +485,11 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest): server = self.client.show_server(self.server_id)['server'] image_name = server['name'] + '-shelved' - params = {'name': image_name} - images = self.compute_images_client.list_images(**params)['images'] + if CONF.image_feature_enabled.api_v1: + kwargs = {'name': image_name} + else: + kwargs = {'params': {'name': image_name}} + images = self.images_client.list_images(**kwargs)['images'] self.assertEqual(1, len(images)) self.assertEqual(image_name, images[0]['name']) diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py index 27e1bc1b5f..6e7789aa6a 100644 --- a/tempest/cmd/cleanup_service.py +++ b/tempest/cmd/cleanup_service.py @@ -720,11 +720,11 @@ class FlavorService(BaseService): class ImageService(BaseService): def __init__(self, manager, **kwargs): super(ImageService, self).__init__(kwargs) - self.client = manager.compute_images_client + self.client = manager.image_client_v2 def list(self): client = self.client - images = client.list_images({"all_tenants": True})['images'] + images = client.list_images(params={"all_tenants": True})['images'] if not self.is_save_state: images = [image for image in images if image['id'] not in self.saved_state_json['images'].keys()] diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py index 9db7f92f6b..b2e8462ef2 100644 --- a/tempest/scenario/manager.py +++ b/tempest/scenario/manager.py @@ -221,8 +221,12 @@ class ScenarioTest(tempest.test.BaseTestCase): if size is None: size = CONF.volume.volume_size if imageRef: - image = self.compute_images_client.show_image(imageRef)['image'] - min_disk = image.get('minDisk') + if CONF.image_feature_enabled.api_v1: + resp = self.image_client.check_image(imageRef) + image = common_image.get_image_meta_from_headers(resp) + else: + image = self.image_client.show_image(imageRef) + min_disk = image.get('min_disk') size = max(size, min_disk) if name is None: name = data_utils.rand_name(self.__class__.__name__ + "-volume") diff --git a/tempest/tests/api/compute/test_base.py b/tempest/tests/api/compute/test_base.py index 47f4ad6927..1593464624 100644 --- a/tempest/tests/api/compute/test_base.py +++ b/tempest/tests/api/compute/test_base.py @@ -131,8 +131,13 @@ class TestBaseV2ComputeTest(base.TestCase): self.assertIn(fault, six.text_type(ex)) else: self.assertNotIn(fault, six.text_type(ex)) + if compute_base.BaseV2ComputeTest.is_requested_microversion_compatible( + '2.35'): + status = 'ACTIVE' + else: + status = 'active' wait_for_image_status.assert_called_once_with( - compute_images_client, image_id, 'active') + compute_images_client, image_id, status) servers_client.show_server.assert_called_once_with( mock.sentinel.server_id)