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
diff --git a/tempest/api/compute/images/test_images_oneserver_negative.py b/tempest/api/compute/images/test_images_oneserver_negative.py
index 0296220..275a26f 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 @@
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 2290751..8805262 100644
--- a/tools/tempest-integrated-gate-compute-exclude-list.txt
+++ b/tools/tempest-integrated-gate-compute-exclude-list.txt
@@ -11,9 +11,3 @@
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