diff options
| author | Jenkins <jenkins@review.openstack.org> | 2015-05-26 18:20:16 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2015-05-26 18:20:16 +0000 |
| commit | d80c70e58abdc4260600ceadc81a49802d7878d6 (patch) | |
| tree | 551bbc55c296c84b40062e034c4126c5ad1d3892 /glanceclient/shell.py | |
| parent | 7ab349097852f2fa3b1543b3b1f94e2a28b09bd6 (diff) | |
| parent | 1f89beb6098f4f6a8d8c2912392b273bc068b2e3 (diff) | |
| download | python-glanceclient-d80c70e58abdc4260600ceadc81a49802d7878d6.tar.gz | |
Merge "Improve import related error handling"
Diffstat (limited to 'glanceclient/shell.py')
| -rw-r--r-- | glanceclient/shell.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 6ffd53d..8cd2c2d 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -47,6 +47,8 @@ from keystoneclient import session osprofiler_profiler = importutils.try_import("osprofiler.profiler") _ = _i18n._ +SUPPORTED_VERSIONS = [1, 2] + class OpenStackImagesShell(object): @@ -291,12 +293,7 @@ class OpenStackImagesShell(object): self.subcommands = {} subparsers = parser.add_subparsers(metavar='<subcommand>') - 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() + submodule = utils.import_versioned_module(version, 'shell') self._find_actions(subparsers, submodule) self._find_actions(subparsers, self) @@ -610,14 +607,32 @@ class OpenStackImagesShell(object): # build available subcommands based on version try: api_version = int(options.os_image_api_version or url_version or 1) + if api_version not in SUPPORTED_VERSIONS: + raise ValueError except ValueError: - print("Invalid API version parameter") - utils.exit() + msg = ("Invalid API version parameter. " + "Supported values are %s" % SUPPORTED_VERSIONS) + utils.exit(msg=msg) if api_version == 2: self._cache_schemas(options) - subcommand_parser = self.get_subcommand_parser(api_version) + try: + subcommand_parser = self.get_subcommand_parser(api_version) + except ImportError as e: + if options.debug: + traceback.print_exc() + if not str(e): + # Add a generic import error message if the raised ImportError + # has none. + raise ImportError('Unable to import module. Re-run ' + 'with --debug for more info.') + raise + except Exception: + if options.debug: + traceback.print_exc() + raise + self.parser = subcommand_parser # Handle top-level --help/-h before attempting to parse |
