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
This commit is contained in:
Dan Smith 2020-08-21 12:49:37 -07:00
parent 1580b4d821
commit 8c7342cbc1
1 changed files with 12 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import hashlib
import os
import subprocess
import tempfile
import time
import uuid
from oslo_serialization import jsonutils
@ -5709,7 +5710,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