Merge lp:~rvb/maas/subnet-calc2 into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 972
Proposed branch: lp:~rvb/maas/subnet-calc2
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 65 lines (+8/-10)
3 files modified
src/maasserver/models/nodegroup.py (+4/-4)
src/maasserver/tests/test_commands_config_master_dhcp.py (+0/-2)
src/maasserver/tests/test_nodegroup.py (+4/-4)
To merge this branch: bzr merge lp:~rvb/maas/subnet-calc2
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+122702@code.launchpad.net

Commit message

Fix the 'subnet' used when writing DHCP configuration files.

Description of the change

This branch fixes the subnet used when writing the DHCP configuration file. The value used was the nodegroup's ip_range_low value and that is obviously wrong as the nodegroup's subnet_mask needs to be applied.

= Pre-imp =

No real pre-imp for this but the fix is rather straightforward.

= Notes =

Instead of fiddling with IP addresses manually, I use the netaddr module to do the heavy lifting.

I thought it was clearer to fix the network config of the nodegroup used in the test. The alternative would have been to continue using a random one but in this case I would have to redo the computation of the subnet in the test the same way it's done in the code and the test would not have been very interesting.

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/nodegroup.py'
2--- src/maasserver/models/nodegroup.py 2012-09-04 04:47:28 +0000
3+++ src/maasserver/models/nodegroup.py 2012-09-04 15:07:22 +0000
4@@ -25,6 +25,7 @@
5 from maasserver.dhcp import is_dhcp_management_enabled
6 from maasserver.models.timestampedmodel import TimestampedModel
7 from maasserver.refresh_worker import refresh_worker
8+from netaddr import IPAddress
9 from piston.models import (
10 KEY_SIZE,
11 Token,
12@@ -148,11 +149,10 @@
13 """Write the DHCP configuration file and restart the DHCP server."""
14 # Circular imports.
15 from maasserver.dns import get_dns_server_address
16- # XXX bug=1045589
17- # subnet is calculated incorrectly, see the bug.
18+ subnet = str(
19+ IPAddress(self.ip_range_low) & IPAddress(self.subnet_mask))
20 write_dhcp_config.delay(
21- subnet=self.ip_range_low,
22- next_server=self.worker_ip,
23+ subnet=subnet, next_server=self.worker_ip,
24 omapi_key=self.dhcp_key, subnet_mask=self.subnet_mask,
25 broadcast_ip=self.broadcast_ip, router_ip=self.router_ip,
26 dns_servers=get_dns_server_address(),
27
28=== modified file 'src/maasserver/tests/test_commands_config_master_dhcp.py'
29--- src/maasserver/tests/test_commands_config_master_dhcp.py 2012-09-04 10:18:29 +0000
30+++ src/maasserver/tests/test_commands_config_master_dhcp.py 2012-09-04 15:07:22 +0000
31@@ -22,8 +22,6 @@
32 )
33 from maasserver.testing.factory import factory
34 from maasserver.testing.testcase import TestCase
35-from mock import Mock
36-from provisioningserver import tasks
37 from testtools.matchers import MatchesStructure
38
39
40
41=== modified file 'src/maasserver/tests/test_nodegroup.py'
42--- src/maasserver/tests/test_nodegroup.py 2012-09-04 04:47:28 +0000
43+++ src/maasserver/tests/test_nodegroup.py 2012-09-04 15:07:22 +0000
44@@ -193,7 +193,9 @@
45 mocked_task = self.patch(
46 maasserver.models.nodegroup, 'write_dhcp_config')
47 nodegroup = factory.make_node_group(
48- dhcp_key=factory.getRandomString())
49+ dhcp_key=factory.getRandomString(),
50+ ip_range_low='192.168.102.1', ip_range_high='192.168.103.254',
51+ subnet_mask='255.255.252.0', broadcast_ip='192.168.103.255')
52 nodegroup.set_up_dhcp()
53 dhcp_params = [
54 'subnet_mask', 'broadcast_ip', 'router_ip',
55@@ -204,9 +206,7 @@
56 expected_params["next_server"] = nodegroup.worker_ip
57 expected_params["omapi_key"] = nodegroup.dhcp_key
58 expected_params["dns_servers"] = get_dns_server_address()
59- # XXX bug=1045589
60- # subnet is calculated incorrectly, see the bug.
61- expected_params["subnet"] = nodegroup.ip_range_low
62+ expected_params["subnet"] = '192.168.100.0'
63 mocked_task.delay.assert_called_once_with(**expected_params)
64
65 def test_add_dhcp_host_maps_adds_maps_if_managing_dhcp(self):