Merge ~smoser/cloud-init:bug/1742479-no-manual_cache_clean-warning into cloud-init:master

Proposed by Scott Moser
Status: Merged
Approved by: Chad Smith
Approved revision: 5a6ed582ed7577a884a9b628d59fd26f1b1316d1
Merge reported by: Chad Smith
Merged at revision: 6299e8d0cc230b0c9b41a69a5963bcd2c252c337
Proposed branch: ~smoser/cloud-init:bug/1742479-no-manual_cache_clean-warning
Merge into: cloud-init:master
Diff against target: 65 lines (+20/-6)
3 files modified
cloudinit/cmd/main.py (+7/-1)
cloudinit/util.py (+5/-5)
tests/unittests/test_util.py (+8/-0)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+335956@code.launchpad.net

Commit message

Do not log warning on config files that represent None.

This issue was first identified when manual_cache_clean was set, as
ds-identify would write /run/cloud-init/cloud.cfg with
  # manual_cache_clean
that would generate a warning as cloud-init expected to load a dict.
Any other "empty" config would also log such a warning.

Also fix reading of di_report to allow it to be None, as ds-identify
would write:
  di_report:
    # manual_cache_clean
which reads as 'di_report: None' rather than di_report: {}.

LP: #1742479

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:73f1dc2b0217dd967485dbbb46baf6e489cc769e
https://jenkins.ubuntu.com/server/job/cloud-init-ci/686/
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/686/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) :
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:6f59e49b4ece8eceb43b01a3d7c063ee7899a051
https://jenkins.ubuntu.com/server/job/cloud-init-ci/690/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    FAILED: Ubuntu LTS: Integration

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

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

PASSED: Continuous integration, rev:5a6ed582ed7577a884a9b628d59fd26f1b1316d1
https://jenkins.ubuntu.com/server/job/cloud-init-ci/691/
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/691/rebuild

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

Good fix, LGTM!

review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py
2index 30b37fe..d2f1b77 100644
3--- a/cloudinit/cmd/main.py
4+++ b/cloudinit/cmd/main.py
5@@ -421,7 +421,13 @@ def di_report_warn(datasource, cfg):
6 LOG.debug("no di_report found in config.")
7 return
8
9- dicfg = cfg.get('di_report', {})
10+ dicfg = cfg['di_report']
11+ if dicfg is None:
12+ # ds-identify may write 'di_report:\n #comment\n'
13+ # which reads as {'di_report': None}
14+ LOG.debug("di_report was None.")
15+ return
16+
17 if not isinstance(dicfg, dict):
18 LOG.warning("di_report config not a dictionary: %s", dicfg)
19 return
20diff --git a/cloudinit/util.py b/cloudinit/util.py
21index 8a9f1ab..e42498d 100644
22--- a/cloudinit/util.py
23+++ b/cloudinit/util.py
24@@ -891,17 +891,17 @@ def load_yaml(blob, default=None, allowed=(dict,)):
25 "of length %s with allowed root types %s",
26 len(blob), allowed)
27 converted = safeyaml.load(blob)
28- if not isinstance(converted, allowed):
29+ if converted is None:
30+ LOG.debug("loaded blob returned None, returning default.")
31+ converted = default
32+ elif not isinstance(converted, allowed):
33 # Yes this will just be caught, but thats ok for now...
34 raise TypeError(("Yaml load allows %s root types,"
35 " but got %s instead") %
36 (allowed, type_utils.obj_name(converted)))
37 loaded = converted
38 except (yaml.YAMLError, TypeError, ValueError):
39- if len(blob) == 0:
40- LOG.debug("load_yaml given empty string, returning default")
41- else:
42- logexc(LOG, "Failed loading yaml blob")
43+ logexc(LOG, "Failed loading yaml blob")
44 return loaded
45
46
47diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
48index 787ca20..d63b760 100644
49--- a/tests/unittests/test_util.py
50+++ b/tests/unittests/test_util.py
51@@ -299,6 +299,14 @@ class TestLoadYaml(helpers.TestCase):
52 default=self.mydefault),
53 myobj)
54
55+ def test_none_returns_default(self):
56+ """If yaml.load returns None, then default should be returned."""
57+ blobs = ("", " ", "# foo\n", "#")
58+ mdef = self.mydefault
59+ self.assertEqual(
60+ [(b, self.mydefault) for b in blobs],
61+ [(b, util.load_yaml(blob=b, default=mdef)) for b in blobs])
62+
63
64 class TestMountinfoParsing(helpers.ResourceUsingTestCase):
65 def test_invalid_mountinfo(self):

Subscribers

People subscribed via source and target branches