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
1=== modified file 'cloudinit/stages.py'
2--- cloudinit/stages.py 2012-11-13 03:11:34 +0000
3+++ cloudinit/stages.py 2012-12-05 21:15:25 +0000
4@@ -50,6 +50,22 @@
5 NULL_DATA_SOURCE = None
6
7
8+def fetch_base_config():
9+ base_cfgs = []
10+ default_cfg = util.get_builtin_cfg()
11+ kern_contents = util.read_cc_from_cmdline()
12+ # Kernel/cmdline parameters override system config
13+ if kern_contents:
14+ base_cfgs.append(util.load_yaml(kern_contents, default={}))
15+ # Anything in your conf.d location??
16+ # or the 'default' cloud.cfg location???
17+ base_cfgs.append(util.read_conf_with_confd(CLOUD_CONFIG))
18+ # And finally the default gets to play
19+ if default_cfg:
20+ base_cfgs.append(default_cfg)
21+ return util.mergemanydict(base_cfgs)
22+
23+
24 class Init(object):
25 def __init__(self, ds_deps=None):
26 if ds_deps is not None:
27@@ -63,23 +79,29 @@
28 # Changed only when a fetch occurs
29 self.datasource = NULL_DATA_SOURCE
30
31- def _reset(self, ds=False):
32+ def _reset(self, reset_ds=False):
33 # Recreated on access
34 self._cfg = None
35 self._paths = None
36 self._distro = None
37- if ds:
38+ if reset_ds:
39 self.datasource = NULL_DATA_SOURCE
40
41 @property
42 def distro(self):
43 if not self._distro:
44 # Try to find the right class to use
45- scfg = self._extract_cfg('system')
46- name = scfg.pop('distro', 'ubuntu')
47- cls = distros.fetch(name)
48- LOG.debug("Using distro class %s", cls)
49- self._distro = cls(name, scfg, self.paths)
50+ system_config = self._extract_cfg('system')
51+ distro_name = system_config.pop('distro', 'ubuntu')
52+ distro_cls = distros.fetch(distro_name)
53+ LOG.debug("Using distro class %s", distro_cls)
54+ self._distro = distro_cls(distro_name, system_config, self.paths)
55+ # If we have an active datasource we need to adjust
56+ # said datasource and move its distro/system config
57+ # from whatever it was to a new set...
58+ if self.datasource is not NULL_DATA_SOURCE:
59+ self.datasource.distro = self._distro
60+ self.datasource.sys_cfg = system_config
61 return self._distro
62
63 @property
64@@ -103,9 +125,11 @@
65
66 @property
67 def paths(self):
68- if not self._paths:
69+ if self._paths is None:
70 path_info = self._extract_cfg('paths')
71 self._paths = helpers.Paths(path_info, self.datasource)
72+ # TODO(harlowja): should we readjust the datasources
73+ # path attribute after this has been loaded/reloaded?
74 return self._paths
75
76 def _initial_subdirs(self):
77@@ -155,29 +179,13 @@
78 # None check so that we don't keep on re-loading if empty
79 if self._cfg is None:
80 self._cfg = self._read_cfg(extra_fns)
81- # LOG.debug("Loaded 'init' config %s", self._cfg)
82-
83- def _read_base_cfg(self):
84- base_cfgs = []
85- default_cfg = util.get_builtin_cfg()
86- kern_contents = util.read_cc_from_cmdline()
87- # Kernel/cmdline parameters override system config
88- if kern_contents:
89- base_cfgs.append(util.load_yaml(kern_contents, default={}))
90- # Anything in your conf.d location??
91- # or the 'default' cloud.cfg location???
92- base_cfgs.append(util.read_conf_with_confd(CLOUD_CONFIG))
93- # And finally the default gets to play
94- if default_cfg:
95- base_cfgs.append(default_cfg)
96- return util.mergemanydict(base_cfgs)
97
98 def _read_cfg(self, extra_fns):
99 no_cfg_paths = helpers.Paths({}, self.datasource)
100 merger = helpers.ConfigMerger(paths=no_cfg_paths,
101 datasource=self.datasource,
102 additional_fns=extra_fns,
103- base_cfg=self._read_base_cfg())
104+ base_cfg=fetch_base_config())
105 return merger.cfg
106
107 def _restore_from_cache(self):