From 0b0f254a6935a1b1fff128fa177152dd519e1a3d Mon Sep 17 00:00:00 2001 From: Wesley Wiedenmeier Date: Tue, 20 Dec 2016 10:12:24 -0600 Subject: 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 --- tests/unittests/test_data.py | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests/unittests/test_data.py') 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'}) -- cgit v1.2.3