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
=== modified file 'src/maasserver/api/nodes.py'
--- src/maasserver/api/nodes.py 2015-02-18 23:12:37 +0000
+++ src/maasserver/api/nodes.py 2015-03-04 19:20:30 +0000
@@ -40,6 +40,7 @@
40 get_optional_param,40 get_optional_param,
41 )41 )
42from maasserver.clusterrpc.power_parameters import get_power_types42from maasserver.clusterrpc.power_parameters import get_power_types
43from maasserver.dns.config import dns_update_zones
43from maasserver.enum import (44from maasserver.enum import (
44 IPADDRESS_TYPE,45 IPADDRESS_TYPE,
45 NODE_PERMISSION,46 NODE_PERMISSION,
@@ -476,6 +477,11 @@
476 sticky_ips = mac_address.claim_static_ips(477 sticky_ips = mac_address.claim_static_ips(
477 alloc_type=IPADDRESS_TYPE.STICKY,478 alloc_type=IPADDRESS_TYPE.STICKY,
478 requested_address=requested_address)479 requested_address=requested_address)
480 claims = [
481 (static_ip.ip, mac_address.mac_address.get_raw())
482 for static_ip in sticky_ips]
483 node.update_host_maps(claims)
484 dns_update_zones([node.nodegroup])
479 maaslog.info(485 maaslog.info(
480 "%s: Sticky IP address(es) allocated: %s", node.hostname,486 "%s: Sticky IP address(es) allocated: %s", node.hostname,
481 ', '.join(allocation.ip for allocation in sticky_ips))487 ', '.join(allocation.ip for allocation in sticky_ips))
482488
=== modified file 'src/maasserver/api/tests/test_node.py'
--- src/maasserver/api/tests/test_node.py 2015-02-12 08:52:58 +0000
+++ src/maasserver/api/tests/test_node.py 2015-03-04 19:20:30 +0000
@@ -23,6 +23,7 @@
23import bson23import bson
24from django.core.urlresolvers import reverse24from django.core.urlresolvers import reverse
25from maasserver import forms25from maasserver import forms
26from maasserver.api import nodes as api_nodes
26from maasserver.enum import (27from maasserver.enum import (
27 IPADDRESS_TYPE,28 IPADDRESS_TYPE,
28 NODE_STATUS,29 NODE_STATUS,
@@ -1055,6 +1056,8 @@
1055 def test_claim_sticky_ip_address_returns_existing_if_already_exists(self):1056 def test_claim_sticky_ip_address_returns_existing_if_already_exists(self):
1056 self.become_admin()1057 self.become_admin()
1057 node = factory.make_node_with_mac_attached_to_nodegroupinterface()1058 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
1059 # Silence 'update_host_maps'.
1060 self.patch(node_module, "update_host_maps")
1058 [existing_ip] = node.get_primary_mac().claim_static_ips(1061 [existing_ip] = node.get_primary_mac().claim_static_ips(
1059 alloc_type=IPADDRESS_TYPE.STICKY)1062 alloc_type=IPADDRESS_TYPE.STICKY)
1060 response = self.client.post(1063 response = self.client.post(
@@ -1083,6 +1086,8 @@
1083 def test_claim_sticky_ip_address_claims_sticky_ip_address_non_admin(self):1086 def test_claim_sticky_ip_address_claims_sticky_ip_address_non_admin(self):
1084 node = factory.make_node_with_mac_attached_to_nodegroupinterface(1087 node = factory.make_node_with_mac_attached_to_nodegroupinterface(
1085 owner=self.logged_in_user)1088 owner=self.logged_in_user)
1089 # Silence 'update_host_maps'.
1090 self.patch(node_module, "update_host_maps")
1086 response = self.client.post(1091 response = self.client.post(
1087 self.get_node_uri(node), {'op': 'claim_sticky_ip_address'})1092 self.get_node_uri(node), {'op': 'claim_sticky_ip_address'})
1088 self.assertEqual(httplib.OK, response.status_code, response.content)1093 self.assertEqual(httplib.OK, response.status_code, response.content)
@@ -1106,6 +1111,8 @@
1106 def test_claim_sticky_ip_address_claims_sticky_ip_address(self):1111 def test_claim_sticky_ip_address_claims_sticky_ip_address(self):
1107 self.become_admin()1112 self.become_admin()
1108 node = factory.make_node_with_mac_attached_to_nodegroupinterface()1113 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
1114 # Silence 'update_host_maps'.
1115 self.patch(node_module, "update_host_maps")
1109 response = self.client.post(1116 response = self.client.post(
1110 self.get_node_uri(node), {'op': 'claim_sticky_ip_address'})1117 self.get_node_uri(node), {'op': 'claim_sticky_ip_address'})
1111 self.assertEqual(httplib.OK, response.status_code, response.content)1118 self.assertEqual(httplib.OK, response.status_code, response.content)
@@ -1117,12 +1124,39 @@
1117 (returned_ip, given_ip.alloc_type),1124 (returned_ip, given_ip.alloc_type),
1118 )1125 )
11191126
1127 def test_claim_ip_address_creates_host_DHCP_and_DNS_mappings(self):
1128 self.become_admin()
1129 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
1130 dns_update_zones = self.patch(api_nodes, 'dns_update_zones')
1131 update_host_maps = self.patch(node_module, "update_host_maps")
1132 update_host_maps.return_value = [] # No failures.
1133 response = self.client.post(
1134 self.get_node_uri(node), {'op': 'claim_sticky_ip_address'})
1135 self.assertEqual(httplib.OK, response.status_code, response.content)
1136
1137 self.assertItemsEqual(
1138 [node.get_primary_mac()],
1139 node.mac_addresses_on_managed_interfaces())
1140 # Host maps are updated.
1141 self.assertThat(
1142 update_host_maps, MockCalledOnceWith({
1143 node.nodegroup: {
1144 ip_address.ip: mac.mac_address
1145 for ip_address in mac.ip_addresses.all()
1146 }
1147 for mac in node.mac_addresses_on_managed_interfaces()
1148 }))
1149 # DNS has been updated.
1150 self.assertThat(
1151 dns_update_zones, MockCalledOnceWith([node.nodegroup]))
1152
1120 def test_claim_sticky_ip_address_allows_macaddress_parameter(self):1153 def test_claim_sticky_ip_address_allows_macaddress_parameter(self):
1121 self.become_admin()1154 self.become_admin()
1122 node = factory.make_node_with_mac_attached_to_nodegroupinterface()1155 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
1123 ngi = factory.make_NodeGroupInterface(nodegroup=node.nodegroup)1156 ngi = factory.make_NodeGroupInterface(nodegroup=node.nodegroup)
1124 second_mac = factory.make_MACAddress(node=node, cluster_interface=ngi)1157 second_mac = factory.make_MACAddress(node=node, cluster_interface=ngi)
11251158 # Silence 'update_host_maps'.
1159 self.patch(node_module, "update_host_maps")
1126 response = self.client.post(1160 response = self.client.post(
1127 self.get_node_uri(node),1161 self.get_node_uri(node),
1128 {1162 {
@@ -1157,6 +1191,8 @@
1157 ngi = node.get_primary_mac().cluster_interface1191 ngi = node.get_primary_mac().cluster_interface
1158 requested_address = ngi.static_ip_range_low1192 requested_address = ngi.static_ip_range_low
11591193
1194 # Silence 'update_host_maps'.
1195 self.patch(node_module, "update_host_maps")
1160 response = self.client.post(1196 response = self.client.post(
1161 self.get_node_uri(node),1197 self.get_node_uri(node),
1162 {1198 {