From 951f166210d23bd854e8495d7f56cad367ffaaf2 Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Sat, 12 Mar 2016 10:58:28 +0800 Subject: [PATCH] Fix dict.keys() compatibility for python 3 In Python 2, dict.keys() will return a list. But in Python 3, it will return an iterator. So we need to fix all the places that assuming dict.keys() is a list. Change-Id: I8d1cc536377b3e5c644cfaa0892e40d0bd7c11b1 Closes-Bug: #1556350 --- openstackclient/common/commandmanager.py | 2 +- openstackclient/common/exceptions.py | 2 +- openstackclient/common/utils.py | 2 +- openstackclient/shell.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openstackclient/common/commandmanager.py b/openstackclient/common/commandmanager.py index b809d63..c190e33 100644 --- a/openstackclient/common/commandmanager.py +++ b/openstackclient/common/commandmanager.py @@ -56,4 +56,4 @@ class CommandManager(cliff.commandmanager.CommandManager): ) group_list.append(cmd_name) return group_list - return self.commands.keys() + return list(self.commands.keys()) diff --git a/openstackclient/common/exceptions.py b/openstackclient/common/exceptions.py index 5f5f5ab..ee0f7a1 100644 --- a/openstackclient/common/exceptions.py +++ b/openstackclient/common/exceptions.py @@ -122,7 +122,7 @@ def from_response(response, body): cls = _code_map.get(response.status, ClientException) if body: if hasattr(body, 'keys'): - error = body[body.keys()[0]] + error = body[list(body.keys())[0]] message = error.get('message') details = error.get('details') else: diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 840da40..c6ed6a7 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -281,7 +281,7 @@ def get_client_class(api_name, version, version_map): client_path = version_map[str(version)] except (KeyError, ValueError): msg = "Invalid %s client version '%s'. must be one of: %s" % ( - (api_name, version, ', '.join(version_map.keys()))) + (api_name, version, ', '.join(list(version_map.keys())))) raise exceptions.UnsupportedVersion(msg) return importutils.import_class(client_path) diff --git a/openstackclient/shell.py b/openstackclient/shell.py index 53e9be0..7750f2a 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -355,7 +355,7 @@ class OpenStackShell(app.App): self.log.warning( "%s version %s is not in supported versions %s" % (api, version_opt, - ', '.join(mod.API_VERSIONS.keys()))) + ', '.join(list(mod.API_VERSIONS.keys())))) # Command groups deal only with major versions version = '.v' + version_opt.replace('.', '_').split('_')[0]