diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py index 925c5c705a..5cb9456722 100644 --- a/ironic/api/controllers/v1/node.py +++ b/ironic/api/controllers/v1/node.py @@ -869,8 +869,13 @@ class NodeTraitsController(rest.RestController): with notify.handle_error_notification(context, node, 'update', chassis_uuid=chassis_uuid): topic = pecan.request.rpcapi.get_topic_for(node) - pecan.request.rpcapi.remove_node_traits( - context, node.id, traits, topic=topic) + try: + pecan.request.rpcapi.remove_node_traits( + context, node.id, traits, topic=topic) + except exception.NodeTraitNotFound: + # NOTE(hshiina): Internal node ID should not be exposed. + raise exception.NodeTraitNotFound(node_id=node.uuid, + trait=trait) notify.emit_end_notification(context, node, 'update', chassis_uuid=chassis_uuid) diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index 228de8c4c2..8d03032809 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -4926,11 +4926,13 @@ class TestTraits(test_api_base.BaseApiTest): def test_delete_trait_fails_if_trait_not_found(self, mock_notify, mock_remove): mock_remove.side_effect = exception.NodeTraitNotFound( - node_id=self.node.uuid, trait='CUSTOM_12') + node_id=self.node.id, trait='CUSTOM_12') ret = self.delete('/nodes/%s/traits/CUSTOM_12' % self.node.name, headers={api_base.Version.string: self.version}, expect_errors=True) self.assertEqual(http_client.NOT_FOUND, ret.status_code) + self.assertIn(self.node.uuid, ret.json['error_message']) + self.assertNotIn(self.node.id, ret.json['error_message']) mock_remove.assert_called_once_with(mock.ANY, self.node.id, ['CUSTOM_12'], topic='test-topic') mock_notify.assert_has_calls( diff --git a/releasenotes/notes/bug-2002062-959b865ced05b746.yaml b/releasenotes/notes/bug-2002062-959b865ced05b746.yaml new file mode 100644 index 0000000000..eeb1b315c0 --- /dev/null +++ b/releasenotes/notes/bug-2002062-959b865ced05b746.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes a bug that exposes an internal node ID in an error message when + requested to delete a trait which doesn't exist. See + `bug 2002062 `_ for + details.