Fix get_release_file retries

Due to fact that mirrors are not always up, there is very rare possibility
 that client will waste time of full bootstrap image building due to 2-3
 second downtime of a mirror. Also, due specific work-flow of fuel mirrors
 that may introduces instability to CI jobs.

Conflicts:

	bareon/tests/test_utils.py

Change-Id: Icecc1f4e355713ee95ac5e8d0d13ea326630c056
Closes-bug: #1563366
This commit is contained in:
alexz 2016-05-13 14:26:16 +03:00 committed by Alexander Gordeev
parent 4e249de7e8
commit da6b43bf83
2 changed files with 11 additions and 2 deletions

View File

@ -244,6 +244,14 @@ class ExecuteTestCase(unittest2.TestCase):
self.assertRaises(errors.HttpUrlConnectionError,
utils.init_http_request, 'http://fake_url')
@mock.patch('time.sleep')
@mock.patch.object(requests, 'get')
def test_init_http_request_max_retries_exceeded_HTTPerror(
self, mock_req, mock_s):
mock_req.side_effect = requests.exceptions.HTTPError
self.assertRaises(errors.HttpUrlConnectionError,
utils.init_http_request, 'http://fake_url')
@mock.patch('bareon.utils.utils.os.makedirs')
@mock.patch('bareon.utils.utils.os.path.isdir', return_value=False)
def test_makedirs_if_not_exists(self, mock_isdir, mock_makedirs):

View File

@ -255,12 +255,14 @@ def init_http_request(url, byte_range=0, proxies=None, noproxy_addrs=None):
timeout=CONF.http_request_timeout,
headers={'Range': 'bytes=%s-' % byte_range},
proxies=proxies)
response_obj.raise_for_status()
except (socket.timeout,
urllib3.exceptions.DecodeError,
urllib3.exceptions.ProxyError,
requests.exceptions.ConnectionError,
requests.exceptions.Timeout,
requests.exceptions.TooManyRedirects) as e:
requests.exceptions.TooManyRedirects,
requests.exceptions.HTTPError) as e:
LOG.debug("Got non-critical error when accessing to %s "
"on %s attempt: %s", url, retry + 1, e)
else:
@ -272,7 +274,6 @@ def init_http_request(url, byte_range=0, proxies=None, noproxy_addrs=None):
else:
raise errors.HttpUrlConnectionError(
"Exceeded maximum http request retries for %s".format(url))
response_obj.raise_for_status()
return response_obj