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
1diff --git a/src/provisioningserver/rpc/boot_images.py b/src/provisioningserver/rpc/boot_images.py
2index def25e3..9a23d49 100644
3--- a/src/provisioningserver/rpc/boot_images.py
4+++ b/src/provisioningserver/rpc/boot_images.py
5@@ -63,12 +63,19 @@ def reload_boot_images():
6
7
8 def get_hosts_from_sources(sources):
9- """Return set of hosts that are contained in the given sources."""
10+ """Return set of hosts that are contained in the given sources.
11+
12+ If the host is an IPv6 address, we also return it in the format
13+ of [<ipv6-address>] because things like no_proxy (which this
14+ function is used for), need it that way."""
15 hosts = set()
16 for source in sources:
17 url = urlparse(source['url'])
18 if url.hostname is not None:
19 hosts.add(url.hostname)
20+ # If it's the IPv6 address, we add also add it inside []
21+ if ':' in url.hostname:
22+ hosts.add('[%s]' % url.hostname)
23 return hosts
24
25
26@@ -110,7 +117,9 @@ def _run_import(sources, maas_url, http_proxy=None, https_proxy=None):
27 if https_proxy is not None:
28 variables['https_proxy'] = https_proxy
29 # Communication to the sources and loopback should not go through proxy.
30- no_proxy_hosts = ["localhost", "::ffff:127.0.0.1", "127.0.0.1", "::1"]
31+ no_proxy_hosts = [
32+ "localhost", "::ffff:127.0.0.1", "127.0.0.1", "::1",
33+ "[::ffff:127.0.0.1]", "[::1]"]
34 no_proxy_hosts += list(get_hosts_from_sources(sources))
35 variables['no_proxy'] = ','.join(no_proxy_hosts)
36 with environment_variables(variables):
37diff --git a/src/provisioningserver/rpc/tests/test_boot_images.py b/src/provisioningserver/rpc/tests/test_boot_images.py
38index bc7e797..43e00cd 100644
39--- a/src/provisioningserver/rpc/tests/test_boot_images.py
40+++ b/src/provisioningserver/rpc/tests/test_boot_images.py
41@@ -11,6 +11,7 @@ from unittest.mock import (
42 ANY,
43 sentinel,
44 )
45+from urllib.parse import urlparse
46
47 from maastesting.factory import factory
48 from maastesting.matchers import (
49@@ -57,7 +58,9 @@ from twisted.internet.task import Clock
50
51
52 def make_sources():
53- hosts = [factory.make_name('host').lower() for _ in range(3)]
54+ hosts = [factory.make_hostname().lower() for _ in range(2)]
55+ hosts.append(factory.make_ipv4_address())
56+ hosts.append("[%s]" % factory.make_ipv6_address())
57 urls = [
58 'http://%s:%s/images-stream/streams/v1/index.json' % (
59 host, randint(1, 1000))
60@@ -119,7 +122,16 @@ class TestReloadBootImages(MAASTestCase):
61 class TestGetHostsFromSources(MAASTestCase):
62
63 def test__returns_set_of_hosts_from_sources(self):
64- sources, hosts = make_sources()
65+ sources, _ = make_sources()
66+ hosts = set()
67+ for source in sources:
68+ # Use the source to obtain the hosts and add it to a list.
69+ host = urlparse(source["url"]).hostname
70+ hosts.add(host)
71+ # If the host is an IPv6 address, add an extra fixed IPv6
72+ # with brackets.
73+ if ':' in host:
74+ hosts.add("[%s]" % host)
75 self.assertItemsEqual(hosts, get_hosts_from_sources(sources))
76
77
78@@ -240,7 +252,8 @@ class TestRunImport(MAASTestCase):
79 _run_import(sources=[], maas_url=factory.make_simple_http_url())
80 self.assertEqual(
81 fake.env['no_proxy'],
82- "localhost,::ffff:127.0.0.1,127.0.0.1,::1")
83+ ("localhost,::ffff:127.0.0.1,127.0.0.1,::1,"
84+ "[::ffff:127.0.0.1],[::1]"))
85
86 def test__run_import_sets_proxy_for_source_host(self):
87 host = factory.make_name("host").lower()
88@@ -250,7 +263,8 @@ class TestRunImport(MAASTestCase):
89 _run_import(sources=sources, maas_url=maas_url)
90 self.assertItemsEqual(
91 fake.env['no_proxy'].split(','),
92- ["localhost", "::ffff:127.0.0.1", "127.0.0.1", "::1"] + [host])
93+ ["localhost", "::ffff:127.0.0.1", "127.0.0.1", "::1",
94+ "[::ffff:127.0.0.1]", "[::1]"] + [host])
95
96 def test__run_import_accepts_sources_parameter(self):
97 fake = self.patch(boot_resources, 'import_images')

Subscribers

People subscribed via source and target branches