diff --git a/lib/generate.py b/lib/generate.py index 3ead52307d..ba2e31f05f 100755 --- a/lib/generate.py +++ b/lib/generate.py @@ -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] diff --git a/releasenotes/notes/container_cidr_key_restored-4d232fff46ec00b9.yaml b/releasenotes/notes/container_cidr_key_restored-4d232fff46ec00b9.yaml new file mode 100644 index 0000000000..ce4a521495 --- /dev/null +++ b/releasenotes/notes/container_cidr_key_restored-4d232fff46ec00b9.yaml @@ -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. diff --git a/tests/test_inventory.py b/tests/test_inventory.py index 80f780e794..a38b3eeefb 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -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):