Merge "Remove deleted override vars from inventory"
This commit is contained in:
commit
04a9f2acf7
@ -871,6 +871,11 @@ def _parse_global_variables(user_cidr, inventory, user_defined_config):
|
|||||||
user_defined_config['global_overrides']
|
user_defined_config['global_overrides']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 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']:
|
||||||
|
del inventory['all']['vars'][key]
|
||||||
|
|
||||||
|
|
||||||
def append_if(array, item):
|
def append_if(array, item):
|
||||||
"""Append an ``item`` to an ``array`` if its not already in it.
|
"""Append an ``item`` to an ``array`` if its not already in it.
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- Deleting variable entries from the ``global_overrides`` dictionary in
|
||||||
|
``openstack_user_config.yml`` now properly removes those variables from
|
||||||
|
the ``openstack_inventory.json`` file. See Bug #1588902.
|
@ -382,6 +382,12 @@ class TestConfigChecks(unittest.TestCase):
|
|||||||
with open(USER_CONFIG_FILE, 'wb') as f:
|
with open(USER_CONFIG_FILE, 'wb') as f:
|
||||||
f.write(yaml.dump(self.user_defined_config))
|
f.write(yaml.dump(self.user_defined_config))
|
||||||
|
|
||||||
|
def restore_config(self):
|
||||||
|
# get back our initial user config file
|
||||||
|
os.remove(USER_CONFIG_FILE)
|
||||||
|
os.rename(USER_CONFIG_FILE + ".tmp", USER_CONFIG_FILE)
|
||||||
|
self.config_changed = False
|
||||||
|
|
||||||
def test_missing_container_cidr_network(self):
|
def test_missing_container_cidr_network(self):
|
||||||
self.delete_provider_network('container')
|
self.delete_provider_network('container')
|
||||||
with self.assertRaises(SystemExit) as context:
|
with self.assertRaises(SystemExit) as context:
|
||||||
@ -519,9 +525,7 @@ class TestConfigChecks(unittest.TestCase):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
if self.config_changed:
|
if self.config_changed:
|
||||||
# get back our initial user config file
|
self.restore_config()
|
||||||
os.remove(USER_CONFIG_FILE)
|
|
||||||
os.rename(USER_CONFIG_FILE + ".tmp", USER_CONFIG_FILE)
|
|
||||||
|
|
||||||
|
|
||||||
class TestStaticRouteConfig(TestConfigChecks):
|
class TestStaticRouteConfig(TestConfigChecks):
|
||||||
@ -643,6 +647,45 @@ class TestNetAddressSearch(unittest.TestCase):
|
|||||||
self.assertEqual(pns, new_pns)
|
self.assertEqual(pns, new_pns)
|
||||||
|
|
||||||
|
|
||||||
|
class TestGlobalOverridesConfigDeletion(TestConfigChecks):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestGlobalOverridesConfigDeletion, self).setUp()
|
||||||
|
self.inventory = get_inventory()
|
||||||
|
|
||||||
|
def add_global_override(self, var_name, var_value):
|
||||||
|
"""Adds an arbitrary name and value to the global_overrides dict."""
|
||||||
|
overrides = self.user_defined_config['global_overrides']
|
||||||
|
overrides[var_name] = var_value
|
||||||
|
|
||||||
|
def remove_global_override(self, var_name):
|
||||||
|
"""Removes target key from the global_overrides dict."""
|
||||||
|
overrides = self.user_defined_config['global_overrides']
|
||||||
|
del overrides[var_name]
|
||||||
|
|
||||||
|
def test_global_overrides_delete_when_merge(self):
|
||||||
|
"""Vars removed from global overrides are removed from inventory"""
|
||||||
|
self.add_global_override('foo', 'bar')
|
||||||
|
|
||||||
|
di._parse_global_variables({}, self.inventory,
|
||||||
|
self.user_defined_config)
|
||||||
|
|
||||||
|
self.remove_global_override('foo')
|
||||||
|
|
||||||
|
di._parse_global_variables({}, self.inventory,
|
||||||
|
self.user_defined_config)
|
||||||
|
|
||||||
|
self.assertNotIn('foo', self.inventory['all']['vars'],
|
||||||
|
"foo var not removed from group_vars_all")
|
||||||
|
|
||||||
|
def test_global_overrides_merge(self):
|
||||||
|
self.add_global_override('foo', 'bar')
|
||||||
|
|
||||||
|
di._parse_global_variables({}, self.inventory,
|
||||||
|
self.user_defined_config)
|
||||||
|
|
||||||
|
self.assertEqual('bar', self.inventory['all']['vars']['foo'])
|
||||||
|
|
||||||
|
|
||||||
class TestMultipleRuns(unittest.TestCase):
|
class TestMultipleRuns(unittest.TestCase):
|
||||||
def test_creating_backup_file(self):
|
def test_creating_backup_file(self):
|
||||||
inventory_file_path = os.path.join(TARGET_DIR,
|
inventory_file_path = os.path.join(TARGET_DIR,
|
||||||
|
Loading…
Reference in New Issue
Block a user