python3: Refactor dict for python2/python3 compat

Python3 changed the behavior of dict.keys and dict.values such that
it is now returns a dict_keys object, which is iterable but not
indexable. You can get the python2 result back with an explicit
call to list.

Story: 2006796
Task: 42671

Signed-off-by: Charles Short <charles.short@windriver.com>
Change-Id: I97c9b3c40b997da4ce514742af85bcb73bfe7ee0
(cherry picked from commit 033d32f983)
This commit is contained in:
Charles Short 2021-06-22 13:19:48 -04:00
parent 81fee1c449
commit a0645a4e09
40 changed files with 43 additions and 43 deletions

View File

@ -215,7 +215,7 @@ class NodeOperator(object):
icpu_attrs = {} icpu_attrs = {}
continue continue
self.num_nodes = len(self.topology.keys()) self.num_nodes = len(list(self.topology.keys()))
# In the case topology not detected, hard-code structures # In the case topology not detected, hard-code structures
if self.num_nodes == 0: if self.num_nodes == 0:
@ -265,7 +265,7 @@ class NodeOperator(object):
} }
icpus.append(attrs) icpus.append(attrs)
cpu += 1 cpu += 1
self.num_nodes = len(self.topology.keys()) self.num_nodes = len(list(self.topology.keys()))
LOG.debug("inumas= %s, icpus = %s" % (inumas, icpus)) LOG.debug("inumas= %s, icpus = %s" % (inumas, icpus))

View File

@ -151,7 +151,7 @@ class AddressPool(base.APIBase):
"List of start-end pairs of IP address" "List of start-end pairs of IP address"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.address_pool.fields.keys() self.fields = list(objects.address_pool.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
# Skip fields that we choose to hide # Skip fields that we choose to hide

View File

@ -114,7 +114,7 @@ class Cluster(base.APIBase):
"Links to the collection of storage tiers on this cluster" "Links to the collection of storage tiers on this cluster"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.cluster.fields.keys() self.fields = list(objects.cluster.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
# Skip fields that we choose to hide # Skip fields that we choose to hide

View File

@ -97,7 +97,7 @@ class DataNetwork(base.APIBase):
"Mode for this datanetwork. VxLan only" "Mode for this datanetwork. VxLan only"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.datanetwork.fields.keys() self.fields = list(objects.datanetwork.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -119,7 +119,7 @@ class Disk(base.APIBase):
"applicable for SSDs." "applicable for SSDs."
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.disk.fields.keys() self.fields = list(objects.disk.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -70,7 +70,7 @@ class InterfaceDataNetwork(base.APIBase):
"Represents the type for the datanetwork" "Represents the type for the datanetwork"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.interface_datanetwork.fields.keys() self.fields = list(objects.interface_datanetwork.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -85,7 +85,7 @@ class InterfaceNetwork(base.APIBase):
"Represents the type for the network" "Represents the type for the network"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.interface_network.fields.keys() self.fields = list(objects.interface_network.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -69,7 +69,7 @@ class KubeApp(base.APIBase):
"Represents the application is active" "Represents the application is active"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.kube_app.fields.keys() self.fields = list(objects.kube_app.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -62,7 +62,7 @@ class KubeUpgrade(base.APIBase):
"A list containing a self link and associated kubernetes upgrade links" "A list containing a self link and associated kubernetes upgrade links"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.kube_upgrade.fields.keys() self.fields = list(objects.kube_upgrade.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -41,7 +41,7 @@ class KubeVersion(base.APIBase):
"State of this version" "State of this version"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.kube_version.fields.keys() self.fields = list(objects.kube_version.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -61,7 +61,7 @@ class Label(base.APIBase):
"The uuid of the host this label belongs to" "The uuid of the host this label belongs to"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.label.fields.keys() self.fields = list(objects.label.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -123,7 +123,7 @@ class LLDPAgent(base.APIBase):
"Represent the 802.3 maximum frame size of the lldp agent" "Represent the 802.3 maximum frame size of the lldp agent"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.lldp_agent.fields.keys() self.fields = list(objects.lldp_agent.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -142,7 +142,7 @@ class LLDPNeighbour(base.APIBase):
"Represent the neighbour time-to-live" "Represent the neighbour time-to-live"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.lldp_neighbour.fields.keys() self.fields = list(objects.lldp_neighbour.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -76,7 +76,7 @@ class LLDPTLV(base.APIBase):
"Represent a list containing a self link and associated lldp tlv links" "Represent a list containing a self link and associated lldp tlv links"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.lldp_tlv.fields.keys() self.fields = list(objects.lldp_tlv.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -92,7 +92,7 @@ class Load(base.APIBase):
"A list of the patches required to upgrade to this load" "A list of the patches required to upgrade to this load"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.load.fields.keys() self.fields = list(objects.load.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -82,7 +82,7 @@ class Network(base.APIBase):
"The UUID of the address pool associated with the network" "The UUID of the address pool associated with the network"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.network.fields.keys() self.fields = list(objects.network.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -89,7 +89,7 @@ class Node(base.APIBase):
"Links to the collection of ports on this node" "Links to the collection of ports on this node"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.node.fields.keys() self.fields = list(objects.node.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -90,7 +90,7 @@ class Partition(base.APIBase):
"This partition's meta data" "This partition's meta data"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.partition.fields.keys() self.fields = list(objects.partition.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -133,7 +133,7 @@ class PCIDevice(base.APIBase):
"Represent a list containing a self link and associated device links" "Represent a list containing a self link and associated device links"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.pci_device.fields.keys() self.fields = list(objects.pci_device.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -139,7 +139,7 @@ class Port(base.APIBase):
"Links to the collection of LldpNeighbours on this port" "Links to the collection of LldpNeighbours on this port"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.port.fields.keys() self.fields = list(objects.port.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -1733,7 +1733,7 @@ def _create_storage_profile(profile_name, profile_node):
sdict['journal_location'] = location_uuid sdict['journal_location'] = location_uuid
else: else:
# get the first journal # get the first journal
journal = journals[journals.keys()[0]] journal = journals[list(journals.keys())[0]]
sdict['journal_location'] = journal sdict['journal_location'] = journal
else: else:
# journal is collocated # journal is collocated

View File

@ -65,7 +65,7 @@ class PTP(base.APIBase):
updated_at = wtypes.datetime.datetime updated_at = wtypes.datetime.datetime
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.ptp.fields.keys() self.fields = list(objects.ptp.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -123,7 +123,7 @@ class PV(base.APIBase):
"Links to the collection of partitions on this pv" "Links to the collection of partitions on this pv"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.pv.fields.keys() self.fields = list(objects.pv.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -85,7 +85,7 @@ class Route(base.APIBase):
"The ID of the host this interface belongs to" "The ID of the host this interface belongs to"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.route.fields.keys() self.fields = list(objects.route.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
# Skip fields that we choose to hide # Skip fields that we choose to hide

View File

@ -107,7 +107,7 @@ class SDNController(base.APIBase):
"A list containing a self link and associated SDN controller links" "A list containing a self link and associated SDN controller links"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.sdn_controller.fields.keys() self.fields = list(objects.sdn_controller.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -149,7 +149,7 @@ class Sensor(base.APIBase):
"Represent a list containing a self link and associated isensor links" "Represent a list containing a self link and associated isensor links"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.sensor.fields.keys() self.fields = list(objects.sensor.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -82,7 +82,7 @@ class Service(base.APIBase):
"Service capabilities" "Service capabilities"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.service.fields.keys() self.fields = list(objects.service.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -79,7 +79,7 @@ class ServiceParameter(base.APIBase):
"A list containing a self link and associated links" "A list containing a self link and associated links"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.service_parameter.fields.keys() self.fields = list(objects.service_parameter.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -914,7 +914,7 @@ def _capabilities_semantic_checks(caps_dict):
# Raise exception if unsupported capabilities are passed # Raise exception if unsupported capabilities are passed
invalid_data = set(caps_dict.keys()) - set(valid_data.keys()) invalid_data = set(caps_dict.keys()) - set(valid_data.keys())
if valid_data.keys() != caps_dict.keys(): if list(valid_data.keys()) != list(caps_dict.keys()):
# Build short customer message to help with supported capabilities # Build short customer message to help with supported capabilities
# he can then search for them in the manual. # he can then search for them in the manual.
params = " backend: %s\n" % ", ".join(CAPABILITIES['backend']) params = " backend: %s\n" % ", ".join(CAPABILITIES['backend'])

View File

@ -100,7 +100,7 @@ class StorageTier(base.APIBase):
"Links to the collection of OSDs on this storage tier" "Links to the collection of OSDs on this storage tier"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.storage_tier.fields.keys() self.fields = list(objects.storage_tier.fields.keys())
for k in self.fields: for k in self.fields:
setattr(self, k, kwargs.get(k)) setattr(self, k, kwargs.get(k))

View File

@ -113,7 +113,7 @@ class System(base.APIBase):
"Kernel arguments associated with exnabled spectre/meltdown fix features" "Kernel arguments associated with exnabled spectre/meltdown fix features"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.system.fields.keys() self.fields = list(objects.system.fields.keys())
for k in self.fields: for k in self.fields:
# Translate any special internal representation of data to its # Translate any special internal representation of data to its

View File

@ -73,7 +73,7 @@ class Upgrade(base.APIBase):
"The load version that software upgrading to" "The load version that software upgrading to"
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.fields = objects.software_upgrade.fields.keys() self.fields = list(objects.software_upgrade.fields.keys())
for k in self.fields: for k in self.fields:
if not hasattr(self, k): if not hasattr(self, k):
continue continue

View File

@ -540,7 +540,7 @@ def get_subclouds():
""" """
subcloud_secrets = get_subcloud_secrets() subcloud_secrets = get_subcloud_secrets()
return subcloud_secrets.keys() return list(subcloud_secrets.keys())
def get_intermediate_ca_secret_name(sc): def get_intermediate_ca_secret_name(sc):

View File

@ -552,7 +552,7 @@ class RootCARenew(CertificateRenew):
@staticmethod @staticmethod
def get_secrets_to_recreate(): def get_secrets_to_recreate():
secret_names = utils.get_subcloud_secrets().values() secret_names = list(utils.get_subcloud_secrets().values())
secret_names.insert(0, constants.DC_ADMIN_ENDPOINT_SECRET_NAME) secret_names.insert(0, constants.DC_ADMIN_ENDPOINT_SECRET_NAME)
return secret_names return secret_names

View File

@ -222,7 +222,7 @@ def create_host_overrides(filename):
sys.exit(1) sys.exit(1)
VALID_NOTIFICATION_VALUES = constants.HOOK_PARAMETERS_MAP.keys() VALID_NOTIFICATION_VALUES = list(constants.HOOK_PARAMETERS_MAP.keys())
NOTIFICATION_ACTION_SUCCESS_VALUES = {'success': True, NOTIFICATION_ACTION_SUCCESS_VALUES = {'success': True,
'failure': False} 'failure': False}
@ -260,7 +260,7 @@ def add_action_parsers(subparsers):
parser.set_defaults(func=send_notification) parser.set_defaults(func=send_notification)
parser.add_argument('operation') parser.add_argument('operation')
parser.add_argument('success', parser.add_argument('success',
choices=NOTIFICATION_ACTION_SUCCESS_VALUES.keys(), choices=list(NOTIFICATION_ACTION_SUCCESS_VALUES.keys()),
default='success', default='success',
nargs='?') nargs='?')

View File

@ -613,7 +613,7 @@ FILESYSTEM_HOSTS_SUPPORTED_LIST_DICT = {
STORAGE: FILESYSTEM_STORAGE_SUPPORTED_LIST, STORAGE: FILESYSTEM_STORAGE_SUPPORTED_LIST,
} }
SUPPORTED_LOGICAL_VOLUME_LIST = FILESYSTEM_LV_DICT.values() SUPPORTED_LOGICAL_VOLUME_LIST = list(FILESYSTEM_LV_DICT.values())
SUPPORTED_REPLICATED_FILEYSTEM_LIST = [ SUPPORTED_REPLICATED_FILEYSTEM_LIST = [
FILESYSTEM_NAME_PLATFORM, FILESYSTEM_NAME_PLATFORM,

View File

@ -12866,7 +12866,7 @@ class ConductorManager(service.PeriodicService):
self._log_applications_not_reverted(constants.BACKUP_ACTION_PRE_ETCD_BACKUP) self._log_applications_not_reverted(constants.BACKUP_ACTION_PRE_ETCD_BACKUP)
self._log_applications_not_reverted(constants.BACKUP_ACTION_PRE_BACKUP) self._log_applications_not_reverted(constants.BACKUP_ACTION_PRE_BACKUP)
actions_list = self._backup_action_map.keys() actions_list = list(self._backup_action_map.keys())
self._backup_actions_log = dict(zip(actions_list, [OrderedDict()] * len(actions_list))) self._backup_actions_log = dict(zip(actions_list, [OrderedDict()] * len(actions_list)))
def _revert_backup_operation(self, operation): def _revert_backup_operation(self, operation):

View File

@ -306,8 +306,8 @@ class BaseHelm(object):
elif name_filter: elif name_filter:
monitors = self._get_filtered_ceph_monitor_ips_using_function(name_filter) monitors = self._get_filtered_ceph_monitor_ips_using_function(name_filter)
else: else:
monitors = StorageBackendConfig.get_ceph_mon_ip_addresses( monitors = list(StorageBackendConfig.get_ceph_mon_ip_addresses(
self.dbapi).values() self.dbapi).values())
return monitors return monitors
def _get_formatted_ceph_monitor_ips(self, name_filter=None): def _get_formatted_ceph_monitor_ips(self, name_filter=None):

View File

@ -154,7 +154,7 @@ def _get_drivers():
for notification_driver in CONF.notification_driver: for notification_driver in CONF.notification_driver:
add_driver(notification_driver) add_driver(notification_driver)
return _drivers.values() return list(_drivers.values())
def add_driver(notification_driver): def add_driver(notification_driver):

View File

@ -244,7 +244,7 @@ def get_cmdclass():
for pkg in self.distribution.packages: for pkg in self.distribution.packages:
if '.' not in pkg: if '.' not in pkg:
os.path.walk(pkg, _find_modules, modules) os.path.walk(pkg, _find_modules, modules)
module_list = modules.keys() module_list = list(modules.keys())
module_list.sort() module_list.sort()
autoindex_filename = os.path.join(source_dir, 'autoindex.rst') autoindex_filename = os.path.join(source_dir, 'autoindex.rst')
with open(autoindex_filename, 'w') as autoindex: with open(autoindex_filename, 'w') as autoindex: