Merge lp:~blake-rouse/maas/fix-sticky-ip-hostmap into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 3602
Proposed branch: lp:~blake-rouse/maas/fix-sticky-ip-hostmap
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 112 lines (+43/-1)
2 files modified
src/maasserver/api/nodes.py (+6/-0)
src/maasserver/api/tests/test_node.py (+37/-1)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-sticky-ip-hostmap
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Mike Pontillo (community) Approve
Review via email: mp+251810@code.launchpad.net

Commit message

Update the nodes host maps when a sticky ip address is claimed over the API.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks good to me.

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/api/nodes.py'
2--- src/maasserver/api/nodes.py 2015-02-18 23:12:37 +0000
3+++ src/maasserver/api/nodes.py 2015-03-04 19:20:30 +0000
4@@ -40,6 +40,7 @@
5 get_optional_param,
6 )
7 from maasserver.clusterrpc.power_parameters import get_power_types
8+from maasserver.dns.config import dns_update_zones
9 from maasserver.enum import (
10 IPADDRESS_TYPE,
11 NODE_PERMISSION,
12@@ -476,6 +477,11 @@
13 sticky_ips = mac_address.claim_static_ips(
14 alloc_type=IPADDRESS_TYPE.STICKY,
15 requested_address=requested_address)
16+ claims = [
17+ (static_ip.ip, mac_address.mac_address.get_raw())
18+ for static_ip in sticky_ips]
19+ node.update_host_maps(claims)
20+ dns_update_zones([node.nodegroup])
21 maaslog.info(
22 "%s: Sticky IP address(es) allocated: %s", node.hostname,
23 ', '.join(allocation.ip for allocation in sticky_ips))
24
25=== modified file 'src/maasserver/api/tests/test_node.py'
26--- src/maasserver/api/tests/test_node.py 2015-02-12 08:52:58 +0000
27+++ src/maasserver/api/tests/test_node.py 2015-03-04 19:20:30 +0000
28@@ -23,6 +23,7 @@
29 import bson
30 from django.core.urlresolvers import reverse
31 from maasserver import forms
32+from maasserver.api import nodes as api_nodes
33 from maasserver.enum import (
34 IPADDRESS_TYPE,
35 NODE_STATUS,
36@@ -1055,6 +1056,8 @@
37 def test_claim_sticky_ip_address_returns_existing_if_already_exists(self):
38 self.become_admin()
39 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
40+ # Silence 'update_host_maps'.
41+ self.patch(node_module, "update_host_maps")
42 [existing_ip] = node.get_primary_mac().claim_static_ips(
43 alloc_type=IPADDRESS_TYPE.STICKY)
44 response = self.client.post(
45@@ -1083,6 +1086,8 @@
46 def test_claim_sticky_ip_address_claims_sticky_ip_address_non_admin(self):
47 node = factory.make_node_with_mac_attached_to_nodegroupinterface(
48 owner=self.logged_in_user)
49+ # Silence 'update_host_maps'.
50+ self.patch(node_module, "update_host_maps")
51 response = self.client.post(
52 self.get_node_uri(node), {'op': 'claim_sticky_ip_address'})
53 self.assertEqual(httplib.OK, response.status_code, response.content)
54@@ -1106,6 +1111,8 @@
55 def test_claim_sticky_ip_address_claims_sticky_ip_address(self):
56 self.become_admin()
57 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
58+ # Silence 'update_host_maps'.
59+ self.patch(node_module, "update_host_maps")
60 response = self.client.post(
61 self.get_node_uri(node), {'op': 'claim_sticky_ip_address'})
62 self.assertEqual(httplib.OK, response.status_code, response.content)
63@@ -1117,12 +1124,39 @@
64 (returned_ip, given_ip.alloc_type),
65 )
66
67+ def test_claim_ip_address_creates_host_DHCP_and_DNS_mappings(self):
68+ self.become_admin()
69+ node = factory.make_node_with_mac_attached_to_nodegroupinterface()
70+ dns_update_zones = self.patch(api_nodes, 'dns_update_zones')
71+ update_host_maps = self.patch(node_module, "update_host_maps")
72+ update_host_maps.return_value = [] # No failures.
73+ response = self.client.post(
74+ self.get_node_uri(node), {'op': 'claim_sticky_ip_address'})
75+ self.assertEqual(httplib.OK, response.status_code, response.content)
76+
77+ self.assertItemsEqual(
78+ [node.get_primary_mac()],
79+ node.mac_addresses_on_managed_interfaces())
80+ # Host maps are updated.
81+ self.assertThat(
82+ update_host_maps, MockCalledOnceWith({
83+ node.nodegroup: {
84+ ip_address.ip: mac.mac_address
85+ for ip_address in mac.ip_addresses.all()
86+ }
87+ for mac in node.mac_addresses_on_managed_interfaces()
88+ }))
89+ # DNS has been updated.
90+ self.assertThat(
91+ dns_update_zones, MockCalledOnceWith([node.nodegroup]))
92+
93 def test_claim_sticky_ip_address_allows_macaddress_parameter(self):
94 self.become_admin()
95 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
96 ngi = factory.make_NodeGroupInterface(nodegroup=node.nodegroup)
97 second_mac = factory.make_MACAddress(node=node, cluster_interface=ngi)
98-
99+ # Silence 'update_host_maps'.
100+ self.patch(node_module, "update_host_maps")
101 response = self.client.post(
102 self.get_node_uri(node),
103 {
104@@ -1157,6 +1191,8 @@
105 ngi = node.get_primary_mac().cluster_interface
106 requested_address = ngi.static_ip_range_low
107
108+ # Silence 'update_host_maps'.
109+ self.patch(node_module, "update_host_maps")
110 response = self.client.post(
111 self.get_node_uri(node),
112 {