Merge "Raise HTTP 400 rather than 500 error"
This commit is contained in:
commit
0656229b48
@ -2389,7 +2389,7 @@ class ConductorManager(base_manager.BaseConductorManager):
|
|||||||
@METRICS.timer('ConductorManager.inspect_hardware')
|
@METRICS.timer('ConductorManager.inspect_hardware')
|
||||||
@messaging.expected_exceptions(exception.NoFreeConductorWorker,
|
@messaging.expected_exceptions(exception.NoFreeConductorWorker,
|
||||||
exception.NodeLocked,
|
exception.NodeLocked,
|
||||||
exception.HardwareInspectionFailure,
|
exception.InvalidParameterValue,
|
||||||
exception.InvalidStateRequested,
|
exception.InvalidStateRequested,
|
||||||
exception.UnsupportedDriverExtension)
|
exception.UnsupportedDriverExtension)
|
||||||
def inspect_hardware(self, context, node_id):
|
def inspect_hardware(self, context, node_id):
|
||||||
@ -2406,8 +2406,10 @@ class ConductorManager(base_manager.BaseConductorManager):
|
|||||||
support inspect.
|
support inspect.
|
||||||
:raises: NoFreeConductorWorker when there is no free worker to start
|
:raises: NoFreeConductorWorker when there is no free worker to start
|
||||||
async task
|
async task
|
||||||
:raises: HardwareInspectionFailure when unable to get
|
:raises: InvalidParameterValue when unable to get
|
||||||
essential scheduling properties from hardware.
|
essential scheduling properties from hardware.
|
||||||
|
:raises: MissingParameterValue when required
|
||||||
|
information is not found.
|
||||||
:raises: InvalidStateRequested if 'inspect' is not a
|
:raises: InvalidStateRequested if 'inspect' is not a
|
||||||
valid action to do in the current state.
|
valid action to do in the current state.
|
||||||
|
|
||||||
@ -2419,14 +2421,8 @@ class ConductorManager(base_manager.BaseConductorManager):
|
|||||||
raise exception.UnsupportedDriverExtension(
|
raise exception.UnsupportedDriverExtension(
|
||||||
driver=task.node.driver, extension='inspect')
|
driver=task.node.driver, extension='inspect')
|
||||||
|
|
||||||
try:
|
|
||||||
task.driver.power.validate(task)
|
task.driver.power.validate(task)
|
||||||
task.driver.inspect.validate(task)
|
task.driver.inspect.validate(task)
|
||||||
except exception.InvalidParameterValue as e:
|
|
||||||
error = (_("Failed to validate inspection or power info. "
|
|
||||||
"Error: %(msg)s")
|
|
||||||
% {'msg': e})
|
|
||||||
raise exception.HardwareInspectionFailure(error=error)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
task.process_event(
|
task.process_event(
|
||||||
|
@ -3030,6 +3030,32 @@ class TestPut(test_api_base.BaseApiTest):
|
|||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
self.assertEqual(http_client.CONFLICT, ret.status_code) # Conflict
|
self.assertEqual(http_client.CONFLICT, ret.status_code) # Conflict
|
||||||
|
|
||||||
|
def test_inspect_validation_failed_status_code(self):
|
||||||
|
self.mock_dnih.side_effect = exception.InvalidParameterValue(
|
||||||
|
err='Failed to validate inspection or power info.')
|
||||||
|
node = self.node
|
||||||
|
node.provision_state = states.MANAGEABLE
|
||||||
|
node.reservation = 'fake-host'
|
||||||
|
node.save()
|
||||||
|
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
|
||||||
|
{'target': 'inspect'},
|
||||||
|
headers={api_base.Version.string: "1.6"},
|
||||||
|
expect_errors=True)
|
||||||
|
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
|
||||||
|
|
||||||
|
def test_inspect_validation_failed_missing_parameter_value(self):
|
||||||
|
self.mock_dnih.side_effect = exception.MissingParameterValue(
|
||||||
|
err='Failed to validate inspection or power info.')
|
||||||
|
node = self.node
|
||||||
|
node.provision_state = states.MANAGEABLE
|
||||||
|
node.reservation = 'fake-host'
|
||||||
|
node.save()
|
||||||
|
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
|
||||||
|
{'target': 'inspect'},
|
||||||
|
headers={api_base.Version.string: "1.6"},
|
||||||
|
expect_errors=True)
|
||||||
|
self.assertEqual(http_client.BAD_REQUEST, ret.status_code)
|
||||||
|
|
||||||
@mock.patch.object(rpcapi.ConductorAPI, 'do_provisioning_action')
|
@mock.patch.object(rpcapi.ConductorAPI, 'do_provisioning_action')
|
||||||
def test_manage_from_available(self, mock_dpa):
|
def test_manage_from_available(self, mock_dpa):
|
||||||
self.node.provision_state = states.AVAILABLE
|
self.node.provision_state = states.AVAILABLE
|
||||||
|
@ -5280,13 +5280,22 @@ class NodeInspectHardware(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
|
|||||||
self.assertIsNone(node.reservation)
|
self.assertIsNone(node.reservation)
|
||||||
|
|
||||||
def _test_inspect_hardware_validate_fail(self, mock_validate):
|
def _test_inspect_hardware_validate_fail(self, mock_validate):
|
||||||
mock_validate.side_effect = exception.InvalidParameterValue('error')
|
mock_validate.side_effect = exception.InvalidParameterValue(
|
||||||
|
'Fake error message')
|
||||||
node = obj_utils.create_test_node(self.context, driver='fake')
|
node = obj_utils.create_test_node(self.context, driver='fake')
|
||||||
exc = self.assertRaises(messaging.rpc.ExpectedException,
|
exc = self.assertRaises(messaging.rpc.ExpectedException,
|
||||||
self.service.inspect_hardware,
|
self.service.inspect_hardware,
|
||||||
self.context, node.uuid)
|
self.context, node.uuid)
|
||||||
# Compare true exception hidden by @messaging.expected_exceptions
|
# Compare true exception hidden by @messaging.expected_exceptions
|
||||||
self.assertEqual(exception.HardwareInspectionFailure, exc.exc_info[0])
|
self.assertEqual(exception.InvalidParameterValue, exc.exc_info[0])
|
||||||
|
|
||||||
|
mock_validate.side_effect = exception.MissingParameterValue(
|
||||||
|
'Fake error message')
|
||||||
|
exc = self.assertRaises(messaging.rpc.ExpectedException,
|
||||||
|
self.service.inspect_hardware,
|
||||||
|
self.context, node.uuid)
|
||||||
|
self.assertEqual(exception.MissingParameterValue, exc.exc_info[0])
|
||||||
|
|
||||||
# This is a sync operation last_error should be None.
|
# This is a sync operation last_error should be None.
|
||||||
self.assertIsNone(node.last_error)
|
self.assertIsNone(node.last_error)
|
||||||
# Verify reservation has been cleared.
|
# Verify reservation has been cleared.
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- Raise HTTP 400 Bad request on failure to validate
|
||||||
|
power or inspect interface parameters before inspecting.
|
Loading…
Reference in New Issue
Block a user