Merge lp:~harlowja/cloud-init/cloud-init-dynamic-distro-check into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Joshua Harlow
Status: Rejected
Rejected by: Scott Moser
Proposed branch: lp:~harlowja/cloud-init/cloud-init-dynamic-distro-check
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 115 lines (+62/-16)
2 files modified
cloudinit/exceptions.py (+28/-0)
cloudinit/stages.py (+34/-16)
To merge this branch: bzr merge lp:~harlowja/cloud-init/cloud-init-dynamic-distro-check
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing
cloud-init Commiters Pending
Review via email: mp+300805@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Lars Kellogg-Stedman (larsks) :
1260. By Joshua Harlow

Use a more advanced module 'working' function
that by default performs the same distro checking
behavior (but allows modules to provide there
own if they so desire to).

Revision history for this message
Joshua Harlow (harlowja) wrote :

Yup, I updated it to try that approach instead; seems like its better IMHO.

1261. By Joshua Harlow

Rearrange some of the pre_handling code.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:1261
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~harlowja/cloud-init/cloud-init-dynamic-distro-check/+merge/300805/+edit-commit-message

https://server-team-jenkins.canonical.com/job/cloud-init-ci/36/
Executed test runs:
    None: https://server-team-jenkins.canonical.com/job/lp-vote-on-merge/10/console

Click here to trigger a rebuild:
https://server-team-jenkins.canonical.com/job/cloud-init-ci/36/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

Hello,
Thank you for taking the time to contribute to cloud-init. Cloud-init has moved its revision control system to git. 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 .

Unmerged revisions

1261. By Joshua Harlow

Rearrange some of the pre_handling code.

1260. By Joshua Harlow

Use a more advanced module 'working' function
that by default performs the same distro checking
behavior (but allows modules to provide there
own if they so desire to).

1259. By Joshua Harlow

Allow modules to provide a 'is_usable_on' function

This function, if it exists will allow for the module
to decide if it works on the running distro, making it
a little more flexible (vs the previous distro lists that
are more static) so that the module can itself figure out
if it should be operational or not.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'cloudinit/exceptions.py'
--- cloudinit/exceptions.py 1970-01-01 00:00:00 +0000
+++ cloudinit/exceptions.py 2016-07-22 07:30:56 +0000
@@ -0,0 +1,28 @@
1# vi: ts=4 expandtab
2#
3# Author: Joshua Harlow <harlowja@yahoo-inc.com>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3, as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18class ModuleNotSupported(Exception):
19 """Exception raised when a module states it is not supported.
20
21 Requires that when raised that (a textual) reason that explains why
22 the module believes it is not supported is provided so that this reason
23 can be relayed to users to provide some useful information.
24 """
25
26 def __init__(self, reason):
27 super(ModuleNotSupported, self).__init__(reason)
28 self.reason = reason
029
=== modified file 'cloudinit/stages.py'
--- cloudinit/stages.py 2016-06-10 21:22:17 +0000
+++ cloudinit/stages.py 2016-07-22 07:30:56 +0000
@@ -21,6 +21,7 @@
21# along with this program. If not, see <http://www.gnu.org/licenses/>.21# along with this program. If not, see <http://www.gnu.org/licenses/>.
2222
23import copy23import copy
24import functools
24import os25import os
25import sys26import sys
2627
@@ -40,6 +41,7 @@
40from cloudinit import cloud41from cloudinit import cloud
41from cloudinit import config42from cloudinit import config
42from cloudinit import distros43from cloudinit import distros
44from cloudinit import exceptions
43from cloudinit import helpers45from cloudinit import helpers
44from cloudinit import importer46from cloudinit import importer
45from cloudinit import log as logging47from cloudinit import log as logging
@@ -808,31 +810,47 @@
808 def run_section(self, section_name):810 def run_section(self, section_name):
809 raw_mods = self._read_modules(section_name)811 raw_mods = self._read_modules(section_name)
810 mostly_mods = self._fixup_modules(raw_mods)812 mostly_mods = self._fixup_modules(raw_mods)
811 d_name = self.init.distro.name813 distro = self.init.distro
814
815 def _pre_handle(mod, name, cfg, distro, log):
816 worked_distros = set(mod.distros)
817 worked_distros.update(
818 distros.Distro.expand_osfamily(mod.osfamilies))
819 if len(worked_distros) == 0 or distro.name in worked_distros:
820 return
821 reason = ("Module '%s' is not supported on distribution %s"
822 " as it has stated it only works correctly on"
823 " %s distributions" % (name, distro.name,
824 sorted(worked_distros)))
825 raise exceptions.ModuleNotSupported(reason)
812826
813 skipped = []827 skipped = []
814 forced = []828 forced = []
815 overridden = self.cfg.get('unverified_modules', [])829 overridden = self.cfg.get('unverified_modules', [])
816 for (mod, name, _freq, _args) in mostly_mods:830 for (mod, name, _freq, _args) in mostly_mods:
817 worked_distros = set(mod.distros)
818 worked_distros.update(
819 distros.Distro.expand_osfamily(mod.osfamilies))
820
821 # module does not declare 'distros' or lists this distro
822 if not worked_distros or d_name in worked_distros:
823 continue
824
825 if name in overridden:831 if name in overridden:
826 forced.append(name)832 forced.append(name)
827 else:833 else:
828 skipped.append(name)834 try:
829835 pre_handle_func = getattr(mod, 'pre_handle', None)
830 if skipped:836 if not six.callable(pre_handle_func):
831 LOG.info("Skipping modules %s because they are not verified "837 # Must be an older module, or something we can't
832 "on distro '%s'. To run anyway, add them to "838 # call into, so switch to the default that verifies
833 "'unverified_modules' in config.", skipped, d_name)839 # the basics...
840 pre_handle_func = functools.partial(_pre_handle, mod)
841 pre_handle_func(name, self.cfg, distro, config.LOG)
842 except exceptions.ModuleNotSupported as e:
843 LOG.info(
844 "Skipping module '%s' because %s. To run anyway,"
845 " add this module name to 'unverified_modules'"
846 " in config.", name, e.reason)
847 skipped.append(name)
848 except Exception:
849 LOG.exception("Failed at determining if module '%s'"
850 " can be correctly ran on this system,"
851 " assuming by default it can be ran.")
834 if forced:852 if forced:
835 LOG.info("running unverified_modules: %s", forced)853 LOG.info("Running unverified modules: %s", forced)
836854
837 return self._run_modules(mostly_mods)855 return self._run_modules(mostly_mods)
838856