Merge lp:~blake-rouse/maas/fix-1457990 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 3948
Proposed branch: lp:~blake-rouse/maas/fix-1457990
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 42 lines (+13/-1)
2 files modified
src/maasserver/node_action.py (+3/-0)
src/maasserver/tests/test_node_action.py (+10/-1)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1457990
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+260229@code.launchpad.net

Commit message

Prevent starting commissioning of a node that is new and on.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Code looks good, but minor nit about the wording of the error.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/node_action.py'
2--- src/maasserver/node_action.py 2015-05-23 01:54:39 +0000
3+++ src/maasserver/node_action.py 2015-05-27 01:29:13 +0000
4@@ -236,6 +236,9 @@
5
6 def execute(self):
7 """See `NodeAction.execute`."""
8+ if self.node.power_state == POWER_STATE.ON:
9+ raise NodeActionError(
10+ "Unable to be commissioned because the power is currently on.")
11 try:
12 self.node.start_commissioning(self.user)
13 except RPC_EXCEPTIONS + (ExternalProcessError,) as exception:
14
15=== modified file 'src/maasserver/tests/test_node_action.py'
16--- src/maasserver/tests/test_node_action.py 2015-05-22 17:08:29 +0000
17+++ src/maasserver/tests/test_node_action.py 2015-05-27 01:29:13 +0000
18@@ -263,6 +263,14 @@
19 ("READY", {"status": NODE_STATUS.READY}),
20 )
21
22+ def test_raise_NodeActionError_if_on(self):
23+ node = factory.make_Node(
24+ status=self.status, power_state=POWER_STATE.ON)
25+ user = factory.make_admin()
26+ action = Commission(node, user)
27+ self.assertTrue(action.is_permitted())
28+ self.assertRaises(NodeActionError, action.execute)
29+
30 def test_Commission_starts_commissioning(self):
31 node = factory.make_Node(
32 mac=True, status=self.status,
33@@ -793,7 +801,8 @@
34 self.addCleanup(node_query.enable)
35 node_query.disable()
36
37- action = self.make_action(Commission, NODE_STATUS.READY)
38+ action = self.make_action(
39+ Commission, NODE_STATUS.READY, POWER_STATE.OFF)
40 self.patch_rpc_methods(action.node)
41 exception = self.assertRaises(NodeActionError, action.execute)
42 self.assertEqual(