← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~harlowja/cloud-init/ds-reset-fix into lp:cloud-init

 

Joshua Harlow has proposed merging lp:~harlowja/cloud-init/ds-reset-fix into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/ds-reset-fix/+merge/138312
-- 
https://code.launchpad.net/~harlowja/cloud-init/ds-reset-fix/+merge/138312
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/ds-reset-fix into lp:cloud-init.
=== modified file 'cloudinit/stages.py'
--- cloudinit/stages.py	2012-11-13 03:11:34 +0000
+++ cloudinit/stages.py	2012-12-05 21:05:24 +0000
@@ -63,23 +63,29 @@
         # Changed only when a fetch occurs
         self.datasource = NULL_DATA_SOURCE
 
-    def _reset(self, ds=False):
+    def _reset(self, reset_ds=False):
         # Recreated on access
         self._cfg = None
         self._paths = None
         self._distro = None
-        if ds:
+        if reset_ds:
             self.datasource = NULL_DATA_SOURCE
 
     @property
     def distro(self):
         if not self._distro:
             # Try to find the right class to use
-            scfg = self._extract_cfg('system')
-            name = scfg.pop('distro', 'ubuntu')
-            cls = distros.fetch(name)
-            LOG.debug("Using distro class %s", cls)
-            self._distro = cls(name, scfg, self.paths)
+            system_config = self._extract_cfg('system')
+            distro_name = system_config.pop('distro', 'ubuntu')
+            distro_cls = distros.fetch(distro_name)
+            LOG.debug("Using distro class %s", distro_cls)
+            self._distro = distro_cls(distro_name, system_config, self.paths)
+            # If we have an active datasource we need to adjust
+            # said datasource and move its distro/system config
+            # from whatever it was to a new set...
+            if self.datasource is not NULL_DATA_SOURCE:
+                self.datasource.distro = self._distro
+                self.datasource.sys_cfg = system_config
         return self._distro
 
     @property
@@ -103,9 +109,11 @@
 
     @property
     def paths(self):
-        if not self._paths:
+        if self._paths is None:
             path_info = self._extract_cfg('paths')
             self._paths = helpers.Paths(path_info, self.datasource)
+            # TODO(harlowja): should we readjust the datasources
+            # path attribute after this has been loaded/reloaded?
         return self._paths
 
     def _initial_subdirs(self):
@@ -155,9 +163,9 @@
         # None check so that we don't keep on re-loading if empty
         if self._cfg is None:
             self._cfg = self._read_cfg(extra_fns)
-            # LOG.debug("Loaded 'init' config %s", self._cfg)
 
-    def _read_base_cfg(self):
+    @staticmethod
+    def fetch_base_config():
         base_cfgs = []
         default_cfg = util.get_builtin_cfg()
         kern_contents = util.read_cc_from_cmdline()
@@ -177,7 +185,7 @@
         merger = helpers.ConfigMerger(paths=no_cfg_paths,
                                       datasource=self.datasource,
                                       additional_fns=extra_fns,
-                                      base_cfg=self._read_base_cfg())
+                                      base_cfg=Init.fetch_base_config())
         return merger.cfg
 
     def _restore_from_cache(self):