summaryrefslogtreecommitdiff
path: root/openstackclient/identity
diff options
context:
space:
mode:
authorsunyajing <yajing.sun@easystack.cn>2016-06-24 12:40:29 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-07-22 19:40:50 +0800
commitc45b1d7b230e900d0416a4953607e5d4e1dc9cfd (patch)
tree8fd33e08f4da491210710bc53a876673b08fa12f /openstackclient/identity
parent60639d76a742852e18f9e2889c480be95596c268 (diff)
downloadpython-openstackclient-c45b1d7b230e900d0416a4953607e5d4e1dc9cfd.tar.gz
Fix error for find_service() in identity
if there are more than one services be found with one name, a NoUniqueMatch exception should be raised but we can see a NotFound Exception raised instead. It is because in "find_service()", we use "find_resource()" first, if "find_resource()" return a exception, we just think it is a NotFound Exception and continue to find by type but ignore a NoUniqueMatch exception of "find_resource()". This patch refactor the "find_service()" method to solve this problem. Change-Id: Id4619092c57f276ae0698c89df0d5503b7423a4e Co-Authored-By: Huanxuan Ao <huanxuan.ao@easystack.cn> Closes-Bug:#1597296
Diffstat (limited to 'openstackclient/identity')
-rw-r--r--openstackclient/identity/common.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/openstackclient/identity/common.py b/openstackclient/identity/common.py
index 379f4114..1e40f396 100644
--- a/openstackclient/identity/common.py
+++ b/openstackclient/identity/common.py
@@ -30,21 +30,32 @@ def find_service(identity_client, name_type_or_id):
"""Find a service by id, name or type."""
try:
- # search for the usual ID or name
- return utils.find_resource(identity_client.services, name_type_or_id)
- except exceptions.CommandError:
- try:
- # search for service type
- return identity_client.services.find(type=name_type_or_id)
- # FIXME(dtroyer): This exception should eventually come from
- # common client exceptions
- except identity_exc.NotFound:
- msg = _("No service with a type, name or ID of '%s' exists.")
- raise exceptions.CommandError(msg % name_type_or_id)
- except identity_exc.NoUniqueMatch:
- msg = _("Multiple service matches found for '%s', "
- "use an ID to be more specific.")
- raise exceptions.CommandError(msg % name_type_or_id)
+ # search for service id
+ return identity_client.services.get(name_type_or_id)
+ except identity_exc.NotFound:
+ # ignore NotFound exception, raise others
+ pass
+
+ try:
+ # search for service name
+ return identity_client.services.find(name=name_type_or_id)
+ except identity_exc.NotFound:
+ pass
+ except identity_exc.NoUniqueMatch:
+ msg = _("Multiple service matches found for '%s', "
+ "use an ID to be more specific.")
+ raise exceptions.CommandError(msg % name_type_or_id)
+
+ try:
+ # search for service type
+ return identity_client.services.find(type=name_type_or_id)
+ except identity_exc.NotFound:
+ msg = _("No service with a type, name or ID of '%s' exists.")
+ raise exceptions.CommandError(msg % name_type_or_id)
+ except identity_exc.NoUniqueMatch:
+ msg = _("Multiple service matches found for '%s', "
+ "use an ID to be more specific.")
+ raise exceptions.CommandError(msg % name_type_or_id)
def _get_token_resource(client, resource, parsed_name):