diff options
author | Dan Smith <dansmith@redhat.com> | 2023-02-17 06:40:16 -0800 |
---|---|---|
committer | Dan Smith <dms@danplanet.com> | 2023-02-17 16:52:12 +0000 |
commit | 6833a56f256c860bf4cd9305498fe181f60a13df (patch) | |
tree | 845901b74d4ae24d827185d7576a434235eb1a0d | |
parent | b915c7f35ff105d8ac613cc171cd9235a96eac8d (diff) | |
download | tempest-6833a56f256c860bf4cd9305498fe181f60a13df.tar.gz |
Add retries to more glance location tests
This generalizes the retry loop recently added (in haste) and applies
it to another set of tests that do image location updates.
Fixes-Bug: #1999800
Change-Id: Ib6a44a608cc3b6346c4b9fe23c986cb23d11a906
-rw-r--r-- | tempest/api/image/v2/test_images.py | 58 |
1 files changed, 25 insertions, 33 deletions
diff --git a/tempest/api/image/v2/test_images.py b/tempest/api/image/v2/test_images.py index 1d05f1366..b72397782 100644 --- a/tempest/api/image/v2/test_images.py +++ b/tempest/api/image/v2/test_images.py @@ -819,21 +819,8 @@ class ImageLocationsTest(base.BaseV2ImageTest): # Add a new location new_loc = {'metadata': {'foo': 'bar'}, 'url': CONF.image.http_image} - - # NOTE(danms): If glance was unable to fetch the remote image via - # 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. - 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) + self._update_image_with_retries(image['id'], [ + dict(add='/locations/-', value=new_loc)]) # The image should now be active, with one location that looks # like we expect @@ -858,20 +845,14 @@ class ImageLocationsTest(base.BaseV2ImageTest): def test_set_location(self): self._check_set_location() - def _check_set_multiple_locations(self): - image = self._check_set_location() - - new_loc = {'metadata': {'speed': '88mph'}, - 'url': '%s#new' % CONF.image.http_image} - + def _update_image_with_retries(self, image, patch): # NOTE(danms): If glance was unable to fetch the remote image via # 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. for i in range(BAD_REQUEST_RETRIES): try: - self.client.update_image(image['id'], [ - dict(add='/locations/-', value=new_loc)]) + self.client.update_image(image, patch) break except lib_exc.BadRequest: if i + 1 == BAD_REQUEST_RETRIES: @@ -879,6 +860,15 @@ class ImageLocationsTest(base.BaseV2ImageTest): else: time.sleep(1) + def _check_set_multiple_locations(self): + image = self._check_set_location() + + new_loc = {'metadata': {'speed': '88mph'}, + 'url': '%s#new' % CONF.image.http_image} + self._update_image_with_retries(image['id'], + [dict(add='/locations/-', + value=new_loc)]) + # The image should now have two locations and the last one # (locations are ordered) should have the new URL. image = self.client.show_image(image['id']) @@ -989,8 +979,9 @@ class ImageLocationsTest(base.BaseV2ImageTest): 'os_hash_algo': 'sha512'}, 'metadata': {}, 'url': CONF.image.http_image} - self.client.update_image(image['id'], [ - dict(add='/locations/-', value=new_loc)]) + self._update_image_with_retries(image['id'], + [dict(add='/locations/-', + value=new_loc)]) # Expect that all of our values ended up on the image image = self.client.show_image(image['id']) @@ -1017,8 +1008,9 @@ class ImageLocationsTest(base.BaseV2ImageTest): 'os_hash_algo': orig_image['os_hash_algo']}, 'metadata': {}, 'url': '%s#new' % CONF.image.http_image} - self.client.update_image(orig_image['id'], [ - dict(add='/locations/-', value=new_loc)]) + self._update_image_with_retries(orig_image['id'], + [dict(add='/locations/-', + value=new_loc)]) # Setting the same exact values on a new location should work image = self.client.show_image(orig_image['id']) @@ -1052,17 +1044,17 @@ class ImageLocationsTest(base.BaseV2ImageTest): # This should always fail due to the mismatch self.assertRaises(lib_exc.Conflict, - self.client.update_image, - orig_image['id'], [ - dict(add='/locations/-', value=new_loc)]) + self._update_image_with_retries, + orig_image['id'], + [dict(add='/locations/-', value=new_loc)]) # Now try to add a new location with all of the substitutions, # which should also fail new_loc['validation_data'] = values self.assertRaises(lib_exc.Conflict, - self.client.update_image, - orig_image['id'], [ - dict(add='/locations/-', value=new_loc)]) + self._update_image_with_retries, + orig_image['id'], + [dict(add='/locations/-', value=new_loc)]) # Make sure nothing has changed on our image after all the # above failures |