Merge "Change deploy validation exception handling"
This commit is contained in:
commit
12f48dd496
@ -349,7 +349,6 @@ class ConductorManager(service.PeriodicService):
|
||||
:param node_id: the id or uuid of a node.
|
||||
:raises: InstanceDeployFailure
|
||||
:raises: NodeInMaintenance if the node is in maintenance mode.
|
||||
:raises: InvalidParameterValue if validation fails
|
||||
:raises: NoFreeConductorWorker when there is no free worker to start
|
||||
async task.
|
||||
|
||||
@ -369,7 +368,12 @@ class ConductorManager(service.PeriodicService):
|
||||
raise exception.NodeInMaintenance(op=_('provisioning'),
|
||||
node=node.uuid)
|
||||
|
||||
task.driver.deploy.validate(task, node)
|
||||
try:
|
||||
task.driver.deploy.validate(task, node)
|
||||
except exception.InvalidParameterValue as e:
|
||||
raise exception.InstanceDeployFailure(_(
|
||||
"RPC do_node_deploy failed to validate deploy info. "
|
||||
"Error: %(msg)s") % {'msg': e})
|
||||
|
||||
# Set target state to expose that work is in progress
|
||||
node.provision_state = states.DEPLOYING
|
||||
@ -420,7 +424,6 @@ class ConductorManager(service.PeriodicService):
|
||||
:param context: an admin context.
|
||||
:param node_id: the id or uuid of a node.
|
||||
:raises: InstanceDeployFailure
|
||||
:raises: InvalidParameterValue if validation fails
|
||||
:raises: NoFreeConductorWorker when there is no free worker to start
|
||||
async task
|
||||
|
||||
@ -435,11 +438,17 @@ class ConductorManager(service.PeriodicService):
|
||||
states.ERROR,
|
||||
states.DEPLOYWAIT]:
|
||||
raise exception.InstanceDeployFailure(_(
|
||||
"RCP do_node_tear_down "
|
||||
"RPC do_node_tear_down "
|
||||
"not allowed for node %(node)s in state %(state)s")
|
||||
% {'node': node_id, 'state': node.provision_state})
|
||||
|
||||
task.driver.deploy.validate(task, node)
|
||||
try:
|
||||
task.driver.deploy.validate(task, node)
|
||||
except exception.InvalidParameterValue as e:
|
||||
raise exception.InstanceDeployFailure(_(
|
||||
"RPC do_node_tear_down failed to validate deploy info. "
|
||||
"Error: %(msg)s") % {'msg': e})
|
||||
|
||||
node.provision_state = states.DELETING
|
||||
node.target_provision_state = states.DELETED
|
||||
node.last_error = None
|
||||
|
@ -613,12 +613,15 @@ class ManagerTestCase(base.DbTestCase):
|
||||
|
||||
@mock.patch('ironic.drivers.modules.fake.FakeDeploy.validate')
|
||||
def test_do_node_deploy_validate_fail(self, mock_validate):
|
||||
# InvalidParameterValue should be re-raised as InstanceDeployFailure
|
||||
mock_validate.side_effect = exception.InvalidParameterValue('error')
|
||||
ndict = utils.get_test_node(driver='fake')
|
||||
node = self.dbapi.create_node(ndict)
|
||||
self.assertRaises(exception.InvalidParameterValue,
|
||||
self.service.do_node_deploy,
|
||||
self.context, node.uuid)
|
||||
exc = self.assertRaises(messaging.ClientException,
|
||||
self.service.do_node_deploy,
|
||||
self.context, node.uuid)
|
||||
# Compare true exception hidden by @messaging.client_exceptions
|
||||
self.assertEqual(exc._exc_info[0], exception.InstanceDeployFailure)
|
||||
# This is a sync operation last_error should be None.
|
||||
self.assertIsNone(node.last_error)
|
||||
# Verify reservation has been cleared.
|
||||
@ -712,13 +715,16 @@ class ManagerTestCase(base.DbTestCase):
|
||||
|
||||
@mock.patch('ironic.drivers.modules.fake.FakeDeploy.validate')
|
||||
def test_do_node_tear_down_validate_fail(self, mock_validate):
|
||||
# InvalidParameterValue should be re-raised as InstanceDeployFailure
|
||||
mock_validate.side_effect = exception.InvalidParameterValue('error')
|
||||
ndict = utils.get_test_node(driver='fake')
|
||||
ndict['provision_state'] = states.ACTIVE
|
||||
node = self.dbapi.create_node(ndict)
|
||||
self.assertRaises(exception.InvalidParameterValue,
|
||||
self.service.do_node_tear_down,
|
||||
self.context, node.uuid)
|
||||
exc = self.assertRaises(messaging.ClientException,
|
||||
self.service.do_node_tear_down,
|
||||
self.context, node.uuid)
|
||||
# Compare true exception hidden by @messaging.client_exceptions
|
||||
self.assertEqual(exc._exc_info[0], exception.InstanceDeployFailure)
|
||||
|
||||
@mock.patch('ironic.drivers.modules.fake.FakeDeploy.tear_down')
|
||||
def test_do_node_tear_down_driver_raises_error(self, mock_tear_down):
|
||||
|
Loading…
x
Reference in New Issue
Block a user