Merge lp:~mpontillo/maas/dhcp-leases-bug-1522294-trunk into lp:~maas-committers/maas/trunk

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 4535
Proposed branch: lp:~mpontillo/maas/dhcp-leases-bug-1522294-trunk
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 93 lines (+17/-10)
3 files modified
src/provisioningserver/dhcp/omshell.py (+5/-2)
src/provisioningserver/dhcp/tests/test_omshell.py (+2/-2)
src/provisioningserver/rpc/dhcp.py (+10/-6)
To merge this branch: bzr merge lp:~mpontillo/maas/dhcp-leases-bug-1522294-trunk
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+279662@code.launchpad.net

Commit message

Generate DHCP lease names with identifiers that will parse when dhcpd re-reads the file.

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

Looks good. This needs to go in 1.9 as well but there will be a difference.

You have a conflict about unicode() and str(). In trunk it will now be str() and in 1.9 it will be unicode().

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/omshell.py'
2--- src/provisioningserver/dhcp/omshell.py 2015-12-01 18:12:59 +0000
3+++ src/provisioningserver/dhcp/omshell.py 2015-12-04 21:58:18 +0000
4@@ -160,6 +160,7 @@
5 # the key) and new host mappings (using the MAC as the key).
6 maaslog.debug(
7 "Creating host mapping %s->%s" % (mac_address, ip_address))
8+ name = mac_address.replace(':', '-')
9 stdin = dedent("""\
10 server {self.server_address}
11 key omapi_key {self.shared_key}
12@@ -168,11 +169,12 @@
13 set ip-address = {ip_address}
14 set hardware-address = {mac_address}
15 set hardware-type = 1
16- set name = "{mac_address}"
17+ set name = "{name}"
18 create
19 """)
20 stdin = stdin.format(
21- self=self, ip_address=ip_address, mac_address=mac_address)
22+ self=self, ip_address=ip_address, mac_address=mac_address,
23+ name=name)
24
25 returncode, output = self._run(stdin)
26 # If the call to omshell doesn't result in output containing the
27@@ -201,6 +203,7 @@
28 # be the key for the mapping (it will be the IP if the record was
29 # created with by an old version of MAAS and the MAC otherwise).
30 maaslog.debug("Removing host mapping key=%s" % mac_address)
31+ mac_address = mac_address.replace(':', '-')
32 stdin = dedent("""\
33 server {self.server_address}
34 key omapi_key {self.shared_key}
35
36=== modified file 'src/provisioningserver/dhcp/tests/test_omshell.py'
37--- src/provisioningserver/dhcp/tests/test_omshell.py 2015-12-01 18:12:59 +0000
38+++ src/provisioningserver/dhcp/tests/test_omshell.py 2015-12-04 21:58:18 +0000
39@@ -111,12 +111,12 @@
40 set ip-address = {ip}
41 set hardware-address = {mac}
42 set hardware-type = 1
43- set name = "{mac}"
44+ set name = "{name}"
45 create
46 """)
47 expected_script = expected_script.format(
48 server=server_address, key=shared_key, ip=ip_address,
49- mac=mac_address)
50+ mac=mac_address, name=mac_address.replace(':', '-'))
51
52 # Check that the 'stdin' arg contains the correct set of
53 # commands.
54
55=== modified file 'src/provisioningserver/rpc/dhcp.py'
56--- src/provisioningserver/rpc/dhcp.py 2015-12-01 18:12:59 +0000
57+++ src/provisioningserver/rpc/dhcp.py 2015-12-04 21:58:18 +0000
58@@ -194,7 +194,7 @@
59
60
61 @synchronous
62-def remove_host_maps(mac_addresses, shared_key):
63+def remove_host_maps(identifiers, shared_key):
64 """Remove DHCP host maps for the given IP addresses.
65
66 Additionally, this will ensure that any lease present for the MAC
67@@ -210,17 +210,21 @@
68 _ensure_dhcpv4_is_accessible(CannotRemoveHostMap)
69 # See bug 1039362 regarding server_address.
70 omshell = Omshell(server_address='127.0.0.1', shared_key=shared_key)
71- for mac_address in mac_addresses:
72+ for identifier in identifiers:
73 try:
74- omshell.remove(mac_address)
75- omshell.nullify_lease(mac_address)
76+ # Note: identifiers can be either MAC addresses or IP addresses;
77+ # the region will send us a set of both, due to backward
78+ # compatibility issues (MAAS 1.8 used the IP address as the
79+ # identifier; now we use the MAC.)
80+ omshell.remove(identifier)
81+ omshell.nullify_lease(identifier)
82 except ExternalProcessError as e:
83 maaslog.error(
84 "Could not remove host map for %s: %s.",
85- mac_address, str(e))
86+ identifier, str(e))
87 if 'not connected.' in e.output_as_unicode:
88 raise CannotRemoveHostMap(
89 "The DHCP server could not be reached.")
90 else:
91 raise CannotRemoveHostMap("%s: %s." % (
92- mac_address, e.output_as_unicode))
93+ identifier, e.output_as_unicode))