Merge lp:~harlowja/cloud-init/notify-on-reload into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Joshua Harlow
Status: Rejected
Rejected by: Chad Smith
Proposed branch: lp:~harlowja/cloud-init/notify-on-reload
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 110 lines (+32/-14)
2 files modified
cloudinit/sources/__init__.py (+12/-4)
cloudinit/stages.py (+20/-10)
To merge this branch: bzr merge lp:~harlowja/cloud-init/notify-on-reload
Reviewer Review Type Date Requested Status
Chad Smith Needs Fixing
Server Team CI bot continuous-integration Needs Fixing
Review via email: mp+140365@code.launchpad.net

Commit message

Use a notify/subscribe model for configuration/distro reloading.

  Instead of the previous way where we reached into the datasource
  object and messed with its properties its cleaner to create a
  tiny set of functions that can be used to notify others of changes
  and let them use those changes as they wish. So instead of messing
  with the datasource properties, just notify it something has changed
  and have the datasource modify itself instead.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

Hello,
Thank you for taking the time to contribute to cloud-init. Cloud-init has moved its revision control system to git. We are cleaning up old reviews that no longer apply to the current codebase. As a result, we are marking all bzr merge proposals as 'rejected'. If you would like to re-submit this proposal for review, please do so by following the current HACKING documentation at http://cloudinit.readthedocs.io/en/latest/topics/hacking.html.

review: Needs Fixing

Unmerged revisions

752. By Joshua Harlow

Use a notify/subscribe model for configuration/distro reloading.

Instead of the previous way where we reached into the datasource
object and messed with its properties its cleaner to create a
tiny set of functions that can be used to notify others of changes
and let them use those changes as they wish. So instead of messing
with the datasource properties, just notify it something has changed
and have the datasource modify itself instead.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cloudinit/sources/__init__.py'
--- cloudinit/sources/__init__.py 2012-11-12 17:26:49 +0000
+++ cloudinit/sources/__init__.py 2012-12-18 07:45:25 +0000
@@ -52,16 +52,24 @@
52 self.userdata = None52 self.userdata = None
53 self.metadata = None53 self.metadata = None
54 self.userdata_raw = None54 self.userdata_raw = None
55 name = util.obj_name(self)55 self.name = util.obj_name(self)
56 if name.startswith(DS_PREFIX):56 if self.name.startswith(DS_PREFIX):
57 name = name[len(DS_PREFIX):]57 self.name = self.name[len(DS_PREFIX):]
58 self.ds_cfg = util.get_cfg_by_path(self.sys_cfg,58 self.ds_cfg = util.get_cfg_by_path(self.sys_cfg,
59 ("datasource", name), {})59 ("datasource", self.name), {})
60 if not ud_proc:60 if not ud_proc:
61 self.ud_proc = ud.UserDataProcessor(self.paths)61 self.ud_proc = ud.UserDataProcessor(self.paths)
62 else:62 else:
63 self.ud_proc = ud_proc63 self.ud_proc = ud_proc
6464
65 def notify_reloaded(self, distro, system_config, _cloud_config):
66 if system_config:
67 self.sys_cfg = system_config
68 self.ds_cfg = util.get_cfg_by_path(self.sys_cfg,
69 ("datasource", self.name), {})
70 if distro:
71 self.distro = distro
72
65 def get_userdata(self, apply_filter=False):73 def get_userdata(self, apply_filter=False):
66 if self.userdata is None:74 if self.userdata is None:
67 self.userdata = self.ud_proc.process(self.get_userdata_raw())75 self.userdata = self.ud_proc.process(self.get_userdata_raw())
6876
=== modified file 'cloudinit/stages.py'
--- cloudinit/stages.py 2012-12-17 13:41:11 +0000
+++ cloudinit/stages.py 2012-12-18 07:45:25 +0000
@@ -62,6 +62,7 @@
62 self._distro = None62 self._distro = None
63 # Changed only when a fetch occurs63 # Changed only when a fetch occurs
64 self.datasource = NULL_DATA_SOURCE64 self.datasource = NULL_DATA_SOURCE
65 self.notify_listeners = []
6566
66 def _reset(self, reset_ds=False):67 def _reset(self, reset_ds=False):
67 # Recreated on access68 # Recreated on access
@@ -74,20 +75,24 @@
74 @property75 @property
75 def distro(self):76 def distro(self):
76 if not self._distro:77 if not self._distro:
77 # Try to find the right class to use78 # Try to find the right class to use
78 system_config = self._extract_cfg('system')79 system_config = self._extract_cfg('system')
79 distro_name = system_config.pop('distro', 'ubuntu')80 distro_name = system_config.pop('distro', 'ubuntu')
80 distro_cls = distros.fetch(distro_name)81 distro_cls = distros.fetch(distro_name)
81 LOG.debug("Using distro class %s", distro_cls)82 LOG.debug("Using distro class %s", distro_cls)
82 self._distro = distro_cls(distro_name, system_config, self.paths)83 self._distro = distro_cls(distro_name, system_config, self.paths)
83 # If we have an active datasource we need to adjust84 # Let any listener know that we have reloaded
84 # said datasource and move its distro/system config85 self._notify_reloaded(self._distro, system_config, self.cfg)
85 # from whatever it was to a new set...
86 if self.datasource is not NULL_DATA_SOURCE:
87 self.datasource.distro = self._distro
88 self.datasource.sys_cfg = system_config
89 return self._distro86 return self._distro
9087
88 def add_reloaded_listener(self, listener):
89 if listener not in self.notify_listeners:
90 self.notify_listeners.append(listener)
91
92 def _notify_reloaded(self, distro, system_config, cloud_config):
93 for i in self.notify_listeners:
94 i.notify_reloaded(distro, system_config, cloud_config)
95
91 @property96 @property
92 def cfg(self):97 def cfg(self):
93 return self._extract_cfg('restricted')98 return self._extract_cfg('restricted')
@@ -161,9 +166,11 @@
161 # None check so that we don't keep on re-loading if empty166 # None check so that we don't keep on re-loading if empty
162 if self._cfg is None:167 if self._cfg is None:
163 self._cfg = self._read_cfg(extra_fns)168 self._cfg = self._read_cfg(extra_fns)
164 # LOG.debug("Loaded 'init' config %s", self._cfg)
165169
166 def _read_cfg(self, extra_fns):170 def _read_cfg(self, extra_fns):
171 # A no config path object is used since at the point where this
172 # function is called, it is loading the configuration to be so
173 # it doesn't have access to any previous configuration...
167 no_cfg_paths = helpers.Paths({}, self.datasource)174 no_cfg_paths = helpers.Paths({}, self.datasource)
168 merger = helpers.ConfigMerger(paths=no_cfg_paths,175 merger = helpers.ConfigMerger(paths=no_cfg_paths,
169 datasource=self.datasource,176 datasource=self.datasource,
@@ -235,8 +242,10 @@
235 pkg_list)242 pkg_list)
236 LOG.debug("Loaded datasource %s - %s", dsname, ds)243 LOG.debug("Loaded datasource %s - %s", dsname, ds)
237 self.datasource = ds244 self.datasource = ds
238 # Ensure we adjust our path members datasource245 # Automatically add the loaded datasource to the reload notification
239 # now that we have one (thus allowing ipath to be used)246 # listener list so that it gets notified when configuration and distro
247 # reloads happen...
248 self.add_reloaded_listener(ds)
240 self._reset()249 self._reset()
241 return ds250 return ds
242251
@@ -420,6 +429,7 @@
420 #429 #
421 # They will be recreated on future access...430 # They will be recreated on future access...
422 self._reset()431 self._reset()
432
423 # Note(harlowja): the 'active' datasource will have433 # Note(harlowja): the 'active' datasource will have
424 # references to the previous config, distro, paths434 # references to the previous config, distro, paths
425 # objects before the load of the userdata happened,435 # objects before the load of the userdata happened,