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
diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py
index 30b37fe..d2f1b77 100644
--- a/cloudinit/cmd/main.py
+++ b/cloudinit/cmd/main.py
@@ -421,7 +421,13 @@ def di_report_warn(datasource, cfg):
421 LOG.debug("no di_report found in config.")421 LOG.debug("no di_report found in config.")
422 return422 return
423423
424 dicfg = cfg.get('di_report', {})424 dicfg = cfg['di_report']
425 if dicfg is None:
426 # ds-identify may write 'di_report:\n #comment\n'
427 # which reads as {'di_report': None}
428 LOG.debug("di_report was None.")
429 return
430
425 if not isinstance(dicfg, dict):431 if not isinstance(dicfg, dict):
426 LOG.warning("di_report config not a dictionary: %s", dicfg)432 LOG.warning("di_report config not a dictionary: %s", dicfg)
427 return433 return
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 8a9f1ab..e42498d 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -891,17 +891,17 @@ def load_yaml(blob, default=None, allowed=(dict,)):
891 "of length %s with allowed root types %s",891 "of length %s with allowed root types %s",
892 len(blob), allowed)892 len(blob), allowed)
893 converted = safeyaml.load(blob)893 converted = safeyaml.load(blob)
894 if not isinstance(converted, allowed):894 if converted is None:
895 LOG.debug("loaded blob returned None, returning default.")
896 converted = default
897 elif not isinstance(converted, allowed):
895 # Yes this will just be caught, but thats ok for now...898 # Yes this will just be caught, but thats ok for now...
896 raise TypeError(("Yaml load allows %s root types,"899 raise TypeError(("Yaml load allows %s root types,"
897 " but got %s instead") %900 " but got %s instead") %
898 (allowed, type_utils.obj_name(converted)))901 (allowed, type_utils.obj_name(converted)))
899 loaded = converted902 loaded = converted
900 except (yaml.YAMLError, TypeError, ValueError):903 except (yaml.YAMLError, TypeError, ValueError):
901 if len(blob) == 0:904 logexc(LOG, "Failed loading yaml blob")
902 LOG.debug("load_yaml given empty string, returning default")
903 else:
904 logexc(LOG, "Failed loading yaml blob")
905 return loaded905 return loaded
906906
907907
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 787ca20..d63b760 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -299,6 +299,14 @@ class TestLoadYaml(helpers.TestCase):
299 default=self.mydefault),299 default=self.mydefault),
300 myobj)300 myobj)
301301
302 def test_none_returns_default(self):
303 """If yaml.load returns None, then default should be returned."""
304 blobs = ("", " ", "# foo\n", "#")
305 mdef = self.mydefault
306 self.assertEqual(
307 [(b, self.mydefault) for b in blobs],
308 [(b, util.load_yaml(blob=b, default=mdef)) for b in blobs])
309
302310
303class TestMountinfoParsing(helpers.ResourceUsingTestCase):311class TestMountinfoParsing(helpers.ResourceUsingTestCase):
304 def test_invalid_mountinfo(self):312 def test_invalid_mountinfo(self):

Subscribers

People subscribed via source and target branches