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
This commit is contained in:
parent
fc8ef3aeeb
commit
66275c2496
@ -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':
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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']
|
||||
|
@ -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'])
|
||||
|
@ -31,6 +31,7 @@ CONF = config.CONF
|
||||
|
||||
|
||||
class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
|
||||
max_microversion = '2.35'
|
||||
|
||||
@classmethod
|
||||
def skip_checks(cls):
|
||||
|
@ -22,6 +22,7 @@ CONF = config.CONF
|
||||
|
||||
|
||||
class ListImageFiltersNegativeTestJSON(base.BaseV2ComputeTest):
|
||||
max_microversion = '2.35'
|
||||
|
||||
@classmethod
|
||||
def skip_checks(cls):
|
||||
|
@ -21,6 +21,7 @@ CONF = config.CONF
|
||||
|
||||
|
||||
class ListImagesTestJSON(base.BaseV2ComputeTest):
|
||||
max_microversion = '2.35'
|
||||
|
||||
@classmethod
|
||||
def skip_checks(cls):
|
||||
|
@ -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'])
|
||||
|
||||
|
@ -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()]
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user