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
This commit is contained in:
parent
75cd526bad
commit
bae9e82e67
@ -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)
|
||||
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)
|
||||
|
||||
|
@ -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(
|
||||
|
7
releasenotes/notes/bug-2002062-959b865ced05b746.yaml
Normal file
7
releasenotes/notes/bug-2002062-959b865ced05b746.yaml
Normal file
@ -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 <https://storyboard.openstack.org/#!/story/2002062>`_ for
|
||||
details.
|
Loading…
Reference in New Issue
Block a user