Don't delete container_cidr key when overriding

Commit f426eb98d1 added a global_override
deletion mechanism, but did not account for the automatically-created
container_cidr key.

This change ensures the key is skipped in deletion, and adds further
tests for the _parse_gloabl_variables function.

Change-Id: I5c48adea5920c1524be75939a75af6bed3a9743a
Closes-Bug: #1649632
This commit is contained in:
Nolan Brubaker 2016-12-13 12:21:21 -05:00
parent 3fc41e29c1
commit f4d73c404c
3 changed files with 39 additions and 1 deletions

View File

@ -793,9 +793,12 @@ def _parse_global_variables(user_cidr, inventory, user_defined_config):
)
logger.debug("Applied global_overrides")
kept_vars = user_defined_config['global_overrides'].keys()
kept_vars.append('container_cidr')
# Remove global overrides that were deleted from inventory, too
for key in inventory['all']['vars'].keys():
if key not in user_defined_config['global_overrides']:
if key not in kept_vars:
logger.debug("Deleting key %s from inventory", key)
del inventory['all']['vars'][key]

View File

@ -0,0 +1,8 @@
---
fixes:
- The 'container_cidr' key has been restored back to openstack_inventory.json
The fix to remove deleted global override keys mistakenly deleted the
'container_cidr' key, as well. This was used by downstream consumers,
and cannot be reconstructed with other information inside the inventory
file. Regression tests were also added.

View File

@ -832,6 +832,33 @@ class TestGlobalOverridesConfigDeletion(TestConfigCheckBase):
self.assertEqual('bar', self.inventory['all']['vars']['foo'])
def test_container_cidr_key_retained(self):
user_cidr = self.user_defined_config['cidr_networks']['container']
di._parse_global_variables(user_cidr, self.inventory,
self.user_defined_config)
self.assertIn('container_cidr', self.inventory['all']['vars'])
self.assertEqual(self.inventory['all']['vars']['container_cidr'],
user_cidr)
def test_only_old_vars_deleted(self):
self.inventory['all']['vars']['foo'] = 'bar'
di._parse_global_variables('', self.inventory,
self.user_defined_config)
self.assertNotIn('foo', self.inventory['all']['vars'])
def test_empty_vars(self):
del self.inventory['all']
di._parse_global_variables('', self.inventory,
self.user_defined_config)
self.assertIn('container_cidr', self.inventory['all']['vars'])
for key in self.user_defined_config['global_overrides']:
self.assertIn(key, self.inventory['all']['vars'])
class TestEnsureInventoryUptoDate(unittest.TestCase):
def setUp(self):