From a4029e4d0581815b08beb4669a57636244924d4d Mon Sep 17 00:00:00 2001 From: Bo Wang Date: Fri, 15 Jan 2016 01:55:52 +0800 Subject: [PATCH] Python3: Fix using dictionary keys() It will throw TypeError when you try to operate on dict.keys() like a list in python3. ref:https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects Change-Id: I3f1173e74ddd589f3d363597bd1562299f92e93d --- sahara/plugins/cdh/client/types.py | 2 +- sahara/plugins/hdp/ambariplugin.py | 3 ++- sahara/utils/patches.py | 2 +- sahara/utils/ssh_remote.py | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sahara/plugins/cdh/client/types.py b/sahara/plugins/cdh/client/types.py index 75428350e3..6dd8bfa491 100644 --- a/sahara/plugins/cdh/client/types.py +++ b/sahara/plugins/cdh/client/types.py @@ -297,7 +297,7 @@ class BaseApiObject(object): Default implementation of __str__. Uses the type name and the first attribute retrieved from the attribute map to create the string. """ - name = self._get_attributes().keys()[0] + name = list(self._get_attributes().keys())[0] value = getattr(self, name, None) return "<%s>: %s = %s" % (self.__class__.__name__, name, value) diff --git a/sahara/plugins/hdp/ambariplugin.py b/sahara/plugins/hdp/ambariplugin.py index d7085f7938..4c89ac7872 100644 --- a/sahara/plugins/hdp/ambariplugin.py +++ b/sahara/plugins/hdp/ambariplugin.py @@ -385,7 +385,8 @@ class AmbariPlugin(p.ProvisioningPluginBase): # results in validation handler.get_cluster_spec( - cluster, [], dict(existing.items() + additional.items())) + cluster, [], + dict(list(existing.items()) + list(additional.items()))) def _get_num_hosts(self, cluster): count = 0 diff --git a/sahara/utils/patches.py b/sahara/utils/patches.py index c1b1d11eb5..756a46b7b1 100644 --- a/sahara/utils/patches.py +++ b/sahara/utils/patches.py @@ -79,7 +79,7 @@ def patch_minidom_writexml(): writer.write(indent + "<" + self.tagName) attrs = self._get_attributes() - a_names = attrs.keys() + a_names = list(attrs.keys()) a_names.sort() for a_name in a_names: diff --git a/sahara/utils/ssh_remote.py b/sahara/utils/ssh_remote.py index a5e6d8a2f0..0bdbdbe900 100644 --- a/sahara/utils/ssh_remote.py +++ b/sahara/utils/ssh_remote.py @@ -751,7 +751,7 @@ class InstanceInteropHelper(remote.Remote): self._run_s(_write_file_to, timeout, remote_file, data, run_as_root) def write_files_to(self, files, run_as_root=False, timeout=None): - self._log_command('Writing files "%s"' % files.keys()) + self._log_command('Writing files "%s"' % list(files.keys())) self._run_s(_write_files_to, timeout, files, run_as_root) def append_to_file(self, r_file, data, run_as_root=False, timeout=None): @@ -759,7 +759,7 @@ class InstanceInteropHelper(remote.Remote): self._run_s(_append_to_file, timeout, r_file, data, run_as_root) def append_to_files(self, files, run_as_root=False, timeout=None): - self._log_command('Appending to files "%s"' % files.keys()) + self._log_command('Appending to files "%s"' % list(files.keys())) self._run_s(_append_to_files, timeout, files, run_as_root) def read_file_from(self, remote_file, run_as_root=False, timeout=None):