Merge lp:~jtv/maas/bug-1379641-pass-netmasks 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: 3234
Proposed branch: lp:~jtv/maas/bug-1379641-pass-netmasks
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 207 lines (+38/-17)
9 files modified
src/maasserver/clusterrpc/osystems.py (+3/-1)
src/maasserver/networking_preseed.py (+2/-0)
src/maasserver/tests/test_networking_preseed.py (+3/-0)
src/provisioningserver/drivers/osystem/__init__.py (+4/-1)
src/provisioningserver/drivers/osystem/debian_networking.py (+5/-1)
src/provisioningserver/drivers/osystem/ubuntu.py (+3/-2)
src/provisioningserver/rpc/clusterservice.py (+2/-1)
src/provisioningserver/rpc/osystems.py (+7/-5)
src/provisioningserver/rpc/tests/test_osystems.py (+9/-6)
To merge this branch: bzr merge lp:~jtv/maas/bug-1379641-pass-netmasks
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Gavin Panella (community) Approve
Review via email: mp+237899@code.launchpad.net

Commit message

Add parameter to generation of Curtin network preseeds: netmasks. This is in support of non-64-bit IPv6 netmasks, but it also takes away an obstacle to static IPv4 configuration.

The new parameter is not yet used, nor is it populated. I'm leaving that for separate branches because just the parameter-passing (esp. across RPC) generates so many boilerplate changes.

Description of the change

Post-release we can restructure the way these parameters are passed, e.g. by grouping address, netmask, and gateway into a single dict. But for now the incremental change is still the path of least resistance, tedious as it looks.

(It may look odd that netmasks are mapped out by IP address, not by MAC address like some other items are. The reason is that a single network interface can have multiple IP addresses.)

Jeroen

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve
Revision history for this message
Raphaël Badin (rvb) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/clusterrpc/osystems.py'
2--- src/maasserver/clusterrpc/osystems.py 2014-10-06 10:03:17 +0000
3+++ src/maasserver/clusterrpc/osystems.py 2014-10-10 06:31:47 +0000
4@@ -167,7 +167,9 @@
5 `gateways_mapping` maps to a dict which maps MAC addresses to lists of
6 gateway IP addresses (at most one IPv4 and one IPv6) to be used by the
7 corresponding network interfaces.
8- 'nameservers' maps to a list of DNS servers for the node to use.
9+ `nameservers` maps to a list of DNS servers for the node to use.
10+ `netmasks` maps IP addresses from `ips_mapping` to their respective
11+ netmask strings.
12 :return: A list of preseed dicts.
13 """
14 client = getClientFor(node.nodegroup.uuid)
15
16=== modified file 'src/maasserver/networking_preseed.py'
17--- src/maasserver/networking_preseed.py 2014-10-09 16:05:01 +0000
18+++ src/maasserver/networking_preseed.py 2014-10-10 06:31:47 +0000
19@@ -331,6 +331,8 @@
20 'ips_mapping': map_static_ips(node),
21 'gateways_mapping': map_gateways(node),
22 'nameservers': list_dns_servers(node),
23+ # XXX jtv 2014-10-10, bug=1379641: Pass netmasks.
24+ 'netmasks': {}
25 }
26 preseed = compose_curtin_network_preseed(node, config)
27 return [json.dumps(item) for item in preseed]
28
29=== modified file 'src/maasserver/tests/test_networking_preseed.py'
30--- src/maasserver/tests/test_networking_preseed.py 2014-10-09 16:12:58 +0000
31+++ src/maasserver/tests/test_networking_preseed.py 2014-10-10 06:31:47 +0000
32@@ -767,6 +767,9 @@
33 'ips_mapping': {},
34 'gateways_mapping': {mac.mac_address: [router]},
35 'nameservers': [dns],
36+ # XXX jtv 2014-10-10, bug=1379641: empty for now, but to be
37+ # populated soon.
38+ 'netmasks': {},
39 }
40 self.assertThat(fake, MockCalledOnceWith(node, expected_config))
41
42
43=== modified file 'src/provisioningserver/drivers/osystem/__init__.py'
44--- src/provisioningserver/drivers/osystem/__init__.py 2014-10-06 10:03:17 +0000
45+++ src/provisioningserver/drivers/osystem/__init__.py 2014-10-10 06:31:47 +0000
46@@ -196,7 +196,8 @@
47
48 def compose_curtin_network_preseed(self, interfaces, auto_interfaces,
49 ips_mapping, gateways_mapping,
50- disable_ipv4=False, nameservers=None):
51+ disable_ipv4=False, nameservers=None,
52+ netmasks=None):
53 """Compose a Curtin preseed to configure a node's networking.
54
55 :param interfaces: A list of tuples, each a pair of an interface name
56@@ -218,6 +219,8 @@
57 :param disable_ipv4: Should this node be installed without IPv4
58 networking?
59 :param nameservers: Optional list of DNS servers.
60+ :param netmasks: Optional dict mapping IP addresses from `ips_mapping`
61+ to their respective netmask strings.
62 :return: A list of dicts that can be JSON-encoded and submitted to
63 Curtin as preseeds, perhaps in combination with other preseeds.
64 """
65
66=== modified file 'src/provisioningserver/drivers/osystem/debian_networking.py'
67--- src/provisioningserver/drivers/osystem/debian_networking.py 2014-10-09 02:56:06 +0000
68+++ src/provisioningserver/drivers/osystem/debian_networking.py 2014-10-10 06:31:47 +0000
69@@ -101,7 +101,7 @@
70
71 def compose_network_interfaces(interfaces, auto_interfaces, ips_mapping,
72 gateways_mapping, disable_ipv4=False,
73- nameservers=None):
74+ nameservers=None, netmasks=None):
75 """Return contents for a node's `/etc/network/interfaces` file.
76
77 :param interfaces: A list of interface/MAC pairs for the node.
78@@ -113,11 +113,15 @@
79 containers of the corresponding network interfaces' default gateways.
80 :param disable_ipv4: Should this node be installed without IPv4 networking?
81 :param nameservers: Optional list of DNS servers.
82+ :param netmasks: Optional dict mapping MAC IP addresses from `ips_mapping`
83+ to their respective netmask strings.
84 """
85 if nameservers is None:
86 ipv6_nameserver = None
87 else:
88 ipv6_nameserver = extract_ip_from_sequence(nameservers, 6)
89+ if netmasks is None:
90+ netmasks = {}
91
92 # Should we disable IPv4 on this node? For safety's sake, we won't do this
93 # if the node has no static IPv6 addresses. Otherwise it might become
94
95=== modified file 'src/provisioningserver/drivers/osystem/ubuntu.py'
96--- src/provisioningserver/drivers/osystem/ubuntu.py 2014-10-06 07:09:37 +0000
97+++ src/provisioningserver/drivers/osystem/ubuntu.py 2014-10-10 06:31:47 +0000
98@@ -92,7 +92,8 @@
99
100 def compose_curtin_network_preseed(self, interfaces, auto_interfaces,
101 ips_mapping, gateways_mapping,
102- disable_ipv4=False, nameservers=None):
103+ disable_ipv4=False, nameservers=None,
104+ netmasks=None):
105 """As defined in `OperatingSystem`: generate networking Curtin preseed.
106
107 Supports:
108@@ -104,7 +105,7 @@
109 interfaces_file = compose_network_interfaces(
110 interfaces, auto_interfaces, ips_mapping=ips_mapping,
111 gateways_mapping=gateways_mapping, disable_ipv4=disable_ipv4,
112- nameservers=nameservers)
113+ nameservers=nameservers, netmasks=netmasks)
114 udev_rules = compose_network_interfaces_udev_rules(interfaces)
115 write_files = {
116 'write_files': {
117
118=== modified file 'src/provisioningserver/rpc/clusterservice.py'
119--- src/provisioningserver/rpc/clusterservice.py 2014-10-08 22:05:15 +0000
120+++ src/provisioningserver/rpc/clusterservice.py 2014-10-10 06:31:47 +0000
121@@ -230,11 +230,12 @@
122 ips_mapping = config.get('ips_mapping', {})
123 gateways_mapping = config.get('gateways_mapping', {})
124 nameservers = config.get('nameservers', [])
125+ netmasks = config.get('netmasks', {})
126 return {
127 'data': compose_curtin_network_preseed(
128 osystem, interfaces, auto_interfaces, ips_mapping=ips_mapping,
129 gateways_mapping=gateways_mapping, disable_ipv4=disable_ipv4,
130- nameservers=nameservers),
131+ nameservers=nameservers, netmasks=netmasks),
132 }
133
134 @log_call(level=logging.DEBUG)
135
136=== modified file 'src/provisioningserver/rpc/osystems.py'
137--- src/provisioningserver/rpc/osystems.py 2014-10-06 10:03:17 +0000
138+++ src/provisioningserver/rpc/osystems.py 2014-10-10 06:31:47 +0000
139@@ -119,7 +119,7 @@
140
141 def compose_curtin_network_preseed(os_name, interfaces, auto_interfaces,
142 ips_mapping, gateways_mapping,
143- disable_ipv4, nameservers):
144+ disable_ipv4, nameservers, netmasks):
145 """Compose Curtin network preseed for a node.
146
147 :param os_name: Identifying name of the operating system for which a
148@@ -127,12 +127,14 @@
149 :param interfaces: A list of interface/MAC pairs for the node.
150 :param auto_interfaces: A list of MAC addresses whose network interfaces
151 should come up automatically on node boot.
152- :param ips_mapping: A dict mapping MAC addresses to containers of the
153+ :param ips_mapping: A dict mapping MAC addresses to lists of the
154 corresponding network interfaces' IP addresses.
155- :param gateways_mapping: A `defaultdict` mapping MAC addresses to
156- containers of the corresponding network interfaces' default gateways.
157+ :param gateways_mapping: A dict mapping MAC addresses to lists of the
158+ corresponding network interfaces' default gateways.
159 :param disable_ipv4: Should this node be installed without IPv4 networking?
160 :param nameservers: List of DNS servers.
161+ :param netmasks: A dict mapping IP dadresses from `ips_mapping` to their
162+ respective netmasks.
163 :return: Preseed data, as JSON.
164 """
165 try:
166@@ -143,4 +145,4 @@
167 return osystem.compose_curtin_network_preseed(
168 interfaces, auto_interfaces, ips_mapping=ips_mapping,
169 gateways_mapping=gateways_mapping, disable_ipv4=disable_ipv4,
170- nameservers=nameservers)
171+ nameservers=nameservers, netmasks=netmasks)
172
173=== modified file 'src/provisioningserver/rpc/tests/test_osystems.py'
174--- src/provisioningserver/rpc/tests/test_osystems.py 2014-10-06 10:03:17 +0000
175+++ src/provisioningserver/rpc/tests/test_osystems.py 2014-10-10 06:31:47 +0000
176@@ -205,15 +205,14 @@
177
178 def make_args(self):
179 mac = factory.make_mac_address()
180+ ipv4_net = factory.make_ipv4_network()
181+ ipv4_addr = factory.pick_ip_in_network(ipv4_net)
182+ ipv6_net = factory.make_ipv6_network()
183+ ipv6_addr = factory.pick_ip_in_network(ipv6_net)
184 return {
185 'interfaces': [(factory.make_name('eth'), mac)],
186 'auto_interfaces': [mac],
187- 'ips_mapping': {
188- mac: [
189- factory.make_ipv4_address(),
190- factory.make_ipv6_address(),
191- ],
192- },
193+ 'ips_mapping': {mac: [ipv4_addr, ipv6_addr]},
194 'gateways_mapping': {
195 mac: [
196 factory.make_ipv4_address(),
197@@ -222,6 +221,10 @@
198 },
199 'disable_ipv4': factory.pick_bool(),
200 'nameservers': [factory.make_ipv6_address()],
201+ 'netmasks': {
202+ ipv4_addr: unicode(ipv4_net.netmask),
203+ ipv6_addr: unicode(ipv6_net.netmask),
204+ },
205 }
206
207 def test__forwards_to_OS_implementation(self):