From d5a0e657ed07a4a5ec503b80e71d1f136c79bb8e Mon Sep 17 00:00:00 2001 From: Louis Taylor Date: Tue, 25 Nov 2014 15:33:57 +0000 Subject: [PATCH] Add useful error on invalid --os-image-api-version This adds a useful error message when a user enters an invalid value for --os-image-api-version. Previously, the shell directly attempted to import the module the user specified, and printed the error from the exception raised when that failed: $ glance --os-image-api-version stupid-glance-version No module named vstupid-glance-version.shell Glanceclient now catches this exception and prints something understandable for a user: $ glance --os-image-api-version stupid-glance-version "stupid-glance-version" is not a supported API version. Example values are "1" or "2". Closes-Bug: #1395841 Change-Id: I48a95b7562c10bd68d777be408dcfa22cb05ec6a --- glanceclient/shell.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 80d2f9a..61ef19a 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -284,7 +284,13 @@ class OpenStackImagesShell(object): self.subcommands = {} subparsers = parser.add_subparsers(metavar='') - submodule = utils.import_versioned_module(version, 'shell') + try: + submodule = utils.import_versioned_module(version, 'shell') + except ImportError: + print('"%s" is not a supported API version. Example ' + 'values are "1" or "2".' % version) + utils.exit() + self._find_actions(subparsers, submodule) self._find_actions(subparsers, self)