summaryrefslogtreecommitdiff
path: root/tests/unittests/test_data.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/test_data.py')
-rw-r--r--tests/unittests/test_data.py51
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'})