Fix Python 3 dictionary incompatibilities

There were two instances of abusing old Python 2 behaviors around
dictionary keys that Python 3 no longer allows. These are both fixed.

Change-Id: I5865ee3becf52fca590a1c0c897bcd968210ac9d
This commit is contained in:
Nolan Brubaker 2017-06-06 21:26:27 -04:00 committed by Jesse Pretorius (odyssey4me)
parent ed7032f8be
commit fa5336ca36
2 changed files with 17 additions and 4 deletions

View File

@ -829,14 +829,22 @@ def _parse_global_variables(user_cidr, inventory, user_defined_config):
) )
logger.debug("Applied global_overrides") logger.debug("Applied global_overrides")
kept_vars = user_defined_config['global_overrides'].keys() # NOTE (palendae): wrapped in a list to support python3,
# which uses `dict_keys` objects that can't be appended
kept_vars = list(user_defined_config['global_overrides'].keys())
kept_vars.append('container_cidr') kept_vars.append('container_cidr')
# Remove global overrides that were deleted from inventory, too # Remove global overrides that were deleted from inventory, too
# We use the to_delete list due to Python 3 disallowing dict
# size mutation during iteration
to_delete = []
for key in inventory['all']['vars'].keys(): for key in inventory['all']['vars'].keys():
if key not in kept_vars: if key not in kept_vars:
logger.debug("Deleting key %s from inventory", key) to_delete.append(key)
del inventory['all']['vars'][key]
for key in to_delete:
logger.debug("Deleting key %s from inventory", key)
del inventory['all']['vars'][key]
def _check_same_ip_to_multiple_host(config): def _check_same_ip_to_multiple_host(config):

View File

@ -988,9 +988,14 @@ class TestOverridingEnvVars(OverridingEnvBase):
# a partial override file # a partial override file
vol = self.cinder_config['container_skel']['cinder_volumes_container'] vol = self.cinder_config['container_skel']['cinder_volumes_container']
keys = vol.keys()
to_delete = []
for key in vol.keys(): for key in vol.keys():
if not key == 'properties': if not key == 'properties':
del vol[key] to_delete.append(key)
for key in to_delete:
del vol[key]
self.write_override_env() self.write_override_env()