Merge lp:~jtv/maas/bug-1377005-zero-address into lp:~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 3213
Proposed branch: lp:~jtv/maas/bug-1377005-zero-address
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 107 lines (+40/-15)
2 files modified
src/provisioningserver/drivers/osystem/debian_networking.py (+21/-5)
src/provisioningserver/drivers/osystem/tests/test_debian_networking.py (+19/-10)
To merge this branch: bzr merge lp:~jtv/maas/bug-1377005-zero-address
Reviewer Review Type Date Requested Status
Graham Binns (community) Approve
Review via email: mp+237615@code.launchpad.net

Commit message

Disable IPv4 in a new way: configure network interfaces with IP address of 0.0.0.0.

This unfortunately only seems to work in 14.04. But the previous way, of simply not configuring any IPv4, broke IPv6 networking on all nodes that had IPv4 disabled. The workaround was to configure IPv4 addresses anyway, and then remove them again in /etc/rc.local.

Description of the change

Deleting addresses in /etc/rc.local would give us the worst of both worlds: the code that generates the networking config would have to know each interface's IPv4 address, which it currently it doesn't; and there would still be a phase in the boot process where IPv4 was enabled.

Also, it would mean touching an additional file, and merely appending to /etc/rc.local wouldn't do: we'd need to insert a line before the final “exit 0” statement. There would also be a largish warning unless the command passed a netmask, and currently the generating code doesn't have this information.

Jeroen

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

One comment but looks good.

review: Approve
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Thanks. Added the comment.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/drivers/osystem/debian_networking.py'
2--- src/provisioningserver/drivers/osystem/debian_networking.py 2014-10-06 07:09:37 +0000
3+++ src/provisioningserver/drivers/osystem/debian_networking.py 2014-10-09 02:56:43 +0000
4@@ -16,6 +16,8 @@
5 'compose_network_interfaces',
6 ]
7
8+from textwrap import dedent
9+
10 from netaddr import IPAddress
11
12
13@@ -46,9 +48,24 @@
14 return extract_ip_from_sequence(mapping.get(mac, []), ip_version)
15
16
17-def compose_ipv4_stanza(interface):
18- """Return a Debian `/etc/network/interfaces` stanza for DHCPv4."""
19- return "iface %s inet dhcp" % interface
20+def compose_ipv4_stanza(interface, disable=False):
21+ """Return a Debian `/etc/network/interfaces` stanza for DHCPv4.
22+
23+ :param interface: Name of the network interface whose configuration should
24+ be generated.
25+ :param disable: If `True`, generate a stanza to disable the IPv4 address.
26+ If `False` (the default), generate a DHCP stanza.
27+ :return: Text of the interface's IPv4 address configuration stanza.
28+ """
29+ if disable:
30+ return dedent("""\
31+ # MAAS was configured to disable IPv4 networking on this node.
32+ iface %s inet static
33+ \tnetmask 255.255.255.255
34+ \taddress 0.0.0.0
35+ """.rstrip()) % interface
36+ else:
37+ return "iface %s inet dhcp" % interface
38
39
40 def compose_ipv6_stanza(interface, ip, gateway=None, nameserver=None):
41@@ -114,8 +131,7 @@
42 for interface, mac in interfaces:
43 if mac in auto_interfaces:
44 stanzas.append('auto %s' % interface)
45- if not disable_ipv4:
46- stanzas.append(compose_ipv4_stanza(interface))
47+ stanzas.append(compose_ipv4_stanza(interface, disable=disable_ipv4))
48 static_ipv6 = extract_ip(ips_mapping, mac, 6)
49 if static_ipv6 is not None:
50 gateway = extract_ip(gateways_mapping, mac, 6)
51
52=== modified file 'src/provisioningserver/drivers/osystem/tests/test_debian_networking.py'
53--- src/provisioningserver/drivers/osystem/tests/test_debian_networking.py 2014-10-06 07:09:37 +0000
54+++ src/provisioningserver/drivers/osystem/tests/test_debian_networking.py 2014-10-09 02:56:43 +0000
55@@ -27,17 +27,27 @@
56 compose_network_interfaces,
57 has_static_ipv6_address,
58 )
59+from testtools.matchers import Contains
60
61
62 class TestComposeIPv4Stanza(MAASTestCase):
63
64- def test__produces_dhcp_stanza(self):
65+ def test__produces_dhcp_stanza_by_default(self):
66 interface = factory.make_name('eth')
67- expected = "iface %s inet dhcp" % interface
68 self.assertEqual(
69- expected.strip(),
70+ "iface %s inet dhcp" % interface,
71 compose_ipv4_stanza(interface).strip())
72
73+ def test__produces_static_nil_address_if_disabled(self):
74+ interface = factory.make_name('eth')
75+ stanza = compose_ipv4_stanza(interface, disable=True)
76+ self.expectThat(
77+ stanza,
78+ Contains("iface %s inet static\n" % interface))
79+ self.expectThat(
80+ stanza + '\n',
81+ Contains("address 0.0.0.0\n"))
82+
83
84 class TestComposeIPv6Stanza(MAASTestCase):
85
86@@ -152,15 +162,14 @@
87 self.make_listing(interface, mac), [], {}, {},
88 disable_ipv4=True))
89
90- def test__generates_no_DHCPv4_config_if_node_should_use_IPv6_only(self):
91+ def test__disables_IPv4_statically_if_IPv4_disabled(self):
92+ interface = factory.make_name('eth')
93 mac = factory.make_mac_address()
94- # The space is significant: we're expecting an inet6 line, so don't
95- # match that when we look for inet.
96- self.assertNotIn(
97- " inet ",
98+ self.assertIn(
99+ "\niface %s inet static" % interface,
100 compose_network_interfaces(
101- self.make_listing(mac=mac), [], self.make_mapping(mac), {},
102- disable_ipv4=True))
103+ self.make_listing(interface, mac), [], self.make_mapping(mac),
104+ {}, disable_ipv4=True))
105
106 def test__generates_static_IPv6_config(self):
107 interface = factory.make_name('eth')