From faa163442beca2844183f25443e3168a87dbeaa8 Mon Sep 17 00:00:00 2001 From: Soniya Vyas Date: Wed, 15 Jan 2020 19:34:57 +0530 Subject: [PATCH] Added fix to 'test_delete_saving_image' testcase 'test_delete_saving_image' fails because image snapshot is produced quicker than tempest being able to catch the 'SAVING' transition. Hence, the testcase needs following refinement:- 1. testcase should catch the state of image in 'SAVING' state only and then delete the image. By this case, we can get the idea that image is deleted in 'SAVING' state only and the testcase will achieve its motto. 2. If the image trasits to a state other than 'SAVING', testcase can just delete the image. Related-Bug: #1713163 Signed-off by: Soniya Vyas Change-Id: I50606c67e9f626935878aaa61d0adbc236272054 --- tempest/api/compute/images/test_images.py | 27 +++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tempest/api/compute/images/test_images.py b/tempest/api/compute/images/test_images.py index 7cf26fb473..eef278114b 100644 --- a/tempest/api/compute/images/test_images.py +++ b/tempest/api/compute/images/test_images.py @@ -12,12 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. +import testtools + from tempest.api.compute import base from tempest.common import waiters from tempest import config from tempest.lib.common.utils import data_utils from tempest.lib import decorators -import testtools +from tempest.lib import exceptions as lib_exceptions CONF = config.CONF @@ -51,12 +53,23 @@ class ImagesTestJSON(base.BaseV2ComputeTest): # in task_state image_snapshot self.addCleanup(waiters.wait_for_server_status, self.servers_client, server['id'], 'ACTIVE') - image = self.create_image_from_server(server['id'], - wait_until='SAVING') - self.client.delete_image(image['id']) - msg = ('The image with ID {image_id} failed to be deleted' - .format(image_id=image['id'])) - self.assertTrue(self.client.is_resource_deleted(image['id']), msg) + snapshot_name = data_utils.rand_name('test-snap') + try: + image = self.create_image_from_server(server['id'], + name=snapshot_name, + wait_until='SAVING') + self.client.delete_image(image['id']) + msg = ('The image with ID {image_id} failed to be deleted' + .format(image_id=image['id'])) + self.assertTrue(self.client.is_resource_deleted(image['id']), + msg) + self.assertEqual(snapshot_name, image['name']) + except lib_exceptions.TimeoutException as ex: + # If timeout is reached, we don't need to check state, + # since, it wouldn't be a 'SAVING' state atleast and apart from + # it, this testcase doesn't have scope for other state transition + # Hence, skip the test. + raise self.skipException("This test is skipped because " + str(ex)) @decorators.idempotent_id('aaacd1d0-55a2-4ce8-818a-b5439df8adc9') def test_create_image_from_stopped_server(self):