Merge ~smoser/cloud-init:fix/tests-command-output-simple-warn into cloud-init:master

Proposed by Scott Moser on 2017-10-20
Status: Merged
Approved by: Chad Smith on 2017-10-20
Approved revision: 34182a0ae573692c543b1046ea320ff851fd8555
Merged at revision: c06eea972eb4b7bfa68f4f542f2fb67ea1d455ac
Proposed branch: ~smoser/cloud-init:fix/tests-command-output-simple-warn
Merge into: cloud-init:master
Diff against target: 116 lines (+30/-10)
4 files modified
cloudinit/config/cc_lxd.py (+1/-1)
tests/cloud_tests/testcases/base.py (+5/-1)
tests/cloud_tests/testcases/main/command_output_simple.py (+16/-0)
tests/unittests/test_handler/test_handler_lxd.py (+8/-8)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing on 2017-10-20
Chad Smith 2017-10-20 Approve on 2017-10-20
Joshua Powers (community) Approve on 2017-10-20
Review via email: mp+332587@code.launchpad.net

Commit Message

citest: fix remaining warnings raised by integration tests.

There was fallout in a full integration test run from my adding of
 test_no_warnings_in_log
which asserted that there could not be a WARNING found in the
/var/log/cloud-init.log

This fixes 2 of the cases:
 * TestCommandOutputSimple had a valid WARNING written, so adjust its
   test case to allow for that.
 * TestLxdDir had a valid config in the test but the module would
   log a WARNING, so fix the module.

Also updates lxd unit tests to look for WARN themselves.

To post a comment you must log in.
Joshua Powers (powersj) wrote :

+1 Thanks for the cleanup

review: Approve
Chad Smith (chad.smith) wrote :

+1 with this minor patch which ensures the unit tests are actually checking for warnings. So we don't rely on costly integration tests finding them

Also, it moves lxd tests to our CiTestCase to make sure we are pulling from common logging setup
http://paste.ubuntu.com/25780782/

review: Approve

FAILED: Continuous integration, rev:16b5b5f691b03f2520d52ba7556a097561c25995
https://jenkins.ubuntu.com/server/job/cloud-init-ci/420/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    FAILED: MAAS Compatability Testing

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

review: Needs Fixing (continuous-integration)
Scott Moser (smoser) wrote :

grabbed chad's suggested changes and pushed. thanks.

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

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

review: Needs Fixing (continuous-integration)

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

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

review: Needs Fixing (continuous-integration)

FAILED: Continuous integration, rev:34182a0ae573692c543b1046ea320ff851fd8555
https://jenkins.ubuntu.com/server/job/cloud-init-ci/426/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    FAILED: MAAS Compatability Testing

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

review: Needs Fixing (continuous-integration)

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

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

review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/config/cc_lxd.py b/cloudinit/config/cc_lxd.py
2index e6262f8..09374d2 100644
3--- a/cloudinit/config/cc_lxd.py
4+++ b/cloudinit/config/cc_lxd.py
5@@ -72,7 +72,7 @@ def handle(name, cfg, cloud, log, args):
6 type(init_cfg))
7 init_cfg = {}
8
9- bridge_cfg = lxd_cfg.get('bridge')
10+ bridge_cfg = lxd_cfg.get('bridge', {})
11 if not isinstance(bridge_cfg, dict):
12 log.warn("lxd/bridge config must be a dictionary. found a '%s'",
13 type(bridge_cfg))
14diff --git a/tests/cloud_tests/testcases/base.py b/tests/cloud_tests/testcases/base.py
15index d3586e3..1706f59 100644
16--- a/tests/cloud_tests/testcases/base.py
17+++ b/tests/cloud_tests/testcases/base.py
18@@ -70,7 +70,11 @@ class CloudTestCase(unittest.TestCase):
19
20 def test_no_warnings_in_log(self):
21 """Warnings should not be found in the log."""
22- self.assertNotIn("WARN", self.get_data_file('cloud-init.log'))
23+ self.assertEqual(
24+ [],
25+ [l for l in self.get_data_file('cloud-init.log').splitlines()
26+ if 'WARN' in l],
27+ msg="'WARN' found inside cloud-init.log")
28
29
30 class PasswordListTest(CloudTestCase):
31diff --git a/tests/cloud_tests/testcases/main/command_output_simple.py b/tests/cloud_tests/testcases/main/command_output_simple.py
32index fe4c767..857881c 100644
33--- a/tests/cloud_tests/testcases/main/command_output_simple.py
34+++ b/tests/cloud_tests/testcases/main/command_output_simple.py
35@@ -15,4 +15,20 @@ class TestCommandOutputSimple(base.CloudTestCase):
36 data.splitlines()[-1].strip())
37 # TODO: need to test that all stages redirected here
38
39+ def test_no_warnings_in_log(self):
40+ """Warnings should not be found in the log.
41+
42+ This class redirected stderr and stdout, so it expects to find
43+ a warning in cloud-init.log to that effect."""
44+ redirect_msg = 'Stdout, stderr changing to'
45+ warnings = [
46+ l for l in self.get_data_file('cloud-init.log').splitlines()
47+ if 'WARN' in l]
48+ self.assertEqual(
49+ [], [w for w in warnings if redirect_msg not in w],
50+ msg="'WARN' found inside cloud-init.log")
51+ self.assertEqual(
52+ 1, len(warnings),
53+ msg="Did not find %s in cloud-init.log" % redirect_msg)
54+
55 # vi: ts=4 expandtab
56diff --git a/tests/unittests/test_handler/test_handler_lxd.py b/tests/unittests/test_handler/test_handler_lxd.py
57index f132a77..e0d9ab6 100644
58--- a/tests/unittests/test_handler/test_handler_lxd.py
59+++ b/tests/unittests/test_handler/test_handler_lxd.py
60@@ -5,17 +5,16 @@ from cloudinit.sources import DataSourceNoCloud
61 from cloudinit import (distros, helpers, cloud)
62 from cloudinit.tests import helpers as t_help
63
64-import logging
65-
66 try:
67 from unittest import mock
68 except ImportError:
69 import mock
70
71-LOG = logging.getLogger(__name__)
72
73+class TestLxd(t_help.CiTestCase):
74+
75+ with_logs = True
76
77-class TestLxd(t_help.TestCase):
78 lxd_cfg = {
79 'lxd': {
80 'init': {
81@@ -41,7 +40,7 @@ class TestLxd(t_help.TestCase):
82 def test_lxd_init(self, mock_util):
83 cc = self._get_cloud('ubuntu')
84 mock_util.which.return_value = True
85- cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, LOG, [])
86+ cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, self.logger, [])
87 self.assertTrue(mock_util.which.called)
88 init_call = mock_util.subp.call_args_list[0][0][0]
89 self.assertEqual(init_call,
90@@ -55,7 +54,8 @@ class TestLxd(t_help.TestCase):
91 cc = self._get_cloud('ubuntu')
92 cc.distro = mock.MagicMock()
93 mock_util.which.return_value = None
94- cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, LOG, [])
95+ cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, self.logger, [])
96+ self.assertNotIn('WARN', self.logs.getvalue())
97 self.assertTrue(cc.distro.install_packages.called)
98 install_pkg = cc.distro.install_packages.call_args_list[0][0][0]
99 self.assertEqual(sorted(install_pkg), ['lxd', 'zfs'])
100@@ -64,7 +64,7 @@ class TestLxd(t_help.TestCase):
101 def test_no_init_does_nothing(self, mock_util):
102 cc = self._get_cloud('ubuntu')
103 cc.distro = mock.MagicMock()
104- cc_lxd.handle('cc_lxd', {'lxd': {}}, cc, LOG, [])
105+ cc_lxd.handle('cc_lxd', {'lxd': {}}, cc, self.logger, [])
106 self.assertFalse(cc.distro.install_packages.called)
107 self.assertFalse(mock_util.subp.called)
108
109@@ -72,7 +72,7 @@ class TestLxd(t_help.TestCase):
110 def test_no_lxd_does_nothing(self, mock_util):
111 cc = self._get_cloud('ubuntu')
112 cc.distro = mock.MagicMock()
113- cc_lxd.handle('cc_lxd', {'package_update': True}, cc, LOG, [])
114+ cc_lxd.handle('cc_lxd', {'package_update': True}, cc, self.logger, [])
115 self.assertFalse(cc.distro.install_packages.called)
116 self.assertFalse(mock_util.subp.called)
117

Subscribers

People subscribed via source and target branches

to all changes: