Fix wrong exception raised by conductor for node
* Conductor should raise NodeInMaintenance exception while provisioning node which is under maintainence, same as the exception raised by the REST API Change-Id: Ieab302fb96c7b1c11eaefc79621f0c635a16fefc Closes-Bug: #1286410
This commit is contained in:
parent
d578c98b1a
commit
dc92f2f5a3
@ -187,15 +187,10 @@ class NodeStatesController(rest.RestController):
|
||||
the requested state.
|
||||
:raises: InvalidStateRequested (HTTP 400) if the requested target
|
||||
state is not valid.
|
||||
|
||||
"""
|
||||
rpc_node = objects.Node.get_by_uuid(pecan.request.context, node_uuid)
|
||||
topic = pecan.request.rpcapi.get_topic_for(rpc_node)
|
||||
|
||||
if rpc_node.maintenance:
|
||||
op = _('provisioning')
|
||||
raise exception.NodeInMaintenance(op=op, node=node_uuid)
|
||||
|
||||
if rpc_node.target_provision_state is not None:
|
||||
msg = _('Node %s is already being provisioned.') % rpc_node['uuid']
|
||||
LOG.exception(msg)
|
||||
|
@ -334,9 +334,8 @@ class ConductorManager(service.PeriodicService):
|
||||
{'node': node_id, 'state': node['provision_state']})
|
||||
|
||||
if node.maintenance:
|
||||
raise exception.InstanceDeployFailure(_(
|
||||
"RPC do_node_deploy called for %s, but node is in "
|
||||
"maintenance mode.") % node_id)
|
||||
raise exception.NodeInMaintenance(op=_('provisioning'),
|
||||
node=node.uuid)
|
||||
|
||||
try:
|
||||
task.driver.deploy.validate(task, node)
|
||||
|
@ -938,11 +938,15 @@ class TestPut(base.FunctionalTest):
|
||||
True, 'test-topic')
|
||||
|
||||
def test_provision_node_in_maintenance_fail(self):
|
||||
ndict = dbutils.get_test_node(id=1, uuid=utils.generate_uuid(),
|
||||
maintenance=True)
|
||||
node = self.dbapi.create_node(ndict)
|
||||
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
|
||||
{'target': states.ACTIVE},
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, ret.status_code)
|
||||
self.assertTrue(ret.json['error_message'])
|
||||
with mock.patch.object(rpcapi.ConductorAPI, 'do_node_deploy') as dnd:
|
||||
ndict = dbutils.get_test_node(id=1, uuid=utils.generate_uuid(),
|
||||
maintenance=True)
|
||||
node = self.dbapi.create_node(ndict)
|
||||
dnd.side_effect = exception.NodeInMaintenance(op='provisioning',
|
||||
node=node.uuid)
|
||||
|
||||
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
|
||||
{'target': states.ACTIVE},
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, ret.status_code)
|
||||
self.assertTrue(ret.json['error_message'])
|
||||
|
@ -518,7 +518,7 @@ class ManagerTestCase(base.DbTestCase):
|
||||
def test_do_node_deploy_maintenance(self):
|
||||
ndict = utils.get_test_node(driver='fake', maintenance=True)
|
||||
node = self.dbapi.create_node(ndict)
|
||||
self.assertRaises(exception.InstanceDeployFailure,
|
||||
self.assertRaises(exception.NodeInMaintenance,
|
||||
self.service.do_node_deploy,
|
||||
self.context, node['uuid'])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user