From bae9e82e67039c90b5c139b2e1bd0f1688490182 Mon Sep 17 00:00:00 2001 From: Hironori Shiina Date: Mon, 21 May 2018 18:32:50 +0900 Subject: [PATCH] Reraise exception with converting node ID When a requested trait doesn't exist at trait deletion, the API response contains an internal node ID, which shouldn't be exposed. This patch reraises an exception with a node identifier specified to the API. Change-Id: I781a510b25fa7de735c97b4ed919dfcb3adbdd2c Story: 2002062 Task: 19715 --- ironic/api/controllers/v1/node.py | 9 +++++++-- ironic/tests/unit/api/controllers/v1/test_node.py | 4 +++- releasenotes/notes/bug-2002062-959b865ced05b746.yaml | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/bug-2002062-959b865ced05b746.yaml diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py index b6d2903054..eaf6150eec 100644 --- a/ironic/api/controllers/v1/node.py +++ b/ironic/api/controllers/v1/node.py @@ -865,8 +865,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 14c5a91415..be708714f5 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -4846,11 +4846,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.