Merge lp:~newell-jensen/maas/power-query-handle-bmc-is-none into lp:maas/trunk

Proposed by Newell Jensen on 2016-04-01
Status: Merged
Approved by: Blake Rouse on 2016-04-01
Approved revision: 4858
Merged at revision: 4864
Proposed branch: lp:~newell-jensen/maas/power-query-handle-bmc-is-none
Merge into: lp:maas/trunk
Diff against target: 86 lines (+23/-4)
3 files modified
src/maasserver/models/node.py (+8/-1)
src/maasserver/models/signals/power.py (+3/-1)
src/maasserver/models/signals/tests/test_power.py (+12/-2)
To merge this branch: bzr merge lp:~newell-jensen/maas/power-query-handle-bmc-is-none
Reviewer Review Type Date Requested Status
Blake Rouse (community) 2016-04-01 Approve on 2016-04-01
Review via email: mp+290757@code.launchpad.net

Commit message

Update _power_control_node on the Node model to check if BMC is None before checking if it is accessible. This remedies the situation when a power_query is performed and there is no BMC.

To post a comment you must log in.
Blake Rouse (blake-rouse) wrote :

Looks good.

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/node.py'
2--- src/maasserver/models/node.py 2016-03-30 03:33:50 +0000
3+++ src/maasserver/models/node.py 2016-04-01 16:37:24 +0000
4@@ -2906,8 +2906,15 @@
5 # Check if the BMC is accessible. If not we need to do some work to
6 # make sure we can determine which rack controller can power
7 # control this node.
8+ def is_bmc_accessible():
9+ if self.bmc is None:
10+ raise PowerProblem(
11+ "No BMC is defined. Cannot power control node.")
12+ else:
13+ return self.bmc.is_accessible()
14+
15 defer.addCallback(
16- lambda _: deferToDatabase(transactional(self.bmc.is_accessible)))
17+ lambda _: deferToDatabase(transactional(is_bmc_accessible)))
18
19 def cb_update_routable_racks(accessible):
20 if not accessible:
21
22=== modified file 'src/maasserver/models/signals/power.py'
23--- src/maasserver/models/signals/power.py 2016-03-30 03:33:50 +0000
24+++ src/maasserver/models/signals/power.py 2016-04-01 16:37:24 +0000
25@@ -9,6 +9,7 @@
26
27 from datetime import timedelta
28
29+from maasserver.exceptions import PowerProblem
30 from maasserver.models.node import Node
31 from maasserver.node_status import QUERY_TRANSITIONS
32 from maasserver.utils.orm import (
33@@ -46,7 +47,8 @@
34 d = deferToDatabase(transactional(Node.objects.get), system_id=system_id)
35 d.addCallback(lambda node: node.power_query())
36 d.addErrback(
37- lambda failure: failure.trap((Node.DoesNotExist, UnknownPowerType)))
38+ lambda failure: failure.trap(
39+ (Node.DoesNotExist, UnknownPowerType, PowerProblem)))
40 d.addErrback(
41 log.err,
42 "Failed to update power state of machine after state transition.")
43
44=== modified file 'src/maasserver/models/signals/tests/test_power.py'
45--- src/maasserver/models/signals/tests/test_power.py 2016-03-30 03:33:50 +0000
46+++ src/maasserver/models/signals/tests/test_power.py 2016-04-01 16:37:24 +0000
47@@ -7,6 +7,7 @@
48
49 from crochet import wait_for
50 from maasserver.enum import POWER_STATE
51+from maasserver.exceptions import PowerProblem
52 from maasserver.models.node import Node
53 from maasserver.models.signals import power
54 from maasserver.node_status import (
55@@ -93,13 +94,13 @@
56 power_state = yield power.update_power_state_of_node(node.system_id)
57 self.assertEqual(power_state, POWER_STATE.ON)
58
59- def test__raises_failure_for_Node_DoesNotExist(self):
60+ def test__traps_failure_for_Node_DoesNotExist(self):
61 self.assertIsNone(power.update_power_state_of_node(
62 factory.make_name('system_id')))
63
64 @wait_for_reactor
65 @defer.inlineCallbacks
66- def test__raises_failure_for_UnknownPowerType(self):
67+ def test__traps_failure_for_UnknownPowerType(self):
68 node = yield deferToDatabase(transactional(factory.make_Node))
69 mock_node_objects_get = self.patch(Node.objects, "get")
70 mock_node_objects_get.side_effect = UnknownPowerType()
71@@ -108,6 +109,15 @@
72
73 @wait_for_reactor
74 @defer.inlineCallbacks
75+ def test__traps_failure_for_PowerProblem(self):
76+ node = yield deferToDatabase(transactional(factory.make_Node))
77+ mock_node_objects_get = self.patch(Node.objects, "get")
78+ mock_node_objects_get.side_effect = PowerProblem()
79+ power_state = yield power.update_power_state_of_node(node.system_id)
80+ self.assertIsNone(power_state)
81+
82+ @wait_for_reactor
83+ @defer.inlineCallbacks
84 def test__logs_other_errors(self):
85 node = yield deferToDatabase(transactional(factory.make_Node))
86 mock_node_objects_get = self.patch(Node.objects, "get")