Merge lp:~harlowja/cloud-init/ds-reset-fix into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Joshua Harlow
Status: Merged
Merged at revision: 747
Proposed branch: lp:~harlowja/cloud-init/ds-reset-fix
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 107 lines (+33/-25)
1 file modified
cloudinit/stages.py (+33/-25)
To merge this branch: bzr merge lp:~harlowja/cloud-init/ds-reset-fix
Reviewer Review Type Date Requested Status
Scott Moser Approve
Review via email: mp+138312@code.launchpad.net
To post a comment you must log in.
lp:~harlowja/cloud-init/ds-reset-fix updated
742. By Joshua Harlow

Move the 'fetch_base_config' to be a top level module function.

Revision history for this message
Scott Moser (smoser) wrote :

I'm calling this "merged" at revno 747 that I just pushed.
I picked the fetch_base_config() method out but did not take the other changes.

The request for this review came because I had missed some function when backporting something to quantal, and was seeing something I thought was related (that a 'cloud' passed to a config did not have a distro).

That was fixed by pulling in revno 720 and 722 though.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cloudinit/stages.py'
--- cloudinit/stages.py 2012-11-13 03:11:34 +0000
+++ cloudinit/stages.py 2012-12-05 21:15:25 +0000
@@ -50,6 +50,22 @@
50NULL_DATA_SOURCE = None50NULL_DATA_SOURCE = None
5151
5252
53def fetch_base_config():
54 base_cfgs = []
55 default_cfg = util.get_builtin_cfg()
56 kern_contents = util.read_cc_from_cmdline()
57 # Kernel/cmdline parameters override system config
58 if kern_contents:
59 base_cfgs.append(util.load_yaml(kern_contents, default={}))
60 # Anything in your conf.d location??
61 # or the 'default' cloud.cfg location???
62 base_cfgs.append(util.read_conf_with_confd(CLOUD_CONFIG))
63 # And finally the default gets to play
64 if default_cfg:
65 base_cfgs.append(default_cfg)
66 return util.mergemanydict(base_cfgs)
67
68
53class Init(object):69class Init(object):
54 def __init__(self, ds_deps=None):70 def __init__(self, ds_deps=None):
55 if ds_deps is not None:71 if ds_deps is not None:
@@ -63,23 +79,29 @@
63 # Changed only when a fetch occurs79 # Changed only when a fetch occurs
64 self.datasource = NULL_DATA_SOURCE80 self.datasource = NULL_DATA_SOURCE
6581
66 def _reset(self, ds=False):82 def _reset(self, reset_ds=False):
67 # Recreated on access83 # Recreated on access
68 self._cfg = None84 self._cfg = None
69 self._paths = None85 self._paths = None
70 self._distro = None86 self._distro = None
71 if ds:87 if reset_ds:
72 self.datasource = NULL_DATA_SOURCE88 self.datasource = NULL_DATA_SOURCE
7389
74 @property90 @property
75 def distro(self):91 def distro(self):
76 if not self._distro:92 if not self._distro:
77 # Try to find the right class to use93 # Try to find the right class to use
78 scfg = self._extract_cfg('system')94 system_config = self._extract_cfg('system')
79 name = scfg.pop('distro', 'ubuntu')95 distro_name = system_config.pop('distro', 'ubuntu')
80 cls = distros.fetch(name)96 distro_cls = distros.fetch(distro_name)
81 LOG.debug("Using distro class %s", cls)97 LOG.debug("Using distro class %s", distro_cls)
82 self._distro = cls(name, scfg, self.paths)98 self._distro = distro_cls(distro_name, system_config, self.paths)
99 # If we have an active datasource we need to adjust
100 # said datasource and move its distro/system config
101 # from whatever it was to a new set...
102 if self.datasource is not NULL_DATA_SOURCE:
103 self.datasource.distro = self._distro
104 self.datasource.sys_cfg = system_config
83 return self._distro105 return self._distro
84106
85 @property107 @property
@@ -103,9 +125,11 @@
103125
104 @property126 @property
105 def paths(self):127 def paths(self):
106 if not self._paths:128 if self._paths is None:
107 path_info = self._extract_cfg('paths')129 path_info = self._extract_cfg('paths')
108 self._paths = helpers.Paths(path_info, self.datasource)130 self._paths = helpers.Paths(path_info, self.datasource)
131 # TODO(harlowja): should we readjust the datasources
132 # path attribute after this has been loaded/reloaded?
109 return self._paths133 return self._paths
110134
111 def _initial_subdirs(self):135 def _initial_subdirs(self):
@@ -155,29 +179,13 @@
155 # None check so that we don't keep on re-loading if empty179 # None check so that we don't keep on re-loading if empty
156 if self._cfg is None:180 if self._cfg is None:
157 self._cfg = self._read_cfg(extra_fns)181 self._cfg = self._read_cfg(extra_fns)
158 # LOG.debug("Loaded 'init' config %s", self._cfg)
159
160 def _read_base_cfg(self):
161 base_cfgs = []
162 default_cfg = util.get_builtin_cfg()
163 kern_contents = util.read_cc_from_cmdline()
164 # Kernel/cmdline parameters override system config
165 if kern_contents:
166 base_cfgs.append(util.load_yaml(kern_contents, default={}))
167 # Anything in your conf.d location??
168 # or the 'default' cloud.cfg location???
169 base_cfgs.append(util.read_conf_with_confd(CLOUD_CONFIG))
170 # And finally the default gets to play
171 if default_cfg:
172 base_cfgs.append(default_cfg)
173 return util.mergemanydict(base_cfgs)
174182
175 def _read_cfg(self, extra_fns):183 def _read_cfg(self, extra_fns):
176 no_cfg_paths = helpers.Paths({}, self.datasource)184 no_cfg_paths = helpers.Paths({}, self.datasource)
177 merger = helpers.ConfigMerger(paths=no_cfg_paths,185 merger = helpers.ConfigMerger(paths=no_cfg_paths,
178 datasource=self.datasource,186 datasource=self.datasource,
179 additional_fns=extra_fns,187 additional_fns=extra_fns,
180 base_cfg=self._read_base_cfg())188 base_cfg=fetch_base_config())
181 return merger.cfg189 return merger.cfg
182190
183 def _restore_from_cache(self):191 def _restore_from_cache(self):