1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 | diff --git a/cloudinit/config/cc_write_files.py b/cloudinit/config/cc_write_files.py
index 15f42f2..1835a31 100644
--- a/cloudinit/config/cc_write_files.py
+++ b/cloudinit/config/cc_write_files.py
@@ -53,6 +53,7 @@ import six
from cloudinit.settings import PER_INSTANCE
from cloudinit import util
+
frequency = PER_INSTANCE
DEFAULT_OWNER = "root:root"
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index e78abce..569f1ae 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -97,11 +97,13 @@ class CiTestCase(TestCase):
super(CiTestCase, self).setUp()
if self.with_logs:
# Create a log handler so unit tests can search expected logs.
- logger = logging.getLogger()
+ self.logger = logging.getLogger()
self.logs = six.StringIO()
+ formatter = logging.Formatter('%(levelname)s: %(message)s')
handler = logging.StreamHandler(self.logs)
- self.old_handlers = logger.handlers
- logger.handlers = [handler]
+ handler.setFormatter(formatter)
+ self.old_handlers = self.logger.handlers
+ self.logger.handlers = [handler]
def tearDown(self):
if self.with_logs:
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 42f49e0..b17f389 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -263,7 +263,8 @@ fdescfs /dev/fd fdescfs rw 0 0
{}, distro=None, paths=self.paths)
self.assertFalse(dsrc.get_data())
self.assertEqual(
- "Non-Azure DMI asset tag '{0}' discovered.\n".format(nonazure_tag),
+ "DEBUG: Non-Azure DMI asset tag '{0}' discovered.\n".format(
+ nonazure_tag),
self.logs.getvalue())
def test_basic_seed_dir(self):
diff --git a/tests/unittests/test_handler/test_handler_ntp.py b/tests/unittests/test_handler/test_handler_ntp.py
index 3a9f7f7..c4299d9 100644
--- a/tests/unittests/test_handler/test_handler_ntp.py
+++ b/tests/unittests/test_handler/test_handler_ntp.py
@@ -216,7 +216,8 @@ class TestNtp(FilesystemMockingTestCase):
"""When no ntp section is defined handler logs a warning and noops."""
cc_ntp.handle('cc_ntp', {}, None, None, [])
self.assertEqual(
- 'Skipping module named cc_ntp, not present or disabled by cfg\n',
+ 'DEBUG: Skipping module named cc_ntp, '
+ 'not present or disabled by cfg\n',
self.logs.getvalue())
def test_ntp_handler_schema_validation_allows_empty_ntp_config(self):
diff --git a/tests/unittests/test_handler/test_handler_write_files.py b/tests/unittests/test_handler/test_handler_write_files.py
index c67504f..41cc84f 100644
--- a/tests/unittests/test_handler/test_handler_write_files.py
+++ b/tests/unittests/test_handler/test_handler_write_files.py
@@ -8,7 +8,6 @@ from ..helpers import CiTestCase, FilesystemMockingTestCase
import base64
import gzip
-import mock
import shutil
import six
import tempfile
@@ -100,35 +99,32 @@ class TestWriteFiles(FilesystemMockingTestCase):
class TestDecodePerms(CiTestCase):
- mocklog = None
- def setUp(self):
- super(CiTestCase, self).setUp()
- self.mocklog = mock.MagicMock()
+ with_logs = True
def test_none_returns_default(self):
"""If None is passed as perms, then default should be returned."""
default = object()
- found = decode_perms(None, default, self.mocklog)
+ found = decode_perms(None, default, self.logger)
self.assertEqual(default, found)
def test_integer(self):
"""A valid integer should return itself."""
- found = decode_perms(0o755, None, self.mocklog)
+ found = decode_perms(0o755, None, self.logger)
self.assertEqual(0o755, found)
def test_valid_octal_string(self):
"""A string should be read as octal."""
- found = decode_perms("644", None, self.mocklog)
+ found = decode_perms("644", None, self.logger)
self.assertEqual(0o644, found)
def test_invalid_octal_string_returns_default_and_warns(self):
"""A string with invalid octal should warn and return default."""
- found = decode_perms("999", None, self.mocklog)
+ found = decode_perms("999", None, self.logger)
self.assertIsNone(found)
- warnings = self.mocklog.warning.call_args_list
- self.assertEqual(1, len(warnings))
- self.assertIn("Undecodable", warnings[0][0][0])
+ self.assertEqual(
+ "WARNING: Undecodable permissions '999', returning default None\n",
+ self.logs.getvalue())
def _gzip_bytes(data):
|