Replace iter methods with python3 compatable calls
Replace iteritems with items Replace iterkeys with keys Replace itervalues with values Special Note: In Python 2 those are copies of the elements. In Python3 those are references to the dictionary elements. The openstack python2to3 documents suggests wrapping the calls with a list if the dict is expected to change while iterating. nfv_scenario_tests (non guest) all pass. Story: 2004241 Task: 28070 Change-Id: Iddb69b83f0be2f8ec240f7708d2c6d0dc675848c Signed-off-by: Al Bailey <Al.Bailey@windriver.com>
This commit is contained in:
parent
ac6339b3c3
commit
735d9b3392
@ -55,33 +55,33 @@ class AlarmHandlers(stevedore.enabled.EnabledExtensionManager):
|
||||
"""
|
||||
Raise an alarm using the handlers
|
||||
"""
|
||||
for handler_type, handler in self._handlers.iteritems():
|
||||
for handler_type, handler in self._handlers.items():
|
||||
handler.obj.raise_alarm(alarm_uuid, alarm_data)
|
||||
|
||||
def clear_alarm(self, alarm_uuid):
|
||||
"""
|
||||
Clear an alarm using the handlers
|
||||
"""
|
||||
for handler_type, handler in self._handlers.iteritems():
|
||||
for handler_type, handler in self._handlers.items():
|
||||
handler.obj.clear_alarm(alarm_uuid)
|
||||
|
||||
def audit_alarms(self):
|
||||
"""
|
||||
Audit alarms using the handlers
|
||||
"""
|
||||
for handler_type, handler in self._handlers.iteritems():
|
||||
for handler_type, handler in self._handlers.items():
|
||||
handler.obj.audit_alarms()
|
||||
|
||||
def initialize(self, config_file):
|
||||
"""
|
||||
Initialize handlers
|
||||
"""
|
||||
for handler_id, handler in self._handlers.iteritems():
|
||||
for handler_id, handler in self._handlers.items():
|
||||
handler.obj.initialize(config_file)
|
||||
|
||||
def finalize(self):
|
||||
"""
|
||||
Finalize handlers
|
||||
"""
|
||||
for handler_id, handler in self._handlers.iteritems():
|
||||
for handler_id, handler in self._handlers.items():
|
||||
handler.obj.finalize()
|
||||
|
@ -55,19 +55,19 @@ class EventLogHandlers(stevedore.enabled.EnabledExtensionManager):
|
||||
"""
|
||||
Log a particular event using the handlers
|
||||
"""
|
||||
for handler_type, handler in self._handlers.iteritems():
|
||||
for handler_type, handler in self._handlers.items():
|
||||
handler.obj.log(log_data)
|
||||
|
||||
def initialize(self, config_file):
|
||||
"""
|
||||
Initialize handlers
|
||||
"""
|
||||
for handler_id, handler in self._handlers.iteritems():
|
||||
for handler_id, handler in self._handlers.items():
|
||||
handler.obj.initialize(config_file)
|
||||
|
||||
def finalize(self):
|
||||
"""
|
||||
Finalize handlers
|
||||
"""
|
||||
for handler_id, handler in self._handlers.iteritems():
|
||||
for handler_id, handler in self._handlers.items():
|
||||
handler.obj.finalize()
|
||||
|
@ -166,7 +166,7 @@ def reset_histogram_data(name=None):
|
||||
Reset histogram data
|
||||
"""
|
||||
if name is None:
|
||||
for histogram in _histograms.itervalues():
|
||||
for histogram in _histograms.values():
|
||||
histogram.reset_data()
|
||||
else:
|
||||
histogram = _find_histogram(name)
|
||||
@ -179,7 +179,7 @@ def display_histogram_data(name=None, pretty_format=True):
|
||||
Display histogram data captured
|
||||
"""
|
||||
if name is None:
|
||||
for histogram in _histograms.itervalues():
|
||||
for histogram in _histograms.values():
|
||||
histogram.display_data(pretty_format)
|
||||
else:
|
||||
histogram = _find_histogram(name)
|
||||
|
@ -109,7 +109,7 @@ class TCPServer(object):
|
||||
Shutdown the TCP Server
|
||||
"""
|
||||
connections = self._client_connections.copy()
|
||||
for client_connection in connections.itervalues():
|
||||
for client_connection in connections.values():
|
||||
selobj.selobj_del_read_obj(client_connection.selobj)
|
||||
selobj.selobj_del_error_callback(client_connection.selobj)
|
||||
client_connection.close()
|
||||
|
@ -96,7 +96,7 @@ class RPCListener(threading.Thread):
|
||||
"""
|
||||
self._message_filters_lock.acquire()
|
||||
try:
|
||||
for msg_type, msg_filter in self._message_filters.iteritems():
|
||||
for msg_type, msg_filter in self._message_filters.items():
|
||||
msg_data = msg_filter(body)
|
||||
if msg_data is not None:
|
||||
msg = dict()
|
||||
|
@ -63,7 +63,7 @@ class Test(object):
|
||||
"""
|
||||
Clears the log files so that they are empty, expected to be overloaded
|
||||
"""
|
||||
for file_name in self.LOG_FILES.itervalues():
|
||||
for file_name in self.LOG_FILES.values():
|
||||
with open(file_name, 'w'):
|
||||
pass
|
||||
|
||||
|
@ -106,7 +106,7 @@ class TestHost(_test_base.Test):
|
||||
with open(self._output_dir + '/test_result', 'w') as f:
|
||||
f.write("success=%s, reason=%s\n" % (test_success, test_reason))
|
||||
|
||||
for log_name, log_file in self.LOG_FILES.iteritems():
|
||||
for log_name, log_file in self.LOG_FILES.items():
|
||||
shutil.copyfile(log_file, self._output_dir + '/' + log_name + '.log')
|
||||
|
||||
if self._host_data is not None:
|
||||
|
@ -104,7 +104,7 @@ class TestInstance(_test_base.Test):
|
||||
with open(self._output_dir + '/test_result', 'w') as f:
|
||||
f.write("success=%s, reason=%s\n" % (test_success, test_reason))
|
||||
|
||||
for log_name, log_file in self.LOG_FILES.iteritems():
|
||||
for log_name, log_file in self.LOG_FILES.items():
|
||||
shutil.copyfile(log_file, self._output_dir + '/' + log_name + '.log')
|
||||
|
||||
if self._instance_data is not None:
|
||||
|
@ -173,7 +173,7 @@ class TestInstance(testcase.NFVTestCase):
|
||||
Create an instance group
|
||||
"""
|
||||
member_uuids = []
|
||||
for instance_uuid, instance in self._instance_table.iteritems():
|
||||
for instance_uuid, instance in self._instance_table.items():
|
||||
if instance.name in members:
|
||||
member_uuids.append(instance_uuid)
|
||||
|
||||
@ -231,7 +231,7 @@ class TestInstance(testcase.NFVTestCase):
|
||||
Create a host group
|
||||
"""
|
||||
member_uuids = []
|
||||
for instance_uuid, instance in self._instance_table.iteritems():
|
||||
for instance_uuid, instance in self._instance_table.items():
|
||||
if instance.name in members:
|
||||
member_uuids.append(instance_uuid)
|
||||
|
||||
|
@ -251,7 +251,7 @@ class TestSwPatchStrategy(testcase.NFVTestCase):
|
||||
"""
|
||||
member_uuids = []
|
||||
|
||||
for instance_uuid, instance in self._instance_table.iteritems():
|
||||
for instance_uuid, instance in self._instance_table.items():
|
||||
if instance.name in members:
|
||||
member_uuids.append(instance_uuid)
|
||||
|
||||
@ -310,7 +310,7 @@ class TestSwPatchStrategy(testcase.NFVTestCase):
|
||||
"""
|
||||
member_uuids = []
|
||||
|
||||
for instance_uuid, instance in self._instance_table.iteritems():
|
||||
for instance_uuid, instance in self._instance_table.items():
|
||||
if instance.name in members:
|
||||
member_uuids.append(instance_uuid)
|
||||
|
||||
|
@ -228,7 +228,7 @@ class TestSwUpgradeStrategy(testcase.NFVTestCase):
|
||||
"""
|
||||
member_uuids = []
|
||||
|
||||
for instance_uuid, instance in self._instance_table.iteritems():
|
||||
for instance_uuid, instance in self._instance_table.items():
|
||||
if instance.name in members:
|
||||
member_uuids.append(instance_uuid)
|
||||
|
||||
@ -288,7 +288,7 @@ class TestSwUpgradeStrategy(testcase.NFVTestCase):
|
||||
"""
|
||||
member_uuids = []
|
||||
|
||||
for instance_uuid, instance in self._instance_table.iteritems():
|
||||
for instance_uuid, instance in self._instance_table.items():
|
||||
if instance.name in members:
|
||||
member_uuids.append(instance_uuid)
|
||||
|
||||
|
@ -25,7 +25,7 @@ def _audit_alarms():
|
||||
timer_id = (yield)
|
||||
DLOG.verbose("Audit alarms called, timer_id=%s." % timer_id)
|
||||
instance_table = tables.tables_get_instance_table()
|
||||
for instance in instance_table.itervalues():
|
||||
for instance in instance_table.values():
|
||||
if not instance.is_deleted():
|
||||
alarm.instance_manage_alarms(instance)
|
||||
|
||||
|
@ -1832,7 +1832,7 @@ class InstanceDirector(object):
|
||||
instance_table = tables.tables_get_instance_table()
|
||||
instance_uuids = list()
|
||||
|
||||
for instance in instance_table.itervalues():
|
||||
for instance in instance_table.values():
|
||||
if instance.unlock_to_recover and instance.is_locked():
|
||||
instance_uuids.append(instance.uuid)
|
||||
instance.unlock_to_recover = False
|
||||
@ -1931,7 +1931,7 @@ class InstanceDirector(object):
|
||||
host_operation = Operation(OPERATION_TYPE.MIGRATE_INSTANCES)
|
||||
host_operations[instance.host_name] = host_operation
|
||||
|
||||
for host_name, host_operation in host_operations.iteritems():
|
||||
for host_name, host_operation in host_operations.items():
|
||||
self._host_operations[host_name] = host_operation
|
||||
self._host_migrate_instances(host_table[host_name], host_operation)
|
||||
if host_operation.is_inprogress():
|
||||
@ -1993,7 +1993,7 @@ class InstanceDirector(object):
|
||||
host_operation = Operation(OPERATION_TYPE.STOP_INSTANCES)
|
||||
host_operations[instance.host_name] = host_operation
|
||||
|
||||
for host_name, host_operation in host_operations.iteritems():
|
||||
for host_name, host_operation in host_operations.items():
|
||||
self._host_operations[host_name] = host_operation
|
||||
self._host_stop_instances(host_table[host_name], host_operation,
|
||||
instance_uuids)
|
||||
@ -2061,7 +2061,7 @@ class InstanceDirector(object):
|
||||
host_operation = Operation(operation_type)
|
||||
host_operations[instance.host_name] = host_operation
|
||||
|
||||
for host_name, host_operation in host_operations.iteritems():
|
||||
for host_name, host_operation in host_operations.items():
|
||||
self._host_operations[host_name] = host_operation
|
||||
self._host_start_instances(host_table[host_name], host_operation,
|
||||
instance_uuids)
|
||||
|
@ -182,7 +182,7 @@ def vim_image_api_get_images(connection, msg):
|
||||
"""
|
||||
DLOG.verbose("Get image, all=%s." % msg.get_all)
|
||||
image_table = tables.tables_get_image_table()
|
||||
for image in image_table.itervalues():
|
||||
for image in image_table.values():
|
||||
response = rpc.APIResponseGetImage()
|
||||
response.uuid = image.uuid
|
||||
response.name = image.name
|
||||
|
@ -334,7 +334,7 @@ def vim_instance_api_get_instances(connection, msg):
|
||||
"""
|
||||
DLOG.verbose("Get instance, all=%s." % msg.get_all)
|
||||
instance_table = tables.tables_get_instance_table()
|
||||
for instance in instance_table.itervalues():
|
||||
for instance in instance_table.values():
|
||||
response = rpc.APIResponseGetInstance()
|
||||
response.uuid = instance.uuid
|
||||
response.name = instance.name
|
||||
|
@ -503,7 +503,7 @@ def vim_network_api_get_networks(connection, msg):
|
||||
"""
|
||||
DLOG.verbose("Get network, all=%s." % msg.get_all)
|
||||
network_table = tables.tables_get_network_table()
|
||||
for network in network_table.itervalues():
|
||||
for network in network_table.values():
|
||||
response = rpc.APIResponseGetNetwork()
|
||||
response.uuid = network.uuid
|
||||
response.name = network.name
|
||||
|
@ -162,7 +162,7 @@ def vim_volume_api_get_volumes(connection, msg):
|
||||
"""
|
||||
DLOG.verbose("Get volume, all=%s." % msg.get_all)
|
||||
volume_table = tables.tables_get_volume_table()
|
||||
for volume in volume_table.itervalues():
|
||||
for volume in volume_table.values():
|
||||
response = rpc.APIResponseGetVolume()
|
||||
response.uuid = volume.uuid
|
||||
response.name = volume.name
|
||||
|
@ -102,5 +102,5 @@ def nfvi_finalize():
|
||||
nfvi_guest_finalize()
|
||||
nfvi_sw_mgmt_finalize()
|
||||
|
||||
for pool in _task_worker_pools.itervalues():
|
||||
for pool in _task_worker_pools.values():
|
||||
pool.shutdown()
|
||||
|
@ -18,7 +18,7 @@ class ObjectData(collections.MutableMapping):
|
||||
super(ObjectData, self).__setattr__('_fields', dict())
|
||||
|
||||
if data is not None:
|
||||
for key, value in data.iteritems():
|
||||
for key, value in data.items():
|
||||
self._do_set(key, value)
|
||||
|
||||
@property
|
||||
|
@ -18,7 +18,7 @@ class ObjectData(collections.MutableMapping):
|
||||
super(ObjectData, self).__setattr__('_fields', dict())
|
||||
|
||||
if data is not None:
|
||||
for key, value in data.iteritems():
|
||||
for key, value in data.items():
|
||||
self._do_set(key, value)
|
||||
|
||||
@property
|
||||
|
@ -254,7 +254,7 @@ class SwUpdateStrategy(strategy.Strategy):
|
||||
# service disruption when the remaining instances are stopped or
|
||||
# migrated.
|
||||
if reboot:
|
||||
for instance in instance_table.itervalues():
|
||||
for instance in instance_table.values():
|
||||
if instance.is_locked():
|
||||
for instance_group in instance_group_table.get_by_instance(
|
||||
instance.uuid):
|
||||
@ -866,7 +866,7 @@ class SwPatchStrategy(SwUpdateStrategy):
|
||||
self.save()
|
||||
return
|
||||
|
||||
for host in host_table.itervalues():
|
||||
for host in host_table.values():
|
||||
if HOST_PERSONALITY.COMPUTE in host.personality and \
|
||||
HOST_PERSONALITY.CONTROLLER not in host.personality:
|
||||
# Allow patch orchestration when compute hosts are available,
|
||||
@ -1465,7 +1465,7 @@ class SwUpgradeStrategy(SwUpdateStrategy):
|
||||
return
|
||||
|
||||
host_table = tables.tables_get_host_table()
|
||||
for host in host_table.itervalues():
|
||||
for host in host_table.values():
|
||||
# Only allow upgrade orchestration when all hosts are
|
||||
# available. It is not safe to automate upgrade application
|
||||
# when we do not have full redundancy.
|
||||
@ -1494,7 +1494,7 @@ class SwUpgradeStrategy(SwUpdateStrategy):
|
||||
self._add_upgrade_start_stage()
|
||||
|
||||
# All hosts will be upgraded
|
||||
for host in host_table.itervalues():
|
||||
for host in host_table.values():
|
||||
if HOST_PERSONALITY.CONTROLLER in host.personality:
|
||||
controller_hosts.append(host)
|
||||
|
||||
@ -1506,7 +1506,7 @@ class SwUpgradeStrategy(SwUpdateStrategy):
|
||||
else:
|
||||
# Only hosts not yet upgraded will be upgraded
|
||||
to_load = self.nfvi_upgrade.to_release
|
||||
for host in host_table.itervalues():
|
||||
for host in host_table.values():
|
||||
if host.software_load == to_load:
|
||||
# No need to upgrade this host
|
||||
continue
|
||||
|
@ -1072,7 +1072,7 @@ class MigrateInstancesStep(strategy.StrategyStep):
|
||||
Returns true if all instances have migrated from the source hosts
|
||||
"""
|
||||
source_host_names = []
|
||||
for host_name in self._instance_host_names.itervalues():
|
||||
for host_name in self._instance_host_names.values():
|
||||
if host_name not in source_host_names:
|
||||
source_host_names.append(host_name)
|
||||
|
||||
|
@ -18,7 +18,7 @@ class HypervisorTable(Table):
|
||||
super(HypervisorTable, self).__init__()
|
||||
|
||||
def get_by_host_name(self, host_name, default=None):
|
||||
for hypervisor in self._entries.itervalues():
|
||||
for hypervisor in self._entries.values():
|
||||
if hypervisor.host_name == host_name:
|
||||
return hypervisor
|
||||
return default
|
||||
|
@ -18,12 +18,12 @@ class InstanceTable(Table):
|
||||
super(InstanceTable, self).__init__()
|
||||
|
||||
def on_host(self, host_name):
|
||||
for instance in self._entries.itervalues():
|
||||
for instance in self._entries.values():
|
||||
if instance.on_host(host_name):
|
||||
yield instance
|
||||
|
||||
def exist_on_host(self, host_name):
|
||||
for instance in self._entries.itervalues():
|
||||
for instance in self._entries.values():
|
||||
if instance.on_host(host_name):
|
||||
return True
|
||||
return False
|
||||
|
@ -33,7 +33,7 @@ class SubnetTable(Table):
|
||||
return None
|
||||
|
||||
def on_network(self, network_uuid):
|
||||
for subnet in self._entries.itervalues():
|
||||
for subnet in self._entries.values():
|
||||
if network_uuid == subnet.network_uuid:
|
||||
yield subnet
|
||||
|
||||
|
@ -76,11 +76,10 @@ verbosity=2
|
||||
# F821 undefined name 'unicode' (python3 specific)
|
||||
# - bugbear codes -
|
||||
# B007 Loop control variable 'X' not used within the loop body. If this is intended, start the name with an underscore.
|
||||
# B301 Python 3 does not include `.iter*` methods on dictionaries.
|
||||
ignore = E121,E122,E123,E124,E126,E127,E128,E129,E501,
|
||||
H104,H306,H401,H404,H405,H501,
|
||||
F821,
|
||||
B007, B301
|
||||
B007
|
||||
# H106 Don’t put vim configuration in source files (off by default).
|
||||
# H203 Use assertIs(Not)None to check for None (off by default).
|
||||
# TODO: enable: H904 Delay string interpolations at logging calls (off by default).
|
||||
|
Loading…
x
Reference in New Issue
Block a user