Merge "Prevent updating the node's driver if console is enabled"

This commit is contained in:
Jenkins 2015-03-31 21:42:45 +00:00 committed by Gerrit Code Review
commit 767ba3b2b9
2 changed files with 25 additions and 0 deletions

View File

@ -1078,6 +1078,16 @@ class NodesController(rest.RestController):
e.code = 400
raise e
# NOTE(lucasagomes): If it's changing the driver and the console
# is enabled we prevent updating it because the new driver will
# not be able to stop a console started by the previous one.
delta = rpc_node.obj_what_changed()
if 'driver' in delta and rpc_node.console_enabled:
raise wsme.exc.ClientSideError(
_("Node %s can not update the driver while the console is "
"enabled. Please stop the console first.") % node_ident,
status_code=409)
new_node = pecan.request.rpcapi.update_node(
pecan.request.context, rpc_node, topic)

View File

@ -1169,6 +1169,21 @@ class TestPatch(test_api_base.FunctionalTest):
self.assertEqual(409, response.status_code)
self.assertTrue(response.json['error_message'])
@mock.patch.object(api_node, '_get_rpc_node')
def test_patch_update_drive_console_enabled(self, mock_rpc_node):
self.node.console_enabled = True
mock_rpc_node.return_value = self.node
response = self.patch_json('/nodes/%s' % self.node.uuid,
[{'path': '/driver',
'value': 'foo',
'op': 'add'}],
expect_errors=True)
mock_rpc_node.assert_called_once_with(self.node.uuid)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_code)
self.assertTrue(response.json['error_message'])
class TestPost(test_api_base.FunctionalTest):