Make validation failure on node deploy a 4XX code

Missing information and other validation issues with instance_info is a
user error and should be a 4XX code HTTP response, currently Ironic
responds with a 5XX code indicating something has gone wrong with the
service.

Change-Id: If76e2aba97e0ed9fa63ad3c411ed92969164d3dc
Story: #2001983
Task: #19600
This commit is contained in:
Sam Betts 2018-05-08 14:08:02 +01:00 committed by Jim Rollenhagen
parent 02d8fa1393
commit 6ff9a6b14c
4 changed files with 11 additions and 1 deletions

View File

@ -104,6 +104,8 @@ class IronicException(Exception):
self.kwargs['code'] = self.code
except AttributeError:
pass
else:
self.code = int(kwargs['code'])
if not message:
try:

View File

@ -827,7 +827,7 @@ class ConductorManager(base_manager.BaseConductorManager):
raise exception.InstanceDeployFailure(
_("Failed to validate deploy or power info for node "
"%(node_uuid)s. Error: %(msg)s") %
{'node_uuid': node.uuid, 'msg': e})
{'node_uuid': node.uuid, 'msg': e}, code=e.code)
LOG.debug("do_node_deploy Calling event: %(event)s for node: "
"%(node)s", {'event': event, 'node': node.uuid})

View File

@ -1218,6 +1218,7 @@ class ServiceDoNodeDeployTestCase(mgr_utils.ServiceSetUpMixin,
self.context, node.uuid)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.InstanceDeployFailure, exc.exc_info[0])
self.assertEqual(exc.exc_info[1].code, 400)
# Check the message of InstanceDeployFailure. In a
# messaging.rpc.ExpectedException sys.exc_info() is stored in exc_info
# in the exception object. So InstanceDeployFailure will be in

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixes the HTTP response code for a validation failure when attempting to
move an ironic node to the active state. Validation failure in this
scenario now responses with a 400 status code correctly indicating a user
input error.