Compute images via addClassResourceCleanup
Cleanup images in compute tests via addClassResourceCleanup. Change-Id: I74b01dfa9e1754f4034046daf03f9404abf40b8e
This commit is contained in:
parent
43afce6b8c
commit
b17f7a380b
@ -117,15 +117,12 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest,
|
|||||||
cls.image_ssh_user = CONF.validation.image_ssh_user
|
cls.image_ssh_user = CONF.validation.image_ssh_user
|
||||||
cls.image_ssh_password = CONF.validation.image_ssh_password
|
cls.image_ssh_password = CONF.validation.image_ssh_password
|
||||||
cls.servers = []
|
cls.servers = []
|
||||||
cls.images = []
|
|
||||||
cls.security_groups = []
|
cls.security_groups = []
|
||||||
cls.server_groups = []
|
cls.server_groups = []
|
||||||
cls.volumes = []
|
cls.volumes = []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resource_cleanup(cls):
|
def resource_cleanup(cls):
|
||||||
cls.clear_resources('images', cls.images,
|
|
||||||
cls.compute_images_client.delete_image)
|
|
||||||
cls.clear_servers()
|
cls.clear_servers()
|
||||||
cls.clear_resources('security groups', cls.security_groups,
|
cls.clear_resources('security groups', cls.security_groups,
|
||||||
cls.security_groups_client.delete_security_group)
|
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,
|
image = cls.compute_images_client.create_image(server_id, name=name,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
image_id = data_utils.parse_image_id(image.response['location'])
|
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:
|
if wait_until is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -20,6 +20,7 @@ from tempest.common import image as common_image
|
|||||||
from tempest.common import waiters
|
from tempest.common import waiters
|
||||||
from tempest import config
|
from tempest import config
|
||||||
from tempest.lib.common.utils import data_utils
|
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 decorators
|
||||||
from tempest.lib import exceptions
|
from tempest.lib import exceptions
|
||||||
|
|
||||||
@ -70,7 +71,9 @@ class ImagesMetadataTestJSON(base.BaseV2ComputeTest):
|
|||||||
body = cls.glance_client.create_image(**params)
|
body = cls.glance_client.create_image(**params)
|
||||||
body = body['image'] if 'image' in body else body
|
body = body['image'] if 'image' in body else body
|
||||||
cls.image_id = body['id']
|
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))
|
image_file = six.BytesIO((b'*' * 1024))
|
||||||
if CONF.image_feature_enabled.api_v1:
|
if CONF.image_feature_enabled.api_v1:
|
||||||
cls.glance_client.update_image(cls.image_id, data=image_file)
|
cls.glance_client.update_image(cls.image_id, data=image_file)
|
||||||
|
@ -74,7 +74,6 @@ class ImagesOneServerTestJSON(base.BaseV2ComputeTest):
|
|||||||
|
|
||||||
# Verify the image was deleted correctly
|
# Verify the image was deleted correctly
|
||||||
self.client.delete_image(image['id'])
|
self.client.delete_image(image['id'])
|
||||||
self.images.remove(image['id'])
|
|
||||||
self.client.wait_for_resource_deletion(image['id'])
|
self.client.wait_for_resource_deletion(image['id'])
|
||||||
|
|
||||||
@decorators.idempotent_id('3b7c6fe4-dfe7-477c-9243-b06359db51e6')
|
@decorators.idempotent_id('3b7c6fe4-dfe7-477c-9243-b06359db51e6')
|
||||||
|
@ -107,7 +107,6 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest):
|
|||||||
|
|
||||||
image_id = data_utils.parse_image_id(image.response['location'])
|
image_id = data_utils.parse_image_id(image.response['location'])
|
||||||
self.client.delete_image(image_id)
|
self.client.delete_image(image_id)
|
||||||
self.images.remove(image_id)
|
|
||||||
|
|
||||||
@decorators.attr(type=['negative'])
|
@decorators.attr(type=['negative'])
|
||||||
@decorators.idempotent_id('084f0cbc-500a-4963-8a4e-312905862581')
|
@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
|
# Do not wait, attempt to delete the image, ensure it's successful
|
||||||
self.client.delete_image(image_id)
|
self.client.delete_image(image_id)
|
||||||
self.images.remove(image_id)
|
|
||||||
self.assertRaises(lib_exc.NotFound,
|
self.assertRaises(lib_exc.NotFound,
|
||||||
self.client.show_image, image_id)
|
self.client.show_image, image_id)
|
||||||
|
@ -23,6 +23,7 @@ from tempest.common import image as common_image
|
|||||||
from tempest.common import waiters
|
from tempest.common import waiters
|
||||||
from tempest import config
|
from tempest import config
|
||||||
from tempest.lib.common.utils import data_utils
|
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 decorators
|
||||||
from tempest.lib import exceptions
|
from tempest.lib import exceptions
|
||||||
|
|
||||||
@ -74,7 +75,10 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
|
|||||||
body = cls.glance_client.create_image(**params)
|
body = cls.glance_client.create_image(**params)
|
||||||
body = body['image'] if 'image' in body else body
|
body = body['image'] if 'image' in body else body
|
||||||
image_id = body['id']
|
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
|
# Wait 1 second between creation and upload to ensure a delta
|
||||||
# between created_at and updated_at.
|
# between created_at and updated_at.
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -37,14 +37,16 @@ class TestBaseV2ComputeTest(base.TestCase):
|
|||||||
fake_image = mock.Mock(response={'location': image_id})
|
fake_image = mock.Mock(response={'location': image_id})
|
||||||
compute_images_client.create_image.return_value = fake_image
|
compute_images_client.create_image.return_value = fake_image
|
||||||
# call the utility method
|
# call the utility method
|
||||||
image = compute_base.BaseV2ComputeTest.create_image_from_server(
|
cleanup_path = 'tempest.test.BaseTestCase.addClassResourceCleanup'
|
||||||
mock.sentinel.server_id, name='fake-snapshot-name')
|
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)
|
self.assertEqual(fake_image, image)
|
||||||
# make our assertions
|
# make our assertions
|
||||||
compute_images_client.create_image.assert_called_once_with(
|
compute_images_client.create_image.assert_called_once_with(
|
||||||
mock.sentinel.server_id, name='fake-snapshot-name')
|
mock.sentinel.server_id, name='fake-snapshot-name')
|
||||||
self.assertEqual(1, len(compute_base.BaseV2ComputeTest.images))
|
mock_cleanup.assert_called_once()
|
||||||
self.assertEqual(image_id, compute_base.BaseV2ComputeTest.images[0])
|
self.assertIn(image_id, mock_cleanup.call_args[0])
|
||||||
|
|
||||||
@mock.patch.multiple(compute_base.BaseV2ComputeTest,
|
@mock.patch.multiple(compute_base.BaseV2ComputeTest,
|
||||||
compute_images_client=mock.DEFAULT,
|
compute_images_client=mock.DEFAULT,
|
||||||
|
Loading…
Reference in New Issue
Block a user