Merge "Gracefully handle bad request exception" into stable/2024.2

This commit is contained in:
Zuul 2024-11-19 03:10:03 +00:00 committed by Gerrit Code Review
commit 567888d8bf
3 changed files with 18 additions and 1 deletions

View File

@ -2345,7 +2345,6 @@ class NodesController(rest.RestController):
@pecan.expose()
def _lookup(self, ident, *remainder):
if ident in self._subcontroller_map:
pecan.abort(http_client.NOT_FOUND)
@ -2353,6 +2352,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'

View File

@ -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])

View File

@ -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):