Merge lp:~newell-jensen/maas/bug-1376888 into lp:maas/trunk

Proposed by Newell Jensen on 2014-10-09
Status: Merged
Approved by: Newell Jensen on 2014-10-09
Approved revision: 3222
Merged at revision: 3224
Proposed branch: lp:~newell-jensen/maas/bug-1376888
Merge into: lp:maas/trunk
Diff against target: 85 lines (+33/-10)
2 files modified
src/maasserver/models/node.py (+2/-1)
src/maasserver/models/tests/test_node.py (+31/-9)
To merge this branch: bzr merge lp:~newell-jensen/maas/bug-1376888
Reviewer Review Type Date Requested Status
Blake Rouse Approve on 2014-10-09
Graham Binns (community) 2014-10-09 Approve on 2014-10-09
Review via email: mp+237861@code.launchpad.net

Commit message

Updated Node's delete method so that it will only delete host maps for macs from managed interfaces. This will now allow a user to delete nodes with an unmanaged interface that were previously enlisted into MAAS with a managed interface.

Description of the change

Self-tested with packages and also ran through CI.

To post a comment you must log in.
Graham Binns (gmb) wrote :

Nice work Newell; thanks!

review: Approve
Blake Rouse (blake-rouse) wrote :

Nice! Looks good. One little comment about using django orm.

review: Approve
lp:~newell-jensen/maas/bug-1376888 updated on 2014-10-09
3222. By Newell Jensen on 2014-10-09

Cleaning up tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/node.py'
2--- src/maasserver/models/node.py 2014-10-09 15:55:12 +0000
3+++ src/maasserver/models/node.py 2014-10-09 21:41:02 +0000
4@@ -988,7 +988,8 @@
5 # declare host maps in the dynamic range. At some point we can stop
6 # removing host maps from the dynamic range, once we decide that
7 # enough time has passed.
8- macs = self.macaddress_set.values_list('mac_address', flat=True)
9+ macs = self.mac_addresses_on_managed_interfaces().values_list(
10+ 'mac_address', flat=True)
11 leases = DHCPLease.objects.filter(
12 nodegroup=self.nodegroup, mac__in=macs)
13 leased_ips = leases.values_list("ip", flat=True)
14
15=== modified file 'src/maasserver/models/tests/test_node.py'
16--- src/maasserver/models/tests/test_node.py 2014-10-09 15:55:12 +0000
17+++ src/maasserver/models/tests/test_node.py 2014-10-09 21:41:02 +0000
18@@ -65,7 +65,10 @@
19 NODE_FAILURE_STATUS_TRANSITIONS,
20 NODE_TRANSITIONS,
21 )
22-from maasserver.rpc.testing.fixtures import MockLiveRegionToClusterRPCFixture
23+from maasserver.rpc.testing.fixtures import (
24+ MockLiveRegionToClusterRPCFixture,
25+ RunningClusterRPCFixture,
26+ )
27 from maasserver.testing.eventloop import (
28 RegionEventLoopFixture,
29 RunningEventLoopFixture,
30@@ -364,6 +367,18 @@
31 node = factory.make_Node(osystem=osystem, distro_series=series)
32 self.assertEqual(license_key, node.get_effective_license_key())
33
34+ def test_delete_node_deletes_managed_node_when_changed_to_unmanaged(self):
35+ node = factory.make_node_with_mac_attached_to_nodegroupinterface()
36+ factory.make_DHCPLease(
37+ nodegroup=node.nodegroup,
38+ mac=node.macaddress_set.all().first().mac_address)
39+ interface = node.nodegroup.nodegroupinterface_set.all().first()
40+ interface.management = NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED
41+ interface.save()
42+ self.useFixture(RunningClusterRPCFixture())
43+ node.delete()
44+ self.assertItemsEqual([], Node.objects.all())
45+
46 def test_delete_node_deletes_related_mac(self):
47 node = factory.make_Node()
48 mac = node.add_mac_address('AA:BB:CC:DD:EE:FF')
49@@ -401,9 +416,10 @@
50 def test_delete_node_also_deletes_dhcp_host_map(self):
51 remove_host_maps = self.patch_autospec(
52 node_module, "remove_host_maps")
53- lease = make_active_lease()
54- node = factory.make_Node(nodegroup=lease.nodegroup)
55- node.add_mac_address(lease.mac)
56+ node = factory.make_node_with_mac_attached_to_nodegroupinterface()
57+ lease = factory.make_DHCPLease(
58+ nodegroup=node.nodegroup,
59+ mac=node.macaddress_set.all().first().mac_address)
60 node.delete()
61 self.assertThat(
62 remove_host_maps, MockCalledOnceWith(
63@@ -412,11 +428,17 @@
64 def test_delete_node_removes_multiple_host_maps(self):
65 remove_host_maps = self.patch_autospec(
66 node_module, "remove_host_maps")
67- lease1 = make_active_lease()
68- lease2 = make_active_lease(nodegroup=lease1.nodegroup)
69- node = factory.make_Node(nodegroup=lease1.nodegroup)
70- node.add_mac_address(lease1.mac)
71- node.add_mac_address(lease2.mac)
72+ node = factory.make_node_with_mac_attached_to_nodegroupinterface()
73+ mac = node.add_mac_address('AA:BB:CC:DD:EE:FF')
74+ mac.cluster_interface = (
75+ node.nodegroup.nodegroupinterface_set.all()[:1].get())
76+ mac.save()
77+ lease1 = factory.make_DHCPLease(
78+ nodegroup=node.nodegroup,
79+ mac=node.macaddress_set.all()[:1].get().mac_address)
80+ lease2 = factory.make_DHCPLease(
81+ nodegroup=node.nodegroup,
82+ mac=mac.mac_address)
83 node.delete()
84 self.assertThat(
85 remove_host_maps, MockCalledOnceWith(