diff --git a/ironic/common/exception.py b/ironic/common/exception.py index f33cac85f9..8ab107d9fe 100644 --- a/ironic/common/exception.py +++ b/ironic/common/exception.py @@ -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: diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py index 6e3182358c..801f7808c7 100644 --- a/ironic/conductor/manager.py +++ b/ironic/conductor/manager.py @@ -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}) diff --git a/ironic/tests/unit/conductor/test_manager.py b/ironic/tests/unit/conductor/test_manager.py index eb6cd3eeda..7efbdc6816 100644 --- a/ironic/tests/unit/conductor/test_manager.py +++ b/ironic/tests/unit/conductor/test_manager.py @@ -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 diff --git a/releasenotes/notes/fix_deploy_validation_resp_code-ed93627d1b0dfa94.yaml b/releasenotes/notes/fix_deploy_validation_resp_code-ed93627d1b0dfa94.yaml new file mode 100644 index 0000000000..e2bee8bf43 --- /dev/null +++ b/releasenotes/notes/fix_deploy_validation_resp_code-ed93627d1b0dfa94.yaml @@ -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.