Compute images via addClassResourceCleanup

Cleanup images in compute tests via addClassResourceCleanup.

Change-Id: I74b01dfa9e1754f4034046daf03f9404abf40b8e
This commit is contained in:
Andrea Frittoli 2017-08-29 17:45:58 +01:00
parent 43afce6b8c
commit b17f7a380b
6 changed files with 18 additions and 13 deletions

View File

@ -117,15 +117,12 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest,
cls.image_ssh_user = CONF.validation.image_ssh_user
cls.image_ssh_password = CONF.validation.image_ssh_password
cls.servers = []
cls.images = []
cls.security_groups = []
cls.server_groups = []
cls.volumes = []
@classmethod
def resource_cleanup(cls):
cls.clear_resources('images', cls.images,
cls.compute_images_client.delete_image)
cls.clear_servers()
cls.clear_resources('security groups', cls.security_groups,
cls.security_groups_client.delete_security_group)
@ -293,7 +290,9 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest,
image = cls.compute_images_client.create_image(server_id, name=name,
**kwargs)
image_id = data_utils.parse_image_id(image.response['location'])
cls.images.append(image_id)
cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,
cls.compute_images_client.delete_image,
image_id)
if wait_until is not None:
try:

View File

@ -20,6 +20,7 @@ from tempest.common import image as common_image
from tempest.common import waiters
from tempest import config
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators
from tempest.lib import exceptions
@ -70,7 +71,9 @@ class ImagesMetadataTestJSON(base.BaseV2ComputeTest):
body = cls.glance_client.create_image(**params)
body = body['image'] if 'image' in body else body
cls.image_id = body['id']
cls.images.append(cls.image_id)
cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,
cls.compute_images_client.delete_image,
cls.image_id)
image_file = six.BytesIO((b'*' * 1024))
if CONF.image_feature_enabled.api_v1:
cls.glance_client.update_image(cls.image_id, data=image_file)

View File

@ -74,7 +74,6 @@ class ImagesOneServerTestJSON(base.BaseV2ComputeTest):
# Verify the image was deleted correctly
self.client.delete_image(image['id'])
self.images.remove(image['id'])
self.client.wait_for_resource_deletion(image['id'])
@decorators.idempotent_id('3b7c6fe4-dfe7-477c-9243-b06359db51e6')

View File

@ -107,7 +107,6 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest):
image_id = data_utils.parse_image_id(image.response['location'])
self.client.delete_image(image_id)
self.images.remove(image_id)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('084f0cbc-500a-4963-8a4e-312905862581')
@ -130,6 +129,5 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest):
# Do not wait, attempt to delete the image, ensure it's successful
self.client.delete_image(image_id)
self.images.remove(image_id)
self.assertRaises(lib_exc.NotFound,
self.client.show_image, image_id)

View File

@ -23,6 +23,7 @@ from tempest.common import image as common_image
from tempest.common import waiters
from tempest import config
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators
from tempest.lib import exceptions
@ -74,7 +75,10 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
body = cls.glance_client.create_image(**params)
body = body['image'] if 'image' in body else body
image_id = body['id']
cls.images.append(image_id)
cls.addClassResourceCleanup(
test_utils.call_and_ignore_notfound_exc,
cls.compute_images_client.delete_image,
image_id)
# Wait 1 second between creation and upload to ensure a delta
# between created_at and updated_at.
time.sleep(1)

View File

@ -37,14 +37,16 @@ class TestBaseV2ComputeTest(base.TestCase):
fake_image = mock.Mock(response={'location': image_id})
compute_images_client.create_image.return_value = fake_image
# call the utility method
image = compute_base.BaseV2ComputeTest.create_image_from_server(
mock.sentinel.server_id, name='fake-snapshot-name')
cleanup_path = 'tempest.test.BaseTestCase.addClassResourceCleanup'
with mock.patch(cleanup_path) as mock_cleanup:
image = compute_base.BaseV2ComputeTest.create_image_from_server(
mock.sentinel.server_id, name='fake-snapshot-name')
self.assertEqual(fake_image, image)
# make our assertions
compute_images_client.create_image.assert_called_once_with(
mock.sentinel.server_id, name='fake-snapshot-name')
self.assertEqual(1, len(compute_base.BaseV2ComputeTest.images))
self.assertEqual(image_id, compute_base.BaseV2ComputeTest.images[0])
mock_cleanup.assert_called_once()
self.assertIn(image_id, mock_cleanup.call_args[0])
@mock.patch.multiple(compute_base.BaseV2ComputeTest,
compute_images_client=mock.DEFAULT,