Merge ~newell-jensen/maas:lp1812509 into maas:master

Proposed by Newell Jensen
Status: Merged
Approved by: Newell Jensen
Approved revision: 11fc99cc35737568d9c3c369130c5dbc14f44a32
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~newell-jensen/maas:lp1812509
Merge into: maas:master
Diff against target: 71 lines (+37/-4)
2 files modified
src/maasserver/models/node.py (+8/-3)
src/maasserver/models/tests/test_node.py (+29/-1)
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
MAAS Lander Approve
Review via email: mp+362228@code.launchpad.net

Commit message

LP: #1812509 -- Fix setting the power type for a node with BMCs that have matching power parameters.

To post a comment you must log in.
Revision history for this message
Newell Jensen (newell-jensen) wrote :

To me this seems like a better fix than doing a data migration because if there are any machines with potentially matching power parameters (future power types), this fix will cover them as well.

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1812509 lp:~newell-jensen/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 90036214afa07bca2b58a0dd935eabbe313167a6

review: Approve
Revision history for this message
Björn Tillenius (bjornt) wrote :

I need more context before I can review this. Which revision and migration caused this bug to happen?

I'd like to look more into this, since the solution looks more like a workaround than a proper fix.

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

> I need more context before I can review this. Which revision and migration
> caused this bug to happen?
>
> I'd like to look more into this, since the solution looks more like a
> workaround than a proper fix.

Before the migration, machines with a manual power type were all linked to a singleton BMC. The migration broke up this linked BMC and made it so all the machines had their own BMC. This causes an exception to be raised at this particular point in the code. If we introduced another migration to fix this issue, we would have to rearrange previous migrations, as this needs to be backported to 2.5. I agree with your comment on the XXX portion.

Revision history for this message
Blake Rouse (blake-rouse) wrote :

I think we need to fix this another way, because a manual power type is a unique BMC per machine. I understand that manual is in a unique situation where the power_parameters are the same for each machine.

I feel like there is another way to solve this. I feel like this is only an issue with the manual power provider anyway. Why not special case the manual power type (we already do that in many places) and do the correct thing at that point.

review: Needs Fixing
~newell-jensen/maas:lp1812509 updated
2992c82... by Newell Jensen

Handle the manual power type directly to create its BMC when setting the power type for a node.

8bb5145... by Newell Jensen

Remove code that is no longer needed.

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1812509 lp:~newell-jensen/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 2992c82a4c0e0299e6871e37a7b5722b13aa9613

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1812509 lp:~newell-jensen/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 8bb51451bce93145d6ebaf8c77d41a6ef3ba404c

review: Approve
~newell-jensen/maas:lp1812509 updated
882bc59... by Newell Jensen

Add unit test to show that setting a manual power type machine to manual does not create an additional BMC.

11fc99c... by Newell Jensen

Fix unit test to use bmc id.

Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good, thanks for the test.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
2index 998e02c..b2f558e 100644
3--- a/src/maasserver/models/node.py
4+++ b/src/maasserver/models/node.py
5@@ -1,4 +1,4 @@
6-# Copyright 2012-2018 Canonical Ltd. This software is licensed under the
7+# Copyright 2012-2019 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 """Node objects."""
11@@ -1223,8 +1223,13 @@ class Node(CleanSave, TimestampedModel):
12 return
13 if self.bmc is not None and self.bmc.power_type == power_type:
14 return
15- self.bmc, _ = BMC.objects.get_or_create(
16- power_type=power_type, power_parameters=self.power_parameters)
17+
18+ if power_type == 'manual':
19+ self.bmc = BMC.objects.create(
20+ power_type='manual', power_parameters={})
21+ else:
22+ self.bmc, _ = BMC.objects.get_or_create(
23+ power_type=power_type, power_parameters=self.power_parameters)
24
25 @property
26 def power_parameters(self):
27diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
28index 361b6f8..3aa4169 100644
29--- a/src/maasserver/models/tests/test_node.py
30+++ b/src/maasserver/models/tests/test_node.py
31@@ -1,4 +1,4 @@
32-# Copyright 2012-2018 Canonical Ltd. This software is licensed under the
33+# Copyright 2012-2019 Canonical Ltd. This software is licensed under the
34 # GNU Affero General Public License version 3 (see the file LICENSE).
35
36 """Test maasserver models."""
37@@ -4582,6 +4582,34 @@ class TestNodePowerParameters(MAASServerTestCase):
38 self.assertEqual(node.power_type, node.bmc.power_type)
39 self.assertEqual(ip_address, node.bmc.ip_address.ip)
40
41+ def test_power_type_creates_new_bmc_for_manual_power_type(self):
42+ ip_address = factory.make_ipv4_address()
43+ bmc_parameters = dict(power_address=ip_address)
44+ node_parameters = dict(server_name=factory.make_string())
45+ parameters = {**bmc_parameters, **node_parameters}
46+ node = factory.make_Node(
47+ power_type='virsh', power_parameters=parameters)
48+ self.assertFalse(BMC.objects.filter(power_type='manual'))
49+ node.power_type = 'manual'
50+ node.save()
51+ node = reload_object(node)
52+ self.assertEqual('manual', node.bmc.power_type)
53+ self.assertEqual({}, node.bmc.power_parameters)
54+ self.assertTrue(BMC.objects.filter(power_type='manual'))
55+
56+ def test_power_type_does_not_create_new_bmc_for_already_manual(self):
57+ ip_address = factory.make_ipv4_address()
58+ bmc_parameters = dict(power_address=ip_address)
59+ node_parameters = dict(server_name=factory.make_string())
60+ parameters = {**bmc_parameters, **node_parameters}
61+ node = factory.make_Node(
62+ power_type='manual', power_parameters=parameters)
63+ bmc_id = node.bmc.id
64+ node.power_type = 'manual'
65+ node.save()
66+ node = reload_object(node)
67+ self.assertEqual(bmc_id, node.bmc.id)
68+
69 def test_power_parameters_are_stored_in_proper_scopes(self):
70 node = factory.make_Node(power_type='virsh')
71 bmc_parameters = dict(

Subscribers

People subscribed via source and target branches