From 4900c64d091ffe4ec9050cd71845b12db49bd293 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Mon, 17 Mar 2014 17:32:41 -0600 Subject: Produce a useful error message for NoUniqueMatch Most of the CLIs use a NoUniqueMatch, so produce a useful error message if that happens. Added some tests for find_resource as well. Change-Id: I85ba61d5f6d1be5bd336a1cc4b02501492905f33 Closes-Bug: #1293846 --- openstackclient/common/utils.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'openstackclient/common/utils.py') diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 7cd877ef..d7702a3f 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -74,6 +74,10 @@ def find_resource(manager, name_or_id): msg = "No %s with a name or ID of '%s' exists." % \ (manager.resource_class.__name__.lower(), name_or_id) raise exceptions.CommandError(msg) + if type(ex).__name__ == 'NoUniqueMatch': + msg = "More than one %s exists with the name '%s'." % \ + (manager.resource_class.__name__.lower(), name_or_id) + raise exceptions.CommandError(msg) else: raise -- cgit v1.2.1