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
This commit is contained in:
Bo Wang 2016-01-15 01:55:52 +08:00
parent a31c1c71f7
commit a4029e4d05
4 changed files with 6 additions and 5 deletions

View File

@ -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)

View File

@ -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

View File

@ -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:

View File

@ -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):