summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/stages.py9
-rw-r--r--tests/unittests/test_data.py53
2 files changed, 45 insertions, 17 deletions
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index 21763810..5bed9032 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -11,7 +11,8 @@ import sys
import six
from six.moves import cPickle as pickle
-from cloudinit.settings import (PER_INSTANCE, FREQUENCIES, CLOUD_CONFIG)
+from cloudinit.settings import (
+ FREQUENCIES, CLOUD_CONFIG, PER_INSTANCE, RUN_CLOUD_CONFIG)
from cloudinit import handlers
@@ -834,6 +835,10 @@ class Modules(object):
return self._run_modules(mostly_mods)
+def read_runtime_config():
+ return util.read_conf(RUN_CLOUD_CONFIG)
+
+
def fetch_base_config():
return util.mergemanydict(
[
@@ -841,6 +846,8 @@ def fetch_base_config():
util.get_builtin_cfg(),
# Anything in your conf.d or 'default' cloud.cfg location.
util.read_conf_with_confd(CLOUD_CONFIG),
+ # runtime config
+ read_runtime_config(),
# Kernel/cmdline parameters override system config
util.read_conf_from_cmdline(),
], reverse=True)
diff --git a/tests/unittests/test_data.py b/tests/unittests/test_data.py
index 4092d9ca..4ad86bb6 100644
--- a/tests/unittests/test_data.py
+++ b/tests/unittests/test_data.py
@@ -564,12 +564,12 @@ class TestConvertString(helpers.TestCase):
class TestFetchBaseConfig(helpers.TestCase):
-
- def test_only_builtin_gets_builtin2(self):
+ def test_only_builtin_gets_builtin(self):
ret = helpers.wrap_and_call(
- 'cloudinit.stages.util',
- {'read_conf_with_confd': None,
- 'read_conf_from_cmdline': None},
+ 'cloudinit.stages',
+ {'util.read_conf_with_confd': None,
+ 'util.read_conf_from_cmdline': None,
+ 'read_runtime_config': {'return_value': {}}},
stages.fetch_base_config)
self.assertEqual(util.get_builtin_cfg(), ret)
@@ -578,9 +578,11 @@ class TestFetchBaseConfig(helpers.TestCase):
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},
+ 'cloudinit.stages',
+ {'util.read_conf_with_confd':
+ {'return_value': {test_key: test_value}},
+ 'util.read_conf_from_cmdline': None,
+ 'read_runtime_config': {'return_value': {}}},
stages.fetch_base_config)
self.assertEqual(ret.get(test_key), test_value)
builtin[test_key] = test_value
@@ -592,25 +594,44 @@ class TestFetchBaseConfig(helpers.TestCase):
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},
+ 'cloudinit.stages',
+ {'util.read_conf_from_cmdline': {'return_value': cmdline},
+ 'util.read_conf_with_confd': None,
+ 'read_runtime_config': 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):
+ def test_cmdline_overrides_confd_runtime_and_defaults(self):
builtin = {'key1': 'value0', 'key3': 'other2'}
conf_d = {'key1': 'value1', 'key2': 'other1'}
cmdline = {'key3': 'other3', 'key2': 'other2'}
+ runtime = {'key3': 'runtime3'}
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}},
+ 'cloudinit.stages',
+ {'util.read_conf_with_confd': {'return_value': conf_d},
+ 'util.get_builtin_cfg': {'return_value': builtin},
+ 'read_runtime_config': {'return_value': runtime},
+ 'util.read_conf_from_cmdline': {'return_value': cmdline}},
stages.fetch_base_config)
self.assertEqual(ret, {'key1': 'value1', 'key2': 'other2',
'key3': 'other3'})
+ def test_order_precedence_is_builtin_system_runtime_cmdline(self):
+ builtin = {'key1': 'builtin0', 'key3': 'builtin3'}
+ conf_d = {'key1': 'confd1', 'key2': 'confd2', 'keyconfd1': 'kconfd1'}
+ runtime = {'key1': 'runtime1', 'key2': 'runtime2'}
+ cmdline = {'key1': 'cmdline1'}
+ ret = helpers.wrap_and_call(
+ 'cloudinit.stages',
+ {'util.read_conf_with_confd': {'return_value': conf_d},
+ 'util.get_builtin_cfg': {'return_value': builtin},
+ 'util.read_conf_from_cmdline': {'return_value': cmdline},
+ 'read_runtime_config': {'return_value': runtime},
+ },
+ stages.fetch_base_config)
+ self.assertEqual(ret, {'key1': 'cmdline1', 'key2': 'runtime2',
+ 'key3': 'builtin3', 'keyconfd1': 'kconfd1'})
+
# vi: ts=4 expandtab