Merge lp:~gmb/maas/backport-to-1.7-bug-1382108 into lp:maas/1.7

Proposed by Graham Binns
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 3274
Proposed branch: lp:~gmb/maas/backport-to-1.7-bug-1382108
Merge into: lp:maas/1.7
Diff against target: 107 lines (+75/-1)
2 files modified
src/maasserver/models/node.py (+12/-1)
src/maasserver/models/tests/test_node.py (+63/-0)
To merge this branch: bzr merge lp:~gmb/maas/backport-to-1.7-bug-1382108
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+239299@code.launchpad.net

Commit message

Backport the fix for bug 1382108 to 1.7:

Don't write DHCP host maps when starting a node if its PXE MAC is not on a managed cluster interface, they are not needed. This also removes a related crash (see bug 1382108).

To post a comment you must log in.
Revision history for this message
Christian Reis (kiko) wrote :

Ah, this looks much better. If you can get someone who knows their stuff to review the actual code changes (I don't know the internal API well enough) this is clear to land in 1.7. Thanks!

Revision history for this message
Julian Edwards (julian-edwards) wrote :

Looks almost like my trunk change, therefore it must be fine :)

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Thanks for backporting it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py 2014-10-15 20:00:42 +0000
+++ src/maasserver/models/node.py 2014-10-22 20:24:21 +0000
@@ -414,7 +414,10 @@
414 for node in nodes:414 for node in nodes:
415 if node.status == NODE_STATUS.ALLOCATED:415 if node.status == NODE_STATUS.ALLOCATED:
416 claims = node.claim_static_ip_addresses()416 claims = node.claim_static_ip_addresses()
417 static_mappings[node.nodegroup].update(claims)417 # If the PXE mac is on a managed interface then we can ask
418 # the cluster to generate the DHCP host map(s).
419 if node.is_pxe_mac_on_managed_interface():
420 static_mappings[node.nodegroup].update(claims)
418 node.start_deployment()421 node.start_deployment()
419422
420 # XXX 2014-06-17 bigjools bug=1330765423 # XXX 2014-06-17 bigjools bug=1330765
@@ -1550,3 +1553,11 @@
1550 return self.pxe_mac1553 return self.pxe_mac
15511554
1552 return self.macaddress_set.first()1555 return self.macaddress_set.first()
1556
1557 def is_pxe_mac_on_managed_interface(self):
1558 pxe_mac = self.get_pxe_mac()
1559 if pxe_mac is not None:
1560 cluster_interface = pxe_mac.cluster_interface
1561 if cluster_interface is not None:
1562 return cluster_interface.is_managed
1563 return False
15531564
=== modified file 'src/maasserver/models/tests/test_node.py'
--- src/maasserver/models/tests/test_node.py 2014-10-15 22:29:41 +0000
+++ src/maasserver/models/tests/test_node.py 2014-10-22 20:24:21 +0000
@@ -1834,6 +1834,28 @@
1834 self.assertEqual(node.macaddress_set.first(), node.get_pxe_mac())1834 self.assertEqual(node.macaddress_set.first(), node.get_pxe_mac())
18351835
18361836
1837class TestNode_pxe_mac_on_managed_interface(MAASServerTestCase):
1838
1839 def test__returns_true_if_managed(self):
1840 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
1841 self.assertTrue(node.is_pxe_mac_on_managed_interface())
1842
1843 def test__returns_false_if_no_pxe_mac(self):
1844 node = factory.make_Node()
1845 self.assertFalse(node.is_pxe_mac_on_managed_interface())
1846
1847 def test__returns_false_if_no_attached_cluster_interface(self):
1848 node = factory.make_Node()
1849 node.pxe_mac = factory.make_MACAddress(node=node)
1850 node.save()
1851 self.assertFalse(node.is_pxe_mac_on_managed_interface())
1852
1853 def test__returns_false_if_cluster_interface_unmanaged(self):
1854 node = factory.make_node_with_mac_attached_to_nodegroupinterface(
1855 management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED)
1856 self.assertFalse(node.is_pxe_mac_on_managed_interface())
1857
1858
1837class NodeRoutersTest(MAASServerTestCase):1859class NodeRoutersTest(MAASServerTestCase):
18381860
1839 def test_routers_stores_mac_address(self):1861 def test_routers_stores_mac_address(self):
@@ -2375,6 +2397,47 @@
2375 # demonstrates this behaviour.2397 # demonstrates this behaviour.
2376 self.assertItemsEqual([node1], nodes_started)2398 self.assertItemsEqual([node1], nodes_started)
23772399
2400 def test__does_not_generate_host_maps_if_not_on_managed_interface(self):
2401 cluster = factory.make_NodeGroup()
2402 managed_interface = factory.make_NodeGroupInterface(
2403 nodegroup=cluster,
2404 management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
2405 unmanaged_interface = factory.make_NodeGroupInterface(
2406 nodegroup=cluster,
2407 management=NODEGROUPINTERFACE_MANAGEMENT.DEFAULT)
2408 user = factory.make_User()
2409 [node1, node2] = self.make_acquired_nodes_with_macs(
2410 user, nodegroup=cluster, count=2)
2411 # Give the node a PXE MAC address on the cluster's interface.
2412 node1_mac = node1.get_pxe_mac()
2413 node1_mac.cluster_interface = managed_interface
2414 node1_mac.save()
2415 node2_mac = node1.get_pxe_mac()
2416 node2_mac.cluster_interface = unmanaged_interface
2417 node2_mac.save()
2418
2419 node1_ip = factory.make_ipv4_address()
2420 claim_static_ip_addresses = self.patch(
2421 node_module.Node, 'claim_static_ip_addresses')
2422 claim_static_ip_addresses.side_effect = [
2423 [(node1_ip, node1_mac.mac_address)],
2424 [(factory.make_ipv4_address(), node2_mac.mac_address)],
2425 ]
2426
2427 update_host_maps = self.patch(node_module, "update_host_maps")
2428 Node.objects.start_nodes([node1.system_id, node2.system_id], user)
2429 self.expectThat(update_host_maps, MockCalledOnceWith(ANY))
2430
2431 observed_static_mappings = update_host_maps.call_args[0][0]
2432
2433 [observed_cluster] = observed_static_mappings.keys()
2434 self.expectThat(observed_cluster.uuid, Equals(cluster.uuid))
2435
2436 observed_claims = observed_static_mappings.values()
2437 self.expectThat(
2438 observed_claims,
2439 Equals([{node1_ip: node1_mac.mac_address}]))
2440
23782441
2379class NodeManagerTest_StopNodes(MAASServerTestCase):2442class NodeManagerTest_StopNodes(MAASServerTestCase):
23802443

Subscribers

People subscribed via source and target branches

to all changes: