From 0895d19197ab6313ef80294fe33807a4a71a44ea Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 21 Aug 2020 12:49:37 -0700 Subject: [PATCH] Make test_copy_image_revert_lifecycle handle 409 on import retry This test is very racy in general, and specifically on the post-revert retry to do the import, it may start the next import before the previous one has finished reverting. This patch makes it retry a few times with delay if an HTTP 409 is received so it is tolerant of that situation once it becomes possible in the subsequent patch to add import locking. Change-Id: Ic933f170d43b290fd819e8527ecb60be7f7f3f89 (cherry picked from commit 8c7342cbc15fdbcbafa1ead9aa183e45862cf177) --- glance/tests/functional/v2/test_images.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/glance/tests/functional/v2/test_images.py b/glance/tests/functional/v2/test_images.py index a2f8156a32..311d5637e4 100644 --- a/glance/tests/functional/v2/test_images.py +++ b/glance/tests/functional/v2/test_images.py @@ -15,6 +15,7 @@ import hashlib import os +import time import uuid from oslo_serialization import jsonutils @@ -5616,7 +5617,17 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest): {'method': {'name': 'copy-image'}, 'stores': ['file2', 'file3'], 'all_stores_must_succeed': False}) - response = requests.post(path, headers=headers, data=data) + + for i in range(0, 5): + response = requests.post(path, headers=headers, data=data) + if response.status_code != http.CONFLICT: + break + # We might race with the revert of the previous task and do not + # really have a good way to make sure that it's done. In order + # to make sure we tolerate the 409 possibility when import + # locking is added, gracefully wait a few times before failing. + time.sleep(1) + self.assertEqual(http.ACCEPTED, response.status_code) # Verify image is copied