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 --- cloudinit/stages.py | 26 +++++++++----------------- cloudinit/util.py | 5 +++++ 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/stages.py b/cloudinit/stages.py index 86a13785..ca3f02fe 100644 --- a/cloudinit/stages.py +++ b/cloudinit/stages.py @@ -845,23 +845,15 @@ class Modules(object): def fetch_base_config(): - base_cfgs = [] - default_cfg = util.get_builtin_cfg() - - # Anything in your conf.d location?? - # or the 'default' cloud.cfg location??? - base_cfgs.append(util.read_conf_with_confd(CLOUD_CONFIG)) - - # Kernel/cmdline parameters override system config - kern_contents = util.read_cc_from_cmdline() - if kern_contents: - base_cfgs.append(util.load_yaml(kern_contents, default={})) - - # And finally the default gets to play - if default_cfg: - base_cfgs.append(default_cfg) - - return util.mergemanydict(base_cfgs) + return util.mergemanydict( + [ + # builtin config + util.get_builtin_cfg(), + # Anything in your conf.d or 'default' cloud.cfg location. + util.read_conf_with_confd(CLOUD_CONFIG), + # Kernel/cmdline parameters override system config + util.read_conf_from_cmdline(), + ], reverse=True) def _pkl_store(obj, fname): diff --git a/cloudinit/util.py b/cloudinit/util.py index cc084719..01c396b4 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -993,6 +993,11 @@ def read_conf_with_confd(cfgfile): return mergemanydict([confd_cfg, cfg]) +def read_conf_from_cmdline(cmdline=None): + # return a dictionary or config on the cmdline or None + return load_yaml(read_cc_from_cmdline(cmdline=cmdline)) + + def read_cc_from_cmdline(cmdline=None): # this should support reading cloud-config information from # the kernel command line. It is intended to support content of the -- cgit v1.2.3