raise better exception for duplicate match

When a duplicate match is found the client previously raised a
NeutronClientException which made it hard for programs using the client
to handle errors. This patch now  makes it raise a
NeutronClientNoUniqueMatch  exception instead.

Fixes bug: 1200323

Change-Id: I6ef6f9a9e257104f676dde7ec26be98417ec70e0
This commit is contained in:
Aaron Rosen
2013-07-11 10:54:59 -07:00
parent 2fade1b054
commit 04178517bc
3 changed files with 8 additions and 6 deletions

View File

@@ -167,3 +167,8 @@ class UnsupportedVersion(Exception):
class CommandError(Exception):
pass
class NeutronClientNoUniqueMatch(NeutronClientException):
message = _("Multiple %(resource)s matches found for name '%(name)s',"
" use an ID to be more specific.")

View File

@@ -52,11 +52,8 @@ def _find_resourceid_by_name(client, resource, name):
collection = resource + "s"
info = data[collection]
if len(info) > 1:
msg = (_("Multiple %(resource)s matches found for name '%(name)s',"
" use an ID to be more specific.") %
{'resource': resource, 'name': name})
raise exceptions.NeutronClientException(
message=msg)
raise exceptions.NeutronClientNoUniqueMatch(resource=resource,
name=name)
elif len(info) == 0:
not_found_message = (_("Unable to find %(resource)s with name "
"'%(name)s'") %

View File

@@ -109,7 +109,7 @@ class CLITestNameorID(testtools.TestCase):
try:
neutronV20.find_resourceid_by_name_or_id(
self.client, 'network', name)
except exceptions.NeutronClientException as ex:
except exceptions.NeutronClientNoUniqueMatch as ex:
self.assertTrue('Multiple' in ex.message)
def test_get_id_from_name_notfound(self):