diff --git a/neutronclient/common/exceptions.py b/neutronclient/common/exceptions.py index e02be309c..c62d25335 100644 --- a/neutronclient/common/exceptions.py +++ b/neutronclient/common/exceptions.py @@ -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.") diff --git a/neutronclient/neutron/v2_0/__init__.py b/neutronclient/neutron/v2_0/__init__.py index 57271a79e..8c0944e5d 100644 --- a/neutronclient/neutron/v2_0/__init__.py +++ b/neutronclient/neutron/v2_0/__init__.py @@ -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'") % diff --git a/tests/unit/test_name_or_id.py b/tests/unit/test_name_or_id.py index 09de0add3..b93cd13c0 100644 --- a/tests/unit/test_name_or_id.py +++ b/tests/unit/test_name_or_id.py @@ -109,7 +109,7 @@ def test_get_id_from_name_multiple(self): 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):