diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py index e5d10ca2d8..0dde80f1fe 100644 --- a/ironic/api/controllers/v1/node.py +++ b/ironic/api/controllers/v1/node.py @@ -2349,7 +2349,6 @@ class NodesController(rest.RestController): @pecan.expose() def _lookup(self, ident, *remainder): - if ident in self._subcontroller_map: pecan.abort(http_client.NOT_FOUND) @@ -2357,6 +2356,8 @@ class NodesController(rest.RestController): ident = args.uuid_or_name('node', ident) except exception.InvalidParameterValue as e: pecan.abort(http_client.BAD_REQUEST, e.args[0]) + except exception.InvalidUuidOrName as e: + pecan.abort(http_client.BAD_REQUEST, e.args[0]) if not remainder: return if ((remainder[0] == 'portgroups' diff --git a/ironic/api/controllers/v1/portgroup.py b/ironic/api/controllers/v1/portgroup.py index 91740d3c74..9feace8ea5 100644 --- a/ironic/api/controllers/v1/portgroup.py +++ b/ironic/api/controllers/v1/portgroup.py @@ -147,6 +147,8 @@ class PortgroupsController(pecan.rest.RestController): ident = args.uuid_or_name('portgroup', ident) except exception.InvalidParameterValue as e: pecan.abort(http_client.BAD_REQUEST, e.args[0]) + except exception.InvalidUuidOrName as e: + pecan.abort(http_client.BAD_REQUEST, e.args[0]) if not remainder: return subcontroller = self._subcontroller_map.get(remainder[0]) diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index eb524a778f..006e55f76d 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -2581,6 +2581,20 @@ class TestListNodes(test_api_base.BaseApiTest): mock_vdi.assert_called_once_with(mock.ANY, mock.ANY, node.uuid, 'test-topic') + @mock.patch.object(api_utils, 'get_rpc_node', autospec=True) + def test_validate_invalid_uuid_or_name(self, mock_rpc_node): + invalid_ident = '1234~1234~1234' + mock_rpc_node.side_effect = exception.InvalidUuidOrName( + name=invalid_ident) + + ret = self.get_json('/nodes/%s' % invalid_ident, + headers={api_base.Version.string: "1.5"}, + expect_errors=True) + + self.assertEqual(http_client.BAD_REQUEST, ret.status_code) + self.assertIn('Expected a logical name or UUID', + ret.json['error_message']) + @mock.patch.object(rpcapi.ConductorAPI, 'get_indicator_state', autospec=True) def test_get_indicator_state(self, mock_gis):