From 5b36c36896a3aabf02593eaa43f64b8d5d7ad8b0 Mon Sep 17 00:00:00 2001 From: Ghanshyam Mann Date: Tue, 29 Dec 2020 16:22:30 -0600 Subject: [PATCH] Fix race condition for image test If first image is not captured in saving state, then we should skip the test - test_create_second_image_when_first_image_is_being_saved Test is for creating the another image is first one is in saving state and if image creation operation is fast and it gets created before second API request then this test will fail on its assert. To handle the test scope and this race condition, we need to assert on second operation if image is in saving state.This can be done via capturing the timeout exception from first image creation and waiting for saving state. Change-Id: Id59f7ebb223f968109917182e29267faa808a072 Closes-Bug: #1881592 --- .../images/test_images_oneserver_negative.py | 34 ++++++++++++------- ...t-integrated-gate-compute-exclude-list.txt | 6 ---- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/tempest/api/compute/images/test_images_oneserver_negative.py b/tempest/api/compute/images/test_images_oneserver_negative.py index 0296220bc2..275a26f76b 100644 --- a/tempest/api/compute/images/test_images_oneserver_negative.py +++ b/tempest/api/compute/images/test_images_oneserver_negative.py @@ -110,20 +110,30 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest): Creating another server image when first image is being saved is not allowed. """ - # Create first snapshot - image = self.create_image_from_server(self.server_id) - self.addCleanup(self._reset_server) + try: + # Create first snapshot + image = self.create_image_from_server(self.server_id) + self.addCleanup(self._reset_server) - # Create second snapshot - self.assertRaises(lib_exc.Conflict, self.create_image_from_server, - self.server_id) + # Create second snapshot + self.assertRaises(lib_exc.Conflict, self.create_image_from_server, + self.server_id) - if api_version_utils.compare_version_header_to_response( - "OpenStack-API-Version", "compute 2.45", image.response, "lt"): - image_id = image['image_id'] - else: - image_id = data_utils.parse_image_id(image.response['location']) - self.client.delete_image(image_id) + if api_version_utils.compare_version_header_to_response( + "OpenStack-API-Version", "compute 2.45", image.response, "lt"): + image_id = image['image_id'] + else: + image_id = data_utils.parse_image_id( + image.response['location']) + self.client.delete_image(image_id) + + except lib_exc.TimeoutException as ex: + # Test cannot capture the image saving state. + # 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.attr(type=['negative']) @decorators.idempotent_id('084f0cbc-500a-4963-8a4e-312905862581') diff --git a/tools/tempest-integrated-gate-compute-exclude-list.txt b/tools/tempest-integrated-gate-compute-exclude-list.txt index 2290751736..88052620f6 100644 --- a/tools/tempest-integrated-gate-compute-exclude-list.txt +++ b/tools/tempest-integrated-gate-compute-exclude-list.txt @@ -11,9 +11,3 @@ tempest.api.object_storage tempest.scenario.test_object_storage_basic_ops.TestObjectStorageBasicOps.test_swift_basic_ops tempest.scenario.test_object_storage_basic_ops.TestObjectStorageBasicOps.test_swift_acl_anonymous_download tempest.scenario.test_volume_backup_restore.TestVolumeBackupRestore.test_volume_backup_restore - -# Skip test scenario when creating second image from instance -# https://bugs.launchpad.net/tripleo/+bug/1881592 -# The test is most likely wrong and may fail if the fists image is create quickly. -# FIXME: Either fix the test so it won't race or consider if we should cover the scenario at all. -tempest.api.compute.images.test_images_oneserver_negative.ImagesOneServerNegativeTestJSON.test_create_second_image_when_first_image_is_being_saved