Merge lp:~danilo/maas/bug-1688060-houdini-pod-nodes into lp:~maas-committers/maas/trunk

Proposed by Данило Шеган
Status: Merged
Approved by: Andres Rodriguez
Approved revision: no longer in the source branch.
Merged at revision: 6053
Proposed branch: lp:~danilo/maas/bug-1688060-houdini-pod-nodes
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 54 lines (+17/-2)
2 files modified
src/maasserver/models/bmc.py (+2/-2)
src/maasserver/models/tests/test_bmc.py (+15/-0)
To merge this branch: bzr merge lp:~danilo/maas/bug-1688060-houdini-pod-nodes
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
Andres Rodriguez (community) Approve
Blake Rouse Pending
Review via email: mp+324166@code.launchpad.net

Commit message

When resyncing/refreshing a pod, ensure machines turned into rack controllers are not recommissioned.

Description of the change

When syncing machines, we instead look at all Nodes in the database with matching interface MAC addresses, and not just all Machine nodes (since rack controllers are not part of those).

As a side-effect, this will also match region-and-rack-controllers, region-controllers and devices: I don't see that as a problem (since it is matched by MAC addresses), and I prefer code that's simpler, but I can easily add extra filtering and tests if needed.

Test instructions:

1. Register a (eg. virsh) pod
2. Compose a few machines
3. Deploy one machine
4. ssh to that machine and install maas-rack-controller
5. Go to Nodes/Controllers page and follow "add rack controller" instructions to add the deployed node

It will disappear from the listing of machines in a pod, but at least refreshing a pod won't cause it to recommission (and mess up your MAAS).

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm! I think this would prevent any machine that was part of the pod and became something else to be recommissioned if refreshed.

The one thing in the future is that we will have to show it there with a different status. But that's a future thing.

Since Newell/Blake worked on RSD, I'd like a review from either of them before landing.

review: Approve
Revision history for this message
Newell Jensen (newell-jensen) wrote :

Looks good. I tested your branch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/bmc.py'
2--- src/maasserver/models/bmc.py 2017-05-04 22:02:16 +0000
3+++ src/maasserver/models/bmc.py 2017-05-17 12:04:11 +0000
4@@ -813,7 +813,7 @@
5 for interface in machine.interfaces
6 ]
7 existing_machines = list(
8- Machine.objects.filter(
9+ Node.objects.filter(
10 interface__mac_address__in=all_macs)
11 .prefetch_related("interface_set")
12 .prefetch_related('blockdevice_set__physicalblockdevice')
13@@ -821,7 +821,7 @@
14 .distinct())
15 machines = {
16 machine.id: machine
17- for machine in Machine.objects.filter(bmc__id=self.id)
18+ for machine in Node.objects.filter(bmc__id=self.id)
19 }
20 mac_machine_map = {
21 interface.mac_address: machine
22
23=== modified file 'src/maasserver/models/tests/test_bmc.py'
24--- src/maasserver/models/tests/test_bmc.py 2017-04-24 20:56:23 +0000
25+++ src/maasserver/models/tests/test_bmc.py 2017-05-17 12:04:11 +0000
26@@ -17,6 +17,7 @@
27 INTERFACE_TYPE,
28 IPADDRESS_TYPE,
29 NODE_CREATION_TYPE,
30+ NODE_TYPE,
31 POWER_STATE,
32 )
33 from maasserver.exceptions import PodProblem
34@@ -986,6 +987,20 @@
35 machine = reload_object(machine)
36 self.assertThat(machine.bmc.id, Equals(pod.id))
37
38+ def test_sync_keeps_rack_controller_pod_nodes(self):
39+ pod = factory.make_Pod()
40+ controller = factory.make_RackController(interface=True)
41+ discovered_interface = self.make_discovered_interface(
42+ mac_address=controller.interface_set.first().mac_address)
43+ discovered_machine = self.make_discovered_machine(
44+ interfaces=[discovered_interface])
45+ discovered_pod = self.make_discovered_pod(
46+ machines=[discovered_machine])
47+ pod.sync(discovered_pod, factory.make_User())
48+ controller = reload_object(controller)
49+ self.assertThat(
50+ controller.node_type, Equals(NODE_TYPE.RACK_CONTROLLER))
51+
52 def test_sync_updates_machine_properties_for_dynamic(self):
53 pod = factory.make_Pod()
54 machine = factory.make_Node(