Merge "Prevent updating the node's driver if console is enabled"
This commit is contained in:
commit
767ba3b2b9
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user