Skip to content

Commit 233b9ee

Browse files
xtrusiadosaboy
authored andcommitted
Use https proxy for redirected image downloads
get_urllib_opener only set an http proxy from TEST_HTTP_PROXY. Image downloads start on http://download.cirros-cloud.net but the server now redirects to https://github.com, and with an http-only ProxyHandler the https request bypasses the proxy and connects directly. Where external access is only reachable through a proxy this times out. Also set an https proxy from TEST_HTTPS_PROXY (falling back to TEST_HTTP_PROXY) so the redirected https request goes through the proxy. Signed-off-by: Seyeong Kim <seyeong.kim@canonical.com>
1 parent cf36c08 commit 233b9ee

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

unit_tests/utilities/test_zaza_utilities_openstack.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ def test_get_urllib_opener_proxy(self):
327327
self.ProxyHandler.return_value = ProxyHandler_mock
328328
openstack_utils.get_urllib_opener()
329329
self.build_opener.assert_called_once_with(ProxyHandler_mock)
330-
self.ProxyHandler.assert_called_once_with({'http': 'http://squidy'})
330+
self.ProxyHandler.assert_called_once_with(
331+
{'http': 'http://squidy', 'https': 'http://squidy'})
331332

332333
def test_get_images_by_name(self):
333334
image_mock1 = mock.MagicMock()

zaza/openstack/utilities/openstack.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,15 +2434,27 @@ def get_urllib_opener():
24342434
via TEST_HTTP_PROXY rather than http_proxy so a ProxyHandler is needed
24352435
explicitly stating the proxies.
24362436
2437+
Both http and https proxies are configured: some image downloads are
2438+
served over http but redirect to https (cirros now redirects to
2439+
github.com), so an http-only proxy would let the https request bypass
2440+
the proxy and fail where external access is proxy-only.
2441+
24372442
:returns: An opener which opens URLs via BaseHandlers chained together
24382443
:rtype: urllib.request.OpenerDirector
24392444
"""
24402445
deploy_env = deployment_env.get_deployment_context()
24412446
http_proxy = deploy_env.get('TEST_HTTP_PROXY')
2442-
logging.debug('TEST_HTTP_PROXY: {}'.format(http_proxy))
2447+
https_proxy = deploy_env.get('TEST_HTTPS_PROXY') or http_proxy
2448+
logging.debug('TEST_HTTP_PROXY: {} TEST_HTTPS_PROXY: {}'.format(
2449+
http_proxy, https_proxy))
24432450

2451+
proxies = {}
24442452
if http_proxy:
2445-
handler = urllib.request.ProxyHandler({'http': http_proxy})
2453+
proxies['http'] = http_proxy
2454+
if https_proxy:
2455+
proxies['https'] = https_proxy
2456+
if proxies:
2457+
handler = urllib.request.ProxyHandler(proxies)
24462458
else:
24472459
handler = urllib.request.HTTPHandler()
24482460
return urllib.request.build_opener(handler)

0 commit comments

Comments
 (0)