Merge "Reraise exception with converting node ID"

This commit is contained in:
Zuul 2018-05-30 05:57:30 +00:00 committed by Gerrit Code Review
commit 30b494ad46
3 changed files with 17 additions and 3 deletions

View File

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

View File

@ -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(

View 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.