Merge "Fix the exception when ID/Name not found"
This commit is contained in:
@@ -69,9 +69,8 @@ def find_resource_by_id(client, resource, resource_id, cmd_resource=None,
|
|||||||
not_found_message = (_("Unable to find %(resource)s with id "
|
not_found_message = (_("Unable to find %(resource)s with id "
|
||||||
"'%(id)s'") %
|
"'%(id)s'") %
|
||||||
{'resource': resource, 'id': resource_id})
|
{'resource': resource, 'id': resource_id})
|
||||||
# 404 is used to simulate server side behavior
|
# 404 is raised by exceptions.NotFound to simulate serverside behavior
|
||||||
raise exceptions.NeutronClientException(
|
raise exceptions.NotFound(message=not_found_message)
|
||||||
message=not_found_message, status_code=404)
|
|
||||||
|
|
||||||
|
|
||||||
def find_resourceid_by_id(client, resource, resource_id, cmd_resource=None,
|
def find_resourceid_by_id(client, resource, resource_id, cmd_resource=None,
|
||||||
@@ -106,9 +105,8 @@ def _find_resource_by_name(client, resource, name, project_id=None,
|
|||||||
not_found_message = (_("Unable to find %(resource)s with name "
|
not_found_message = (_("Unable to find %(resource)s with name "
|
||||||
"'%(name)s'") %
|
"'%(name)s'") %
|
||||||
{'resource': resource, 'name': name})
|
{'resource': resource, 'name': name})
|
||||||
# 404 is used to simulate server side behavior
|
# 404 is raised by exceptions.NotFound to simulate serverside behavior
|
||||||
raise exceptions.NeutronClientException(
|
raise exceptions.NotFound(message=not_found_message)
|
||||||
message=not_found_message, status_code=404)
|
|
||||||
else:
|
else:
|
||||||
return info[0]
|
return info[0]
|
||||||
|
|
||||||
@@ -119,7 +117,7 @@ def find_resource_by_name_or_id(client, resource, name_or_id,
|
|||||||
try:
|
try:
|
||||||
return find_resource_by_id(client, resource, name_or_id,
|
return find_resource_by_id(client, resource, name_or_id,
|
||||||
cmd_resource, parent_id, fields)
|
cmd_resource, parent_id, fields)
|
||||||
except exceptions.NeutronClientException:
|
except exceptions.NotFound:
|
||||||
return _find_resource_by_name(client, resource, name_or_id,
|
return _find_resource_by_name(client, resource, name_or_id,
|
||||||
project_id, cmd_resource, parent_id,
|
project_id, cmd_resource, parent_id,
|
||||||
fields)
|
fields)
|
||||||
|
@@ -144,7 +144,7 @@ class CLITestNameorID(testtools.TestCase):
|
|||||||
try:
|
try:
|
||||||
neutronV20.find_resourceid_by_name_or_id(
|
neutronV20.find_resourceid_by_name_or_id(
|
||||||
self.client, 'network', name)
|
self.client, 'network', name)
|
||||||
except exceptions.NeutronClientException as ex:
|
except exceptions.NotFound as ex:
|
||||||
self.assertIn('Unable to find', ex.message)
|
self.assertIn('Unable to find', ex.message)
|
||||||
self.assertEqual(404, ex.status_code)
|
self.assertEqual(404, ex.status_code)
|
||||||
|
|
||||||
@@ -193,6 +193,6 @@ class CLITestNameorID(testtools.TestCase):
|
|||||||
try:
|
try:
|
||||||
neutronV20.find_resourceid_by_name_or_id(
|
neutronV20.find_resourceid_by_name_or_id(
|
||||||
self.client, 'security_group', name, project)
|
self.client, 'security_group', name, project)
|
||||||
except exceptions.NeutronClientException as ex:
|
except exceptions.NotFound as ex:
|
||||||
self.assertIn('Unable to find', ex.message)
|
self.assertIn('Unable to find', ex.message)
|
||||||
self.assertEqual(404, ex.status_code)
|
self.assertEqual(404, ex.status_code)
|
||||||
|
Reference in New Issue
Block a user