diff options
author | Scott Moser <smoser@brickies.net> | 2017-10-20 16:05:04 -0600 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2017-10-20 16:06:58 -0600 |
commit | c06eea972eb4b7bfa68f4f542f2fb67ea1d455ac (patch) | |
tree | 258b4301f3cebc23d8c2031cf9209e29b51de358 | |
parent | a51968d50e7cdecabaf255c26386fd82f6640cc3 (diff) | |
download | vyos-cloud-init-c06eea972eb4b7bfa68f4f542f2fb67ea1d455ac.tar.gz vyos-cloud-init-c06eea972eb4b7bfa68f4f542f2fb67ea1d455ac.zip |
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.
-rw-r--r-- | cloudinit/config/cc_lxd.py | 2 | ||||
-rw-r--r-- | tests/cloud_tests/testcases/base.py | 6 | ||||
-rw-r--r-- | tests/cloud_tests/testcases/main/command_output_simple.py | 16 | ||||
-rw-r--r-- | tests/unittests/test_handler/test_handler_lxd.py | 16 |
4 files changed, 30 insertions, 10 deletions
diff --git a/cloudinit/config/cc_lxd.py b/cloudinit/config/cc_lxd.py index e6262f8c..09374d2e 100644 --- a/cloudinit/config/cc_lxd.py +++ b/cloudinit/config/cc_lxd.py @@ -72,7 +72,7 @@ def handle(name, cfg, cloud, log, args): type(init_cfg)) init_cfg = {} - bridge_cfg = lxd_cfg.get('bridge') + bridge_cfg = lxd_cfg.get('bridge', {}) if not isinstance(bridge_cfg, dict): log.warn("lxd/bridge config must be a dictionary. found a '%s'", type(bridge_cfg)) diff --git a/tests/cloud_tests/testcases/base.py b/tests/cloud_tests/testcases/base.py index d3586e3c..1706f59b 100644 --- a/tests/cloud_tests/testcases/base.py +++ b/tests/cloud_tests/testcases/base.py @@ -70,7 +70,11 @@ class CloudTestCase(unittest.TestCase): def test_no_warnings_in_log(self): """Warnings should not be found in the log.""" - self.assertNotIn("WARN", self.get_data_file('cloud-init.log')) + self.assertEqual( + [], + [l for l in self.get_data_file('cloud-init.log').splitlines() + if 'WARN' in l], + msg="'WARN' found inside cloud-init.log") class PasswordListTest(CloudTestCase): diff --git a/tests/cloud_tests/testcases/main/command_output_simple.py b/tests/cloud_tests/testcases/main/command_output_simple.py index fe4c7670..857881cb 100644 --- a/tests/cloud_tests/testcases/main/command_output_simple.py +++ b/tests/cloud_tests/testcases/main/command_output_simple.py @@ -15,4 +15,20 @@ class TestCommandOutputSimple(base.CloudTestCase): data.splitlines()[-1].strip()) # TODO: need to test that all stages redirected here + def test_no_warnings_in_log(self): + """Warnings should not be found in the log. + + This class redirected stderr and stdout, so it expects to find + a warning in cloud-init.log to that effect.""" + redirect_msg = 'Stdout, stderr changing to' + warnings = [ + l for l in self.get_data_file('cloud-init.log').splitlines() + if 'WARN' in l] + self.assertEqual( + [], [w for w in warnings if redirect_msg not in w], + msg="'WARN' found inside cloud-init.log") + self.assertEqual( + 1, len(warnings), + msg="Did not find %s in cloud-init.log" % redirect_msg) + # vi: ts=4 expandtab diff --git a/tests/unittests/test_handler/test_handler_lxd.py b/tests/unittests/test_handler/test_handler_lxd.py index f132a778..e0d9ab6c 100644 --- a/tests/unittests/test_handler/test_handler_lxd.py +++ b/tests/unittests/test_handler/test_handler_lxd.py @@ -5,17 +5,16 @@ from cloudinit.sources import DataSourceNoCloud from cloudinit import (distros, helpers, cloud) from cloudinit.tests import helpers as t_help -import logging - try: from unittest import mock except ImportError: import mock -LOG = logging.getLogger(__name__) +class TestLxd(t_help.CiTestCase): + + with_logs = True -class TestLxd(t_help.TestCase): lxd_cfg = { 'lxd': { 'init': { @@ -41,7 +40,7 @@ class TestLxd(t_help.TestCase): def test_lxd_init(self, mock_util): cc = self._get_cloud('ubuntu') mock_util.which.return_value = True - cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, LOG, []) + cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, self.logger, []) self.assertTrue(mock_util.which.called) init_call = mock_util.subp.call_args_list[0][0][0] self.assertEqual(init_call, @@ -55,7 +54,8 @@ class TestLxd(t_help.TestCase): cc = self._get_cloud('ubuntu') cc.distro = mock.MagicMock() mock_util.which.return_value = None - cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, LOG, []) + cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, self.logger, []) + self.assertNotIn('WARN', self.logs.getvalue()) self.assertTrue(cc.distro.install_packages.called) install_pkg = cc.distro.install_packages.call_args_list[0][0][0] self.assertEqual(sorted(install_pkg), ['lxd', 'zfs']) @@ -64,7 +64,7 @@ class TestLxd(t_help.TestCase): def test_no_init_does_nothing(self, mock_util): cc = self._get_cloud('ubuntu') cc.distro = mock.MagicMock() - cc_lxd.handle('cc_lxd', {'lxd': {}}, cc, LOG, []) + cc_lxd.handle('cc_lxd', {'lxd': {}}, cc, self.logger, []) self.assertFalse(cc.distro.install_packages.called) self.assertFalse(mock_util.subp.called) @@ -72,7 +72,7 @@ class TestLxd(t_help.TestCase): def test_no_lxd_does_nothing(self, mock_util): cc = self._get_cloud('ubuntu') cc.distro = mock.MagicMock() - cc_lxd.handle('cc_lxd', {'package_update': True}, cc, LOG, []) + cc_lxd.handle('cc_lxd', {'package_update': True}, cc, self.logger, []) self.assertFalse(cc.distro.install_packages.called) self.assertFalse(mock_util.subp.called) |