Retry image download if it's corrupted

Adding IOError in list of catching exceptions in order to
fix behavior when nova-compute wouldn't retry image download
when got "Corrupt image download" error from glanceclient
and had num_retries config option set.

Closes-Bug: #1950657
Change-Id: Iae4fd0579f71d3ba6793dbdb037275352d7e57b0
This commit is contained in:
sdmitriev1 2021-11-18 22:05:05 -05:00
parent 69b0d31d20
commit ce493273b9
3 changed files with 23 additions and 1 deletions

View File

@ -178,7 +178,8 @@ class GlanceClientWrapper(object):
kwargs = kwargs or {}
retry_excs = (glanceclient.exc.ServiceUnavailable,
glanceclient.exc.InvalidEndpoint,
glanceclient.exc.CommunicationError)
glanceclient.exc.CommunicationError,
IOError)
num_attempts = 1 + CONF.glance.num_retries
controller_name = controller or 'images'

View File

@ -464,6 +464,20 @@ class TestGlanceClientWrapperRetries(test.NoDBTestCase):
client = glance.GlanceClientWrapper()
self.assert_retry_attempted(sleep_mock, client, 'https://host2:9293')
@mock.patch('random.shuffle')
@mock.patch('time.sleep')
@mock.patch('nova.image.glance._glanceclient_from_endpoint')
def test_retry_works_for_corrupted_image(self, create_client_mock,
sleep_mock, shuffle_mock):
side_effect = [
IOError,
None
]
self._mock_client_images_response(create_client_mock, side_effect)
self.flags(num_retries=1, group='glance')
client = glance.GlanceClientWrapper()
self.assert_retry_attempted(sleep_mock, client, 'https://host2:9293')
@mock.patch('random.shuffle')
@mock.patch('time.sleep')
@mock.patch('nova.image.glance._glanceclient_from_endpoint')

View File

@ -0,0 +1,7 @@
---
fixes:
- |
`Bug 1950657 <https://bugs.launchpad.net/nova/+bug/1950657>`_, fixing
behavior when nova-compute wouldn't retry image download when gets
"Corrupt image download" error from glanceclient and has num_retries
config option set.