Fix the exception when ID/Name not found
Currently NeutronClient raises a broad exception (NeutronClientException) from [1]-[2], which is not appropriate. The following patch proposes using the NotFound exception which does the same work. [1]:http://git.openstack.org/cgit/openstack/python-neutronclient/tree/neutronclient/neutron/v2_0/__init__.py#n72 [2]:http://git.openstack.org/cgit/openstack/python-neutronclient/tree/neutronclient/neutron/v2_0/__init__.py#n109 Change-Id: Ib23d1e53947b5dffcff8db0dde77cae0a0b31243
This commit is contained in:
@@ -68,9 +68,8 @@ def find_resource_by_id(client, resource, resource_id, cmd_resource=None,
|
||||
not_found_message = (_("Unable to find %(resource)s with id "
|
||||
"'%(id)s'") %
|
||||
{'resource': resource, 'id': resource_id})
|
||||
# 404 is used to simulate server side behavior
|
||||
raise exceptions.NeutronClientException(
|
||||
message=not_found_message, status_code=404)
|
||||
# 404 is raised by exceptions.NotFound to simulate serverside behavior
|
||||
raise exceptions.NotFound(message=not_found_message)
|
||||
|
||||
|
||||
def find_resourceid_by_id(client, resource, resource_id, cmd_resource=None,
|
||||
@@ -105,9 +104,8 @@ def _find_resource_by_name(client, resource, name, project_id=None,
|
||||
not_found_message = (_("Unable to find %(resource)s with name "
|
||||
"'%(name)s'") %
|
||||
{'resource': resource, 'name': name})
|
||||
# 404 is used to simulate server side behavior
|
||||
raise exceptions.NeutronClientException(
|
||||
message=not_found_message, status_code=404)
|
||||
# 404 is raised by exceptions.NotFound to simulate serverside behavior
|
||||
raise exceptions.NotFound(message=not_found_message)
|
||||
else:
|
||||
return info[0]
|
||||
|
||||
@@ -118,7 +116,7 @@ def find_resource_by_name_or_id(client, resource, name_or_id,
|
||||
try:
|
||||
return find_resource_by_id(client, resource, name_or_id,
|
||||
cmd_resource, parent_id, fields)
|
||||
except exceptions.NeutronClientException:
|
||||
except exceptions.NotFound:
|
||||
return _find_resource_by_name(client, resource, name_or_id,
|
||||
project_id, cmd_resource, parent_id,
|
||||
fields)
|
||||
|
@@ -144,7 +144,7 @@ class CLITestNameorID(testtools.TestCase):
|
||||
try:
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
self.client, 'network', name)
|
||||
except exceptions.NeutronClientException as ex:
|
||||
except exceptions.NotFound as ex:
|
||||
self.assertIn('Unable to find', ex.message)
|
||||
self.assertEqual(404, ex.status_code)
|
||||
|
||||
@@ -193,6 +193,6 @@ class CLITestNameorID(testtools.TestCase):
|
||||
try:
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
self.client, 'security_group', name, project)
|
||||
except exceptions.NeutronClientException as ex:
|
||||
except exceptions.NotFound as ex:
|
||||
self.assertIn('Unable to find', ex.message)
|
||||
self.assertEqual(404, ex.status_code)
|
||||
|
Reference in New Issue
Block a user