summaryrefslogtreecommitdiff
path: root/cloudinit/stages.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2017-09-13 22:26:03 -0600
committerChad Smith <chad.smith@canonical.com>2017-09-13 22:26:03 -0600
commitf761f2b5f58c8cf13cfee63619f32046216cf66a (patch)
treee534cc7bd15d3ecf0cd0b09e0e3c50042dea1bcc /cloudinit/stages.py
parentcf10a2ff2e2f666d9370f38297a5a105e809ea3c (diff)
downloadcloud-init-git-f761f2b5f58c8cf13cfee63619f32046216cf66a.tar.gz
cloud-config modules: honor distros definitions in each module
Modules can optionally define a list of supported distros on which they can run by declaring a distros attribute in the cc_*py module. This branch fixes handling of cloudinit.stages.Modules.run_section. The behavior of run_section is now the following: - always run a module if the module doesn't declare a distros attribute - always run a module if the module declares distros = [ALL_DISTROS] - skip a module if the distribution on which we run isn't in module.distros - force a run of a skipped module if unverified_modules configuration contains the module name LP: #1715738 LP: #1715690
Diffstat (limited to 'cloudinit/stages.py')
-rw-r--r--cloudinit/stages.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index a1c4a517..d0452688 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -821,28 +821,35 @@ class Modules(object):
skipped = []
forced = []
overridden = self.cfg.get('unverified_modules', [])
+ active_mods = []
+ all_distros = set([distros.ALL_DISTROS])
for (mod, name, _freq, _args) in mostly_mods:
- worked_distros = set(mod.distros)
+ worked_distros = set(mod.distros) # Minimally [] per fixup_modules
worked_distros.update(
distros.Distro.expand_osfamily(mod.osfamilies))
- # module does not declare 'distros' or lists this distro
- if not worked_distros or d_name in worked_distros:
- continue
-
- if name in overridden:
- forced.append(name)
- else:
- skipped.append(name)
+ # Skip only when the following conditions are all met:
+ # - distros are defined in the module != ALL_DISTROS
+ # - the current d_name isn't in distros
+ # - and the module is unverified and not in the unverified_modules
+ # override list
+ if worked_distros and worked_distros != all_distros:
+ if d_name not in worked_distros:
+ if name not in overridden:
+ skipped.append(name)
+ continue
+ forced.append(name)
+ active_mods.append([mod, name, _freq, _args])
if skipped:
- LOG.info("Skipping modules %s because they are not verified "
+ LOG.info("Skipping modules '%s' because they are not verified "
"on distro '%s'. To run anyway, add them to "
- "'unverified_modules' in config.", skipped, d_name)
+ "'unverified_modules' in config.",
+ ','.join(skipped), d_name)
if forced:
- LOG.info("running unverified_modules: %s", forced)
+ LOG.info("running unverified_modules: '%s'", ', '.join(forced))
- return self._run_modules(mostly_mods)
+ return self._run_modules(active_mods)
def read_runtime_config():