diff --git a/fuel_agent/tests/test_artifact_utils.py b/fuel_agent/tests/test_artifact_utils.py index 2cdde06f..76f86319 100644 --- a/fuel_agent/tests/test_artifact_utils.py +++ b/fuel_agent/tests/test_artifact_utils.py @@ -87,6 +87,22 @@ class TestHttpUrl(unittest2.TestCase): for data in enumerate(httpurl): self.assertEqual(content[data[0]], data[1]) + @mock.patch.object(utils, 'init_http_request') + def test_httpurl_next_slow_connection(self, mock_req): + url = "http://fake_url" + content = ['fake content #1', '', 'fake content #2'] + req_mock = mock.Mock(headers={'content-length': 30}) + req_mock.raw.read.side_effect = content + mock_req.return_value = req_mock + http_url = au.HttpUrl(url) + + for data in content: + if data: + self.assertEqual(data, next(http_url)) + expected_calls = [mock.call(url), + mock.call(url, byte_range=len(content[0]))] + self.assertEqual(expected_calls, mock_req.call_args_list) + class TestGunzipStream(unittest2.TestCase): def test_gunzip_stream_next(self): diff --git a/fuel_agent/utils/artifact.py b/fuel_agent/utils/artifact.py index 56c5fed7..b71d7952 100644 --- a/fuel_agent/utils/artifact.py +++ b/fuel_agent/utils/artifact.py @@ -110,7 +110,7 @@ class HttpUrl(Target): except Exception as exc: LOG.exception(exc) self.response_obj = utils.init_http_request( - self.url, self.processed_bytes) + self.url, byte_range=self.processed_bytes) continue else: self.processed_bytes += len(data) diff --git a/fuel_agent/utils/utils.py b/fuel_agent/utils/utils.py index 637c6574..6d12f459 100644 --- a/fuel_agent/utils/utils.py +++ b/fuel_agent/utils/utils.py @@ -222,7 +222,7 @@ def should_bypass_proxy(url, noproxy_addrs): return False -def init_http_request(url, proxies=None, noproxy_addrs=None, byte_range=0): +def init_http_request(url, byte_range=0, proxies=None, noproxy_addrs=None): LOG.debug("Trying to initialize http request object %s, byte range: %s", url, byte_range) if should_bypass_proxy(url, noproxy_addrs):