Merge "Prevent power actions on node in cleaning"

This commit is contained in:
Jenkins 2015-03-31 23:08:19 +00:00 committed by Gerrit Code Review
commit 8bcfb5ab80
2 changed files with 14 additions and 1 deletions

View File

@ -358,7 +358,7 @@ class NodeStatesController(rest.RestController):
:raises: ClientSideError (HTTP 409) if a power operation is
already in progress.
:raises: InvalidStateRequested (HTTP 400) if the requested target
state is not valid.
state is not valid or if the node is in CLEANING state.
"""
# TODO(lucasagomes): Test if it's able to transition to the
@ -373,6 +373,12 @@ class NodeStatesController(rest.RestController):
action=target, node=node_ident,
state=rpc_node.power_state)
# Don't change power state for nodes in cleaning
elif rpc_node.provision_state == ir_states.CLEANING:
raise exception.InvalidStateRequested(
action=target, node=node_ident,
state=rpc_node.power_state)
pecan.request.rpcapi.change_node_power_state(pecan.request.context,
rpc_node.uuid, target,
topic)

View File

@ -1618,6 +1618,13 @@ class TestPut(test_api_base.FunctionalTest):
{'target': 'not-supported'}, expect_errors=True)
self.assertEqual(400, ret.status_code)
def test_power_change_during_cleaning(self):
self.node.provision_state = states.CLEANING
self.node.save()
ret = self.put_json('/nodes/%s/states/power' % self.node.uuid,
{'target': states.POWER_OFF}, expect_errors=True)
self.assertEqual(400, ret.status_code)
def test_provision_invalid_state_request(self):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': 'not-supported'}, expect_errors=True)