Merge ~andreserl/maas:lp1790015_ipv6 into maas:master

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: 2bb405d7003311cf7d521692664ff35730bdc391
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~andreserl/maas:lp1790015_ipv6
Merge into: maas:master
Diff against target: 97 lines (+29/-6)
2 files modified
src/provisioningserver/rpc/boot_images.py (+11/-2)
src/provisioningserver/rpc/tests/test_boot_images.py (+18/-4)
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
MAAS Lander Needs Fixing
Review via email: mp+354133@code.launchpad.net

Commit message

LP: #1790015 - Fix no_proxy to also use IPv6 addresses inside brackets.

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

UNIT TESTS
-b lp1790015_ipv6 lp:~andreserl/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/3821/console
COMMIT: 15682bf000493f2c953f163fada25f6b2a0bc4af

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

UNIT TESTS
-b lp1790015_ipv6 lp:~andreserl/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/3822/console
COMMIT: 3497b173d796be08ebf43465c13771316bb3af80

review: Needs Fixing
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

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

UNABLE TO START LANDING

STATUS: MISSING COMMIT MESSAGE

~andreserl/maas:lp1790015_ipv6 updated
2bb405d... by Andres Rodriguez

Fix tests which was cuasing infinite loop

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/provisioningserver/rpc/boot_images.py b/src/provisioningserver/rpc/boot_images.py
index def25e3..9a23d49 100644
--- a/src/provisioningserver/rpc/boot_images.py
+++ b/src/provisioningserver/rpc/boot_images.py
@@ -63,12 +63,19 @@ def reload_boot_images():
6363
6464
65def get_hosts_from_sources(sources):65def get_hosts_from_sources(sources):
66 """Return set of hosts that are contained in the given sources."""66 """Return set of hosts that are contained in the given sources.
67
68 If the host is an IPv6 address, we also return it in the format
69 of [<ipv6-address>] because things like no_proxy (which this
70 function is used for), need it that way."""
67 hosts = set()71 hosts = set()
68 for source in sources:72 for source in sources:
69 url = urlparse(source['url'])73 url = urlparse(source['url'])
70 if url.hostname is not None:74 if url.hostname is not None:
71 hosts.add(url.hostname)75 hosts.add(url.hostname)
76 # If it's the IPv6 address, we add also add it inside []
77 if ':' in url.hostname:
78 hosts.add('[%s]' % url.hostname)
72 return hosts79 return hosts
7380
7481
@@ -110,7 +117,9 @@ def _run_import(sources, maas_url, http_proxy=None, https_proxy=None):
110 if https_proxy is not None:117 if https_proxy is not None:
111 variables['https_proxy'] = https_proxy118 variables['https_proxy'] = https_proxy
112 # Communication to the sources and loopback should not go through proxy.119 # Communication to the sources and loopback should not go through proxy.
113 no_proxy_hosts = ["localhost", "::ffff:127.0.0.1", "127.0.0.1", "::1"]120 no_proxy_hosts = [
121 "localhost", "::ffff:127.0.0.1", "127.0.0.1", "::1",
122 "[::ffff:127.0.0.1]", "[::1]"]
114 no_proxy_hosts += list(get_hosts_from_sources(sources))123 no_proxy_hosts += list(get_hosts_from_sources(sources))
115 variables['no_proxy'] = ','.join(no_proxy_hosts)124 variables['no_proxy'] = ','.join(no_proxy_hosts)
116 with environment_variables(variables):125 with environment_variables(variables):
diff --git a/src/provisioningserver/rpc/tests/test_boot_images.py b/src/provisioningserver/rpc/tests/test_boot_images.py
index bc7e797..43e00cd 100644
--- a/src/provisioningserver/rpc/tests/test_boot_images.py
+++ b/src/provisioningserver/rpc/tests/test_boot_images.py
@@ -11,6 +11,7 @@ from unittest.mock import (
11 ANY,11 ANY,
12 sentinel,12 sentinel,
13)13)
14from urllib.parse import urlparse
1415
15from maastesting.factory import factory16from maastesting.factory import factory
16from maastesting.matchers import (17from maastesting.matchers import (
@@ -57,7 +58,9 @@ from twisted.internet.task import Clock
5758
5859
59def make_sources():60def make_sources():
60 hosts = [factory.make_name('host').lower() for _ in range(3)]61 hosts = [factory.make_hostname().lower() for _ in range(2)]
62 hosts.append(factory.make_ipv4_address())
63 hosts.append("[%s]" % factory.make_ipv6_address())
61 urls = [64 urls = [
62 'http://%s:%s/images-stream/streams/v1/index.json' % (65 'http://%s:%s/images-stream/streams/v1/index.json' % (
63 host, randint(1, 1000))66 host, randint(1, 1000))
@@ -119,7 +122,16 @@ class TestReloadBootImages(MAASTestCase):
119class TestGetHostsFromSources(MAASTestCase):122class TestGetHostsFromSources(MAASTestCase):
120123
121 def test__returns_set_of_hosts_from_sources(self):124 def test__returns_set_of_hosts_from_sources(self):
122 sources, hosts = make_sources()125 sources, _ = make_sources()
126 hosts = set()
127 for source in sources:
128 # Use the source to obtain the hosts and add it to a list.
129 host = urlparse(source["url"]).hostname
130 hosts.add(host)
131 # If the host is an IPv6 address, add an extra fixed IPv6
132 # with brackets.
133 if ':' in host:
134 hosts.add("[%s]" % host)
123 self.assertItemsEqual(hosts, get_hosts_from_sources(sources))135 self.assertItemsEqual(hosts, get_hosts_from_sources(sources))
124136
125137
@@ -240,7 +252,8 @@ class TestRunImport(MAASTestCase):
240 _run_import(sources=[], maas_url=factory.make_simple_http_url())252 _run_import(sources=[], maas_url=factory.make_simple_http_url())
241 self.assertEqual(253 self.assertEqual(
242 fake.env['no_proxy'],254 fake.env['no_proxy'],
243 "localhost,::ffff:127.0.0.1,127.0.0.1,::1")255 ("localhost,::ffff:127.0.0.1,127.0.0.1,::1,"
256 "[::ffff:127.0.0.1],[::1]"))
244257
245 def test__run_import_sets_proxy_for_source_host(self):258 def test__run_import_sets_proxy_for_source_host(self):
246 host = factory.make_name("host").lower()259 host = factory.make_name("host").lower()
@@ -250,7 +263,8 @@ class TestRunImport(MAASTestCase):
250 _run_import(sources=sources, maas_url=maas_url)263 _run_import(sources=sources, maas_url=maas_url)
251 self.assertItemsEqual(264 self.assertItemsEqual(
252 fake.env['no_proxy'].split(','),265 fake.env['no_proxy'].split(','),
253 ["localhost", "::ffff:127.0.0.1", "127.0.0.1", "::1"] + [host])266 ["localhost", "::ffff:127.0.0.1", "127.0.0.1", "::1",
267 "[::ffff:127.0.0.1]", "[::1]"] + [host])
254268
255 def test__run_import_accepts_sources_parameter(self):269 def test__run_import_accepts_sources_parameter(self):
256 fake = self.patch(boot_resources, 'import_images')270 fake = self.patch(boot_resources, 'import_images')

Subscribers

People subscribed via source and target branches