Merge lp:~lamont/maas/bug-1564925 into lp:~maas-committers/maas/trunk

Proposed by LaMont Jones
Status: Merged
Approved by: LaMont Jones
Approved revision: no longer in the source branch.
Merged at revision: 4866
Proposed branch: lp:~lamont/maas/bug-1564925
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 275 lines (+63/-38)
3 files modified
src/provisioningserver/dhcp/testing/config.py (+13/-6)
src/provisioningserver/dhcp/tests/test_config.py (+49/-31)
src/provisioningserver/templates/dhcp/dhcpd6.conf.template (+1/-1)
To merge this branch: bzr merge lp:~lamont/maas/bug-1564925
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+290765@code.launchpad.net

Commit message

Generate correct dhcpd6.conf configuration.

Description of the change

Generate correct dhcpd6.conf configuration.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good. Thanks for the quick fix. Testing was more work than fixing the bug. ;-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/dhcp/testing/config.py'
2--- src/provisioningserver/dhcp/testing/config.py 2016-03-26 00:36:43 +0000
3+++ src/provisioningserver/dhcp/testing/config.py 2016-04-01 17:46:03 +0000
4@@ -40,7 +40,7 @@
5
6 def make_host(
7 hostname=None, interface_name=None,
8- mac_address=None, ip=None, dhcp_snippets=None):
9+ mac_address=None, ip=None, ipv6=False, dhcp_snippets=None):
10 """Return a host entry for a subnet from network."""
11 if hostname is None:
12 hostname = factory.make_name("host")
13@@ -49,7 +49,10 @@
14 if mac_address is None:
15 mac_address = factory.make_mac_address()
16 if ip is None:
17- ip = str(factory.make_ipv4_address())
18+ if ipv6 is True:
19+ ip = str(factory.make_ipv6_address())
20+ else:
21+ ip = str(factory.make_ipv4_address())
22 if dhcp_snippets is None:
23 dhcp_snippets = make_dhcp_snippets()
24 return {
25@@ -60,10 +63,14 @@
26 }
27
28
29-def make_subnet_config(network=None, pools=None, dhcp_snippets=None):
30+def make_subnet_config(network=None, pools=None, ipv6=False,
31+ dhcp_snippets=None):
32 """Return complete DHCP configuration dict for a subnet."""
33 if network is None:
34- network = factory.make_ipv4_network()
35+ if ipv6 is True:
36+ network = factory.make_ipv6_network()
37+ else:
38+ network = factory.make_ipv4_network()
39 if pools is None:
40 pools = [make_subnet_pool(network)]
41 if dhcp_snippets is None:
42@@ -82,13 +89,13 @@
43 }
44
45
46-def make_shared_network(name=None, subnets=None):
47+def make_shared_network(name=None, subnets=None, ipv6=False):
48 """Return complete DHCP configuration dict for a shared network."""
49 if name is None:
50 name = factory.make_name("vlan")
51 if subnets is None:
52 subnets = [
53- make_subnet_config()
54+ make_subnet_config(ipv6=ipv6)
55 for _ in range(3)
56 ]
57 return {
58
59=== modified file 'src/provisioningserver/dhcp/tests/test_config.py'
60--- src/provisioningserver/dhcp/tests/test_config.py 2016-03-26 00:36:43 +0000
61+++ src/provisioningserver/dhcp/tests/test_config.py 2016-04-01 17:46:03 +0000
62@@ -62,19 +62,19 @@
63 """)
64
65
66-def make_sample_params(hosts=None):
67+def make_sample_params(hosts=None, ipv6=False):
68 """Return a dict of arbitrary DHCP configuration parameters."""
69 failover_peers = [
70 make_failover_peer_config()
71 for _ in range(3)
72 ]
73 shared_networks = [
74- make_shared_network()
75+ make_shared_network(ipv6=ipv6)
76 for _ in range(3)
77 ]
78 if hosts is None:
79 hosts = [
80- make_host()
81+ make_host(ipv6=ipv6)
82 for _ in range(3)
83 ]
84 return {
85@@ -89,6 +89,11 @@
86 class TestGetConfig(PservTestCase):
87 """Tests for `get_config`."""
88
89+ scenarios = [
90+ ("v4", dict(template='dhcpd.conf.template', ipv6=False)),
91+ ("v6", dict(template='dhcpd6.conf.template', ipv6=True)),
92+ ]
93+
94 def patch_template(self, name=None, template_content=sample_template):
95 """Patch the DHCP config template with the given contents.
96
97@@ -97,7 +102,7 @@
98 code being tested.
99 """
100 if name is None:
101- name = 'dhcpd.conf.template'
102+ name = self.template
103 fake_root = self.make_dir()
104 template_dir = path.join(fake_root, 'templates', 'dhcp')
105 makedirs(template_dir)
106@@ -106,30 +111,29 @@
107 self.patch(config, 'locate_template').return_value = template
108 return tempita.Template(template_content, name=template)
109
110- def test__uses_branch_template_by_default(self):
111- # Since the branch comes with dhcp templates in etc/maas, we can
112- # instantiate those templates without any hackery.
113- self.assertIsNotNone(
114- config.get_config('dhcpd.conf.template', **make_sample_params()))
115- self.assertIsNotNone(
116- config.get_config('dhcpd6.conf.template', **make_sample_params()))
117-
118 def test__substitutes_parameters(self):
119 template_name = factory.make_name('template')
120 template = self.patch_template(name=template_name)
121- params = make_sample_params()
122+ params = make_sample_params(ipv6=self.ipv6)
123 self.assertEqual(
124 template.substitute(params),
125 config.get_config(template_name, **params))
126
127+ def test__uses_branch_template_by_default(self):
128+ # Since the branch comes with dhcp templates in etc/maas, we can
129+ # instantiate those templates without any hackery.
130+ self.assertIsNotNone(
131+ config.get_config(
132+ self.template, **make_sample_params(ipv6=self.ipv6)))
133+
134 def test__complains_if_too_few_parameters(self):
135 template = self.patch_template()
136- params = make_sample_params()
137+ params = make_sample_params(ipv6=self.ipv6)
138 del params['shared_networks'][0]['subnets'][0]['subnet']
139
140 e = self.assertRaises(
141 config.DHCPConfigError,
142- config.get_config, 'dhcpd.conf.template', **params)
143+ config.get_config, self.template, **params)
144
145 tbe = traceback.TracebackException.from_exception(e)
146 self.assertDocTestMatches(
147@@ -152,14 +156,14 @@
148 )
149
150 def test__includes_compose_conditional_bootloader(self):
151- params = make_sample_params()
152+ params = make_sample_params(ipv6=self.ipv6)
153 bootloader = config.compose_conditional_bootloader()
154 self.assertThat(
155- config.get_config('dhcpd.conf.template', **params),
156+ config.get_config(self.template, **params),
157 Contains(bootloader))
158
159 def test__renders_without_ntp_servers_set(self):
160- params = make_sample_params()
161+ params = make_sample_params(ipv6=self.ipv6)
162 for network in params['shared_networks']:
163 for subnet in network['subnets']:
164 del subnet['ntp_server']
165@@ -167,19 +171,19 @@
166 rendered = template.substitute(params)
167 self.assertEqual(
168 rendered,
169- config.get_config('dhcpd.conf.template', **params))
170+ config.get_config(self.template, **params))
171 self.assertNotIn("ntp-servers", rendered)
172
173 def test__renders_router_ip_if_present(self):
174- params = make_sample_params()
175+ params = make_sample_params(ipv6=self.ipv6)
176 router_ip = factory.make_ipv4_address()
177 params['shared_networks'][0]['subnets'][0]['router_ip'] = router_ip
178 self.assertThat(
179- config.get_config('dhcpd.conf.template', **params),
180+ config.get_config(self.template, **params),
181 Contains(router_ip))
182
183 def test__renders_with_empty_string_router_ip(self):
184- params = make_sample_params()
185+ params = make_sample_params(ipv6=self.ipv6)
186 for network in params['shared_networks']:
187 for subnet in network['subnets']:
188 subnet['router_ip'] = ''
189@@ -187,7 +191,7 @@
190 rendered = template.substitute(params)
191 self.assertEqual(
192 rendered,
193- config.get_config('dhcpd.conf.template', **params))
194+ config.get_config(self.template, **params))
195 self.assertNotIn("routers", rendered)
196
197 def test__renders_with_hosts(self):
198@@ -196,8 +200,8 @@
199 make_host(network)
200 for _ in range(3)
201 ]
202- params = make_sample_params(hosts)
203- config_output = config.get_config('dhcpd.conf.template', **params)
204+ params = make_sample_params(hosts, ipv6=self.ipv6)
205+ config_output = config.get_config(self.template, **params)
206 self.assertThat(
207 config_output,
208 ContainsAll([
209@@ -218,8 +222,8 @@
210 ]))
211
212 def test__renders_global_dhcp_snippets(self):
213- params = make_sample_params()
214- config_output = config.get_config('dhcpd.conf.template', **params)
215+ params = make_sample_params(ipv6=self.ipv6)
216+ config_output = config.get_config(self.template, **params)
217 self.assertThat(
218 config_output,
219 ContainsAll([
220@@ -228,8 +232,8 @@
221 ]))
222
223 def test__renders_subnet_dhcp_snippets(self):
224- params = make_sample_params()
225- config_output = config.get_config('dhcpd.conf.template', **params)
226+ params = make_sample_params(ipv6=self.ipv6)
227+ config_output = config.get_config(self.template, **params)
228 for shared_network in params['shared_networks']:
229 for subnet in shared_network['subnets']:
230 self.assertThat(
231@@ -240,8 +244,8 @@
232 ]))
233
234 def test__renders_node_dhcp_snippets(self):
235- params = make_sample_params()
236- config_output = config.get_config('dhcpd.conf.template', **params)
237+ params = make_sample_params(ipv6=self.ipv6)
238+ config_output = config.get_config(self.template, **params)
239 for host in params['hosts']:
240 self.assertThat(
241 config_output,
242@@ -250,6 +254,20 @@
243 for dhcp_snippet in host['dhcp_snippets']
244 ]))
245
246+ def test__renders_subnet_cidr(self):
247+ params = make_sample_params(ipv6=self.ipv6)
248+ config_output = config.get_config(self.template, **params)
249+ for shared_network in params['shared_networks']:
250+ for subnet in shared_network['subnets']:
251+ if self.ipv6 is True:
252+ expected = "subnet6 %s" % subnet['subnet_cidr']
253+ else:
254+ expected = "subnet %s netmask %s" % (
255+ subnet['subnet'], subnet['subnet_mask'])
256+ self.assertThat(
257+ config_output,
258+ Contains(expected))
259+
260
261 class TestComposeConditionalBootloader(PservTestCase):
262 """Tests for `compose_conditional_bootloader`."""
263
264=== modified file 'src/provisioningserver/templates/dhcp/dhcpd6.conf.template'
265--- src/provisioningserver/templates/dhcp/dhcpd6.conf.template 2016-03-26 00:36:43 +0000
266+++ src/provisioningserver/templates/dhcp/dhcpd6.conf.template 2016-04-01 17:46:03 +0000
267@@ -45,7 +45,7 @@
268 {{for shared_network in shared_networks}}
269 shared-network {{shared_network["name"]}} {
270 {{for dhcp_subnet in shared_network["subnets"]}}
271- subnet6 {{dhcp_subnet['subnet']}} netmask {{dhcp_subnet['subnet_mask']}} {
272+ subnet6 {{dhcp_subnet['subnet_cidr']}} {
273 ignore-client-uids true;
274 {{if dhcp_subnet.get('dns_servers')}}
275 option dhcp6.name-servers {{dhcp_subnet['dns_servers']}};