diff --git a/bareon/tests/test_utils.py b/bareon/tests/test_utils.py index 181fa48..5fe0be7 100644 --- a/bareon/tests/test_utils.py +++ b/bareon/tests/test_utils.py @@ -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): diff --git a/bareon/utils/utils.py b/bareon/utils/utils.py index 2a38250..0af6cf9 100644 --- a/bareon/utils/utils.py +++ b/bareon/utils/utils.py @@ -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