From ce493273b9404530dfa8ecfe3eaa3d6c81a20e39 Mon Sep 17 00:00:00 2001 From: sdmitriev1 Date: Thu, 18 Nov 2021 22:05:05 -0500 Subject: [PATCH] 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 --- nova/image/glance.py | 3 ++- nova/tests/unit/image/test_glance.py | 14 ++++++++++++++ ...-retry-corrupted-download-5798b0df44a00e4e.yaml | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/bug-retry-corrupted-download-5798b0df44a00e4e.yaml diff --git a/nova/image/glance.py b/nova/image/glance.py index 870e1cd9a002..666bc30a66e1 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -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' diff --git a/nova/tests/unit/image/test_glance.py b/nova/tests/unit/image/test_glance.py index 163a6ddc60b3..f8fbe3fbd183 100644 --- a/nova/tests/unit/image/test_glance.py +++ b/nova/tests/unit/image/test_glance.py @@ -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') diff --git a/releasenotes/notes/bug-retry-corrupted-download-5798b0df44a00e4e.yaml b/releasenotes/notes/bug-retry-corrupted-download-5798b0df44a00e4e.yaml new file mode 100644 index 000000000000..e61132ec33fd --- /dev/null +++ b/releasenotes/notes/bug-retry-corrupted-download-5798b0df44a00e4e.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + `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.