Merge ~adam-collard/maas:bootsources-proxy into maas:master

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: 7ae93085eada98478bbe482267a288ec77e2a8b9
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas:bootsources-proxy
Merge into: maas:master
Diff against target: 67 lines (+18/-6)
2 files modified
src/maasserver/bootsources.py (+7/-2)
src/maasserver/tests/test_bootsources.py (+11/-4)
Reviewer Review Type Date Requested Status
MAAS Lander Needs Fixing
Alberto Donato (community) Approve
Review via email: mp+408888@code.launchpad.net

Commit message

Remove http{,s}_proxy from environ when fetching bootsources

If MAAS has been configured not to use a HTTP{,/S} proxy, then it will now remove any proxies from the environment it executes simplestreams in to fetch images.

This test was failing before since although not overriding the proxy, we weren't ensuring it was unset.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b bootsources-proxy lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 7abc3218a7c474d3ed1ef85d73aedab409bdfbf1

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

+1

it's a pity that we have to set it globally but I don't see a better way for now

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b bootsources-proxy lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/11048/console
COMMIT: f5b70f44c659c1e38eac198d67f1e7a67843fdc1

review: Needs Fixing
Revision history for this message
Adam Collard (adam-collard) wrote :

jenkins: !test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/bootsources.py b/src/maasserver/bootsources.py
2index 8ca822d..0f3e1f1 100644
3--- a/src/maasserver/bootsources.py
4+++ b/src/maasserver/bootsources.py
5@@ -113,8 +113,8 @@ def get_simplestreams_env():
6 no_proxy_hosts = "127.0.0.1,localhost"
7 # When using a proxy and using an image mirror, we may not want
8 # to use the proxy to download the images, as they could be
9- # localted in the local network, hence it makes no sense to use
10- # it. With this, we add the image mirror localtion(s) to the
11+ # located in the local network, hence it makes no sense to use
12+ # it. With this, we add the image mirror location(s) to the
13 # no proxy variable, which ensures MAAS contacts the mirror
14 # directly instead of through the proxy.
15 no_proxy = Config.objects.get_config("boot_images_no_proxy")
16@@ -124,6 +124,11 @@ def get_simplestreams_env():
17 host = urlparse(source["url"]).netloc.split(":")[0]
18 no_proxy_hosts = ",".join((no_proxy_hosts, host))
19 env["no_proxy"] = no_proxy_hosts
20+ else:
21+ # The proxy is disabled, let's not accidentally use proxy from
22+ # encompassing environment.
23+ env["http_proxy"] = ""
24+ env["https_proxy"] = ""
25 return env
26
27
28diff --git a/src/maasserver/tests/test_bootsources.py b/src/maasserver/tests/test_bootsources.py
29index 5b70e8e..deb3412 100644
30--- a/src/maasserver/tests/test_bootsources.py
31+++ b/src/maasserver/tests/test_bootsources.py
32@@ -7,8 +7,7 @@
33 import html
34 from os import environ
35 import random
36-from unittest import skip
37-from unittest.mock import ANY, MagicMock
38+from unittest.mock import ANY, MagicMock, patch
39
40 from fixtures import EnvironmentVariableFixture
41 from requests.exceptions import ConnectionError
42@@ -410,7 +409,6 @@ class TestPrivateCacheBootSources(MAASTransactionServerTestCase):
43 MockCalledOnceWith(ANY, user_agent=get_maas_user_agent()),
44 )
45
46- @skip("XXX: GavinPanella 2015-12-04 bug=1546235: Fails spuriously.")
47 def test_doesnt_have_env_http_and_https_proxy_set_if_disabled(self):
48 proxy_address = factory.make_name("proxy")
49 Config.objects.set_config("http_proxy", proxy_address)
50@@ -419,7 +417,16 @@ class TestPrivateCacheBootSources(MAASTransactionServerTestCase):
51 self
52 )
53 factory.make_BootSource(keyring_data=b"1234")
54- cache_boot_sources()
55+ env_http_proxy_address = factory.make_name("http-proxy")
56+ env_https_proxy_address = factory.make_name("https-proxy")
57+ with patch.dict(
58+ "os.environ",
59+ {
60+ "http_proxy": env_http_proxy_address,
61+ "https_proxy": env_https_proxy_address,
62+ },
63+ ):
64+ cache_boot_sources()
65 self.assertEqual(
66 ("", ""),
67 (

Subscribers

People subscribed via source and target branches