Merge ~rjschwei/cloud-init:emptyStageOK into cloud-init:master

Proposed by Robert Schweikert
Status: Merged
Approved by: Chad Smith
Approved revision: 636a27373ef9d7b389a6a273930ab3e0ea73acdc
Merge reported by: Chad Smith
Merged at revision: fef2616b9876d3d354b0de1a8e753361e52e77b0
Proposed branch: ~rjschwei/cloud-init:emptyStageOK
Merge into: cloud-init:master
Diff against target: 69 lines (+33/-3)
2 files modified
cloudinit/stages.py (+3/-1)
tests/unittests/test_runs/test_simple_run.py (+30/-2)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+345377@code.launchpad.net

Commit message

stages: fix tracebacks if a module stage is undefined or empty

In /etc/cloud/cloud.cfg, users and imagees can configure which modules run
during a specific cloud-init stage by modifying one of the following
lists: cloud_init_modules, cloud_init_modules, cloud_init_final_modules.

If any of the configured module lists are absent or empty, cloud-init will
emit the same message it already does for existing lists that only contain
modules which are not unsupported on that platform:

No 'config' modules to run under section 'cloud_config_modules'

LP: #1770462

Description of the change

The user may create a config file that has an empty stage such as

cloud_init_modules:

cloud_config_modules:
 - mounts

if a stage is empty a traceback is generated. With this change an informational message logged and continues processing

To post a comment you must log in.
Revision history for this message
Robert Schweikert (rjschwei) wrote :

I looked around the testing code but couldn't figure out where and how I would test this, thus this does not include any testing.

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

FAILED: Continuous integration, rev:f89dc9b8813793992b492a5ce5bef49849448697
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1113/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1113/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:7c681cc9740a5a15cd3d5346c6e215f28b373ec3
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1114/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1114/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

This log/condition is already 'handled' in cloudinit/cmd/main.py:110 with a message like the following:

No 'config' modules to run under section 'cloud_config_modules', but we should still avoid the Traceback as you say.

you can see this log on a system configured with an empty cloud_config_modules section by running "cloud-init modules --mode config".

root@myb1:~# cloud-init modules --mode config
Cloud-init v. 18.2 running 'modules:config' at Thu, 10 May 2018 19:46:42 +0000. Up 1174.00 seconds.
No 'config' modules to run under section 'cloud_config_modules'

I propose we drop your additional log message, and just return module_list at that point in your patch.

Here is a patch with a test for that behavior not generating a Traceback.
http://paste.ubuntu.com/p/Dkb22CnkMm/

Revision history for this message
Chad Smith (chad.smith) :
review: Needs Fixing
Revision history for this message
Chad Smith (chad.smith) wrote :

Thanks agian for this branch Robert.

I marked workinprogress on the branch so it's off my radar for the moment. When you feel review comments are addressed and you want eyes on it again, please reset the status at the top to "Needs review"

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

PASSED: Continuous integration, rev:636a27373ef9d7b389a6a273930ab3e0ea73acdc
https://jenkins.ubuntu.com/server/job/cloud-init-ci/45/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/45/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

a very belated approve for this.

review: Approve
Revision history for this message
Chad Smith (chad.smith) wrote :

An upstream commit landed for this bug.

To view that commit see the following URL:
https://git.launchpad.net/cloud-init/commit/?id=fef2616b

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/stages.py b/cloudinit/stages.py
2index 3998cf6..286607b 100644
3--- a/cloudinit/stages.py
4+++ b/cloudinit/stages.py
5@@ -697,7 +697,9 @@ class Modules(object):
6 module_list = []
7 if name not in self.cfg:
8 return module_list
9- cfg_mods = self.cfg[name]
10+ cfg_mods = self.cfg.get(name)
11+ if not cfg_mods:
12+ return module_list
13 # Create 'module_list', an array of hashes
14 # Where hash['mod'] = module name
15 # hash['freq'] = frequency
16diff --git a/tests/unittests/test_runs/test_simple_run.py b/tests/unittests/test_runs/test_simple_run.py
17index 762974e..d67c422 100644
18--- a/tests/unittests/test_runs/test_simple_run.py
19+++ b/tests/unittests/test_runs/test_simple_run.py
20@@ -1,5 +1,6 @@
21 # This file is part of cloud-init. See LICENSE file for license information.
22
23+import copy
24 import os
25
26
27@@ -127,8 +128,9 @@ class TestSimpleRun(helpers.FilesystemMockingTestCase):
28 """run_section forced skipped modules by using unverified_modules."""
29
30 # re-write cloud.cfg with unverified_modules override
31- self.cfg['unverified_modules'] = ['spacewalk'] # Would have skipped
32- cloud_cfg = util.yaml_dumps(self.cfg)
33+ cfg = copy.deepcopy(self.cfg)
34+ cfg['unverified_modules'] = ['spacewalk'] # Would have skipped
35+ cloud_cfg = util.yaml_dumps(cfg)
36 util.ensure_dir(os.path.join(self.new_root, 'etc', 'cloud'))
37 util.write_file(os.path.join(self.new_root, 'etc',
38 'cloud', 'cloud.cfg'), cloud_cfg)
39@@ -150,4 +152,30 @@ class TestSimpleRun(helpers.FilesystemMockingTestCase):
40 "running unverified_modules: 'spacewalk'",
41 self.logs.getvalue())
42
43+ def test_none_ds_run_with_no_config_modules(self):
44+ """run_section will report no modules run when none are configured."""
45+
46+ # re-write cloud.cfg with unverified_modules override
47+ cfg = copy.deepcopy(self.cfg)
48+ # Represent empty configuration in /etc/cloud/cloud.cfg
49+ cfg['cloud_init_modules'] = None
50+ cloud_cfg = util.yaml_dumps(cfg)
51+ util.ensure_dir(os.path.join(self.new_root, 'etc', 'cloud'))
52+ util.write_file(os.path.join(self.new_root, 'etc',
53+ 'cloud', 'cloud.cfg'), cloud_cfg)
54+
55+ initer = stages.Init()
56+ initer.read_cfg()
57+ initer.initialize()
58+ initer.fetch()
59+ initer.instancify()
60+ initer.update()
61+ initer.cloudify().run('consume_data', initer.consume_data,
62+ args=[PER_INSTANCE], freq=PER_INSTANCE)
63+
64+ mods = stages.Modules(initer)
65+ (which_ran, failures) = mods.run_section('cloud_init_modules')
66+ self.assertTrue(len(failures) == 0)
67+ self.assertEqual([], which_ran)
68+
69 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches