diff options
author | Wesley Wiedenmeier <wesley.wiedenmeier@gmail.com> | 2016-12-20 10:12:24 -0600 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2016-12-21 10:12:27 -0500 |
commit | 0b0f254a6935a1b1fff128fa177152dd519e1a3d (patch) | |
tree | 967ff205e822f6a8fac8c65ae82bcfb6d21d09c2 /tests/unittests/test_data.py | |
parent | 93cf879ddee1e492d66b02a41965323f5a165784 (diff) | |
download | vyos-cloud-init-0b0f254a6935a1b1fff128fa177152dd519e1a3d.tar.gz vyos-cloud-init-0b0f254a6935a1b1fff128fa177152dd519e1a3d.zip |
Fix config order of precedence, putting kernel command line over system.
The correct order of precedence when reading the base config:
builtin config
system config
kernel command line provided config.
This reverts commit 63501f44, which actually broke the behavior it
reported to fix. It also adds some unit tests to ensure this behavior
is not broken again.
LP: #1582323
Diffstat (limited to 'tests/unittests/test_data.py')
-rw-r--r-- | tests/unittests/test_data.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/unittests/test_data.py b/tests/unittests/test_data.py index 55d9b93f..581b581a 100644 --- a/tests/unittests/test_data.py +++ b/tests/unittests/test_data.py @@ -559,3 +559,54 @@ class TestConvertString(helpers.TestCase): text = "hi mom" msg = ud.convert_string(text) self.assertEqual(text, msg.get_payload(decode=False)) + + +class TestFetchBaseConfig(helpers.TestCase): + + def test_only_builtin_gets_builtin2(self): + ret = helpers.wrap_and_call( + 'cloudinit.stages.util', + {'read_conf_with_confd': None, + 'read_conf_from_cmdline': None}, + stages.fetch_base_config) + self.assertEqual(util.get_builtin_cfg(), ret) + + def test_conf_d_overrides_defaults(self): + builtin = util.get_builtin_cfg() + test_key = sorted(builtin)[0] + test_value = 'test' + ret = helpers.wrap_and_call( + 'cloudinit.stages.util', + {'read_conf_with_confd': {'return_value': {test_key: test_value}}, + 'read_conf_from_cmdline': None}, + stages.fetch_base_config) + self.assertEqual(ret.get(test_key), test_value) + builtin[test_key] = test_value + self.assertEqual(ret, builtin) + + def test_cmdline_overrides_defaults(self): + builtin = util.get_builtin_cfg() + test_key = sorted(builtin)[0] + test_value = 'test' + cmdline = {test_key: test_value} + ret = helpers.wrap_and_call( + 'cloudinit.stages.util', + {'read_conf_from_cmdline': {'return_value': cmdline}, + 'read_conf_with_confd': None}, + stages.fetch_base_config) + self.assertEqual(ret.get(test_key), test_value) + builtin[test_key] = test_value + self.assertEqual(ret, builtin) + + def test_cmdline_overrides_conf_d_and_defaults(self): + builtin = {'key1': 'value0', 'key3': 'other2'} + conf_d = {'key1': 'value1', 'key2': 'other1'} + cmdline = {'key3': 'other3', 'key2': 'other2'} + ret = helpers.wrap_and_call( + 'cloudinit.stages.util', + {'read_conf_with_confd': {'return_value': conf_d}, + 'get_builtin_cfg': {'return_value': builtin}, + 'read_conf_from_cmdline': {'return_value': cmdline}}, + stages.fetch_base_config) + self.assertEqual(ret, {'key1': 'value1', 'key2': 'other2', + 'key3': 'other3'}) |