diff options
author | Zuul <zuul@review.opendev.org> | 2023-02-13 21:34:23 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-02-13 21:34:23 +0000 |
commit | 614b326bde1f26b6d5dcab6a27a4c0af6254e09d (patch) | |
tree | 25df98d2399a0165f60eabcb689fb6099eca8b77 /tempest | |
parent | a9bad0051255327e0a0456a0d46c34f1a6ed4c79 (diff) | |
parent | 1ae54e331e8ed3c332eabbe0bc650615ae809eb5 (diff) | |
download | tempest-614b326bde1f26b6d5dcab6a27a4c0af6254e09d.tar.gz |
Merge "Fix retry_bad_request() context manager"
Diffstat (limited to 'tempest')
-rw-r--r-- | tempest/api/image/v2/test_images.py | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/tempest/api/image/v2/test_images.py b/tempest/api/image/v2/test_images.py index e8734e072..1d05f1366 100644 --- a/tempest/api/image/v2/test_images.py +++ b/tempest/api/image/v2/test_images.py @@ -14,7 +14,6 @@ # License for the specific language governing permissions and limitations # under the License. -import contextlib import io import random import time @@ -29,19 +28,7 @@ from tempest.lib import exceptions as lib_exc CONF = config.CONF LOG = logging.getLogger(__name__) - - -@contextlib.contextmanager -def retry_bad_request(fn): - retries = 3 - for i in range(retries): - try: - yield - except lib_exc.BadRequest: - if i < retries: - time.sleep(1) - else: - raise +BAD_REQUEST_RETRIES = 3 class ImportImagesTest(base.BaseV2ImageTest): @@ -837,9 +824,16 @@ class ImageLocationsTest(base.BaseV2ImageTest): # HTTP, it will return BadRequest. Because this can be transient in # CI, we try this a few times before we agree that it has failed # for a reason worthy of failing the test. - with retry_bad_request(): - self.client.update_image(image['id'], [ - dict(add='/locations/-', value=new_loc)]) + for i in range(BAD_REQUEST_RETRIES): + try: + self.client.update_image(image['id'], [ + dict(add='/locations/-', value=new_loc)]) + break + except lib_exc.BadRequest: + if i + 1 == BAD_REQUEST_RETRIES: + raise + else: + time.sleep(1) # The image should now be active, with one location that looks # like we expect @@ -874,9 +868,16 @@ class ImageLocationsTest(base.BaseV2ImageTest): # HTTP, it will return BadRequest. Because this can be transient in # CI, we try this a few times before we agree that it has failed # for a reason worthy of failing the test. - with retry_bad_request(): - self.client.update_image(image['id'], [ - dict(add='/locations/-', value=new_loc)]) + for i in range(BAD_REQUEST_RETRIES): + try: + self.client.update_image(image['id'], [ + dict(add='/locations/-', value=new_loc)]) + break + except lib_exc.BadRequest: + if i + 1 == BAD_REQUEST_RETRIES: + raise + else: + time.sleep(1) # The image should now have two locations and the last one # (locations are ordered) should have the new URL. |