Merge lp:~chad.smith/curtin/common-ci-test-case into lp:~curtin-dev/curtin/trunk
- common-ci-test-case
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 519 |
Proposed branch: | lp:~chad.smith/curtin/common-ci-test-case |
Merge into: | lp:~curtin-dev/curtin/trunk |
Diff against target: |
1483 lines (+247/-347) 24 files modified
tests/unittests/helpers.py (+36/-0) tests/unittests/test_apt_custom_sources_list.py (+3/-6) tests/unittests/test_apt_source.py (+4/-7) tests/unittests/test_basic.py (+4/-4) tests/unittests/test_block.py (+20/-36) tests/unittests/test_block_iscsi.py (+6/-18) tests/unittests/test_block_lvm.py (+2/-2) tests/unittests/test_block_mdadm.py (+10/-22) tests/unittests/test_block_mkfs.py (+2/-2) tests/unittests/test_clear_holders.py (+5/-5) tests/unittests/test_commands_apply_net.py (+8/-20) tests/unittests/test_commands_block_meta.py (+6/-19) tests/unittests/test_commands_install.py (+4/-4) tests/unittests/test_config.py (+6/-6) tests/unittests/test_curthooks.py (+21/-46) tests/unittests/test_feature.py (+2/-2) tests/unittests/test_gpg.py (+4/-4) tests/unittests/test_make_dname.py (+4/-4) tests/unittests/test_net.py (+8/-14) tests/unittests/test_partitioning.py (+4/-3) tests/unittests/test_public.py (+4/-4) tests/unittests/test_reporter.py (+29/-38) tests/unittests/test_util.py (+48/-62) tests/unittests/test_version.py (+7/-19) |
To merge this branch: | bzr merge lp:~chad.smith/curtin/common-ci-test-case |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Server Team CI bot | continuous-integration | Approve | |
curtin developers | Pending | ||
Review via email: mp+328477@code.launchpad.net |
Commit message
tests: Add CiTestCase common parent for all curtin tests
This branch makes sure all unittests subclass from CiTestCase which provides all unit tests with an add_patch method for mocking as well as tmp_dir and tmp_path creation.
Drop any unittest-specific tempfile setup in favor of self.tmp_dir and self.tmp_path.
Also drop any duplicate add_patch method definitions and convert any mock start/stop logic to add_patch where possible.
Description of the change
tests: Add CiTestCase common parent for all curtin tests
This branch makes sure all unittests subclass from CiTestCase which provides all unit tests with an add_patch method for mocking as well as tmp_dir and tmp_path creation.
Drop any unittest-specific tempfile setup in favor of self.tmp_dir and self.tmp_path.
Also drop any duplicate add_patch method definitions and convert any mock start/stop logic to add_patch where possible.
Server Team CI bot (server-team-bot) wrote : | # |
Ryan Harper (raharper) wrote : | # |
Thanks for starting this.
I'd suggest also adding in the add_patch() which is repeated in many of the base classes in the unittests. It's fine if we punt that to a second MP after this lands as well.
Overall looks fine, couple of questions in line.
Scott Moser (smoser) wrote : | # |
responded to ryan's comment in line. lets drop the functools.
- 518. By Chad Smith
-
drop functools partial as it is unneeded
Chad Smith (chad.smith) : | # |
Server Team CI bot (server-team-bot) wrote : | # |
PASSED: Continuous integration, rev:518
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
- 519. By Chad Smith
-
move add_patch up into CiTestCase, drop all add_patch definitions in subclasses. Convert any locally defined mock start/stop definitions to use add_patch
- 520. By Chad Smith
-
add missing super...setUp calls to classes which have overridden the unittest.setUp method
Server Team CI bot (server-team-bot) wrote : | # |
FAILED: Continuous integration, rev:520
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Ryan Harper (raharper) wrote : | # |
Looks good once you make tox happy
- 521. By Chad Smith
-
allow kwargs passed into CiTestCase.
add_patch per review comments
Server Team CI bot (server-team-bot) wrote : | # |
PASSED: Continuous integration, rev:521
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'tests/unittests/helpers.py' | |||
2 | --- tests/unittests/helpers.py 2016-11-30 22:57:10 +0000 | |||
3 | +++ tests/unittests/helpers.py 2017-08-03 19:32:06 +0000 | |||
4 | @@ -19,6 +19,10 @@ | |||
5 | 19 | import imp | 19 | import imp |
6 | 20 | import importlib | 20 | import importlib |
7 | 21 | import mock | 21 | import mock |
8 | 22 | import os | ||
9 | 23 | import shutil | ||
10 | 24 | import tempfile | ||
11 | 25 | from unittest import TestCase | ||
12 | 22 | 26 | ||
13 | 23 | 27 | ||
14 | 24 | def builtin_module_name(): | 28 | def builtin_module_name(): |
15 | @@ -43,3 +47,35 @@ | |||
16 | 43 | m_patch = '{}.open'.format(mod_name) | 47 | m_patch = '{}.open'.format(mod_name) |
17 | 44 | with mock.patch(m_patch, m_open, create=True): | 48 | with mock.patch(m_patch, m_open, create=True): |
18 | 45 | yield m_open | 49 | yield m_open |
19 | 50 | |||
20 | 51 | |||
21 | 52 | class CiTestCase(TestCase): | ||
22 | 53 | """Common testing class which all curtin unit tests subclass.""" | ||
23 | 54 | |||
24 | 55 | def add_patch(self, target, attr, **kwargs): | ||
25 | 56 | """Patches specified target object and sets it as attr on test | ||
26 | 57 | instance also schedules cleanup""" | ||
27 | 58 | if 'autospec' not in kwargs: | ||
28 | 59 | kwargs['autospec'] = True | ||
29 | 60 | m = mock.patch(target, **kwargs) | ||
30 | 61 | p = m.start() | ||
31 | 62 | self.addCleanup(m.stop) | ||
32 | 63 | setattr(self, attr, p) | ||
33 | 64 | |||
34 | 65 | def tmp_dir(self, dir=None, cleanup=True): | ||
35 | 66 | """Return a full path to a temporary directory for the test run.""" | ||
36 | 67 | if dir is None: | ||
37 | 68 | tmpd = tempfile.mkdtemp( | ||
38 | 69 | prefix="curtin-ci-%s." % self.__class__.__name__) | ||
39 | 70 | else: | ||
40 | 71 | tmpd = tempfile.mkdtemp(dir=dir) | ||
41 | 72 | self.addCleanup(shutil.rmtree, tmpd) | ||
42 | 73 | return tmpd | ||
43 | 74 | |||
44 | 75 | def tmp_path(self, path, _dir=None): | ||
45 | 76 | # return an absolute path to 'path' under dir. | ||
46 | 77 | # if dir is None, one will be created with tmp_dir() | ||
47 | 78 | # the file is not created or modified. | ||
48 | 79 | if _dir is None: | ||
49 | 80 | _dir = self.tmp_dir() | ||
50 | 81 | return os.path.normpath(os.path.abspath(os.path.join(_dir, path))) | ||
51 | 46 | 82 | ||
52 | === modified file 'tests/unittests/test_apt_custom_sources_list.py' | |||
53 | --- tests/unittests/test_apt_custom_sources_list.py 2016-07-29 10:27:20 +0000 | |||
54 | +++ tests/unittests/test_apt_custom_sources_list.py 2017-08-03 19:32:06 +0000 | |||
55 | @@ -3,10 +3,7 @@ | |||
56 | 3 | """ | 3 | """ |
57 | 4 | import logging | 4 | import logging |
58 | 5 | import os | 5 | import os |
59 | 6 | import shutil | ||
60 | 7 | import tempfile | ||
61 | 8 | 6 | ||
62 | 9 | from unittest import TestCase | ||
63 | 10 | 7 | ||
64 | 11 | import yaml | 8 | import yaml |
65 | 12 | import mock | 9 | import mock |
66 | @@ -14,6 +11,7 @@ | |||
67 | 14 | 11 | ||
68 | 15 | from curtin import util | 12 | from curtin import util |
69 | 16 | from curtin.commands import apt_config | 13 | from curtin.commands import apt_config |
70 | 14 | from .helpers import CiTestCase | ||
71 | 17 | 15 | ||
72 | 18 | LOG = logging.getLogger(__name__) | 16 | LOG = logging.getLogger(__name__) |
73 | 19 | 17 | ||
74 | @@ -85,12 +83,11 @@ | |||
75 | 85 | """) | 83 | """) |
76 | 86 | 84 | ||
77 | 87 | 85 | ||
79 | 88 | class TestAptSourceConfigSourceList(TestCase): | 86 | class TestAptSourceConfigSourceList(CiTestCase): |
80 | 89 | """TestAptSourceConfigSourceList - Class to test sources list rendering""" | 87 | """TestAptSourceConfigSourceList - Class to test sources list rendering""" |
81 | 90 | def setUp(self): | 88 | def setUp(self): |
82 | 91 | super(TestAptSourceConfigSourceList, self).setUp() | 89 | super(TestAptSourceConfigSourceList, self).setUp() |
85 | 92 | self.new_root = tempfile.mkdtemp() | 90 | self.new_root = self.tmp_dir() |
84 | 93 | self.addCleanup(shutil.rmtree, self.new_root) | ||
86 | 94 | # self.patchUtils(self.new_root) | 91 | # self.patchUtils(self.new_root) |
87 | 95 | 92 | ||
88 | 96 | @staticmethod | 93 | @staticmethod |
89 | 97 | 94 | ||
90 | === modified file 'tests/unittests/test_apt_source.py' | |||
91 | --- tests/unittests/test_apt_source.py 2017-02-09 19:59:11 +0000 | |||
92 | +++ tests/unittests/test_apt_source.py 2017-08-03 19:32:06 +0000 | |||
93 | @@ -4,11 +4,8 @@ | |||
94 | 4 | import glob | 4 | import glob |
95 | 5 | import os | 5 | import os |
96 | 6 | import re | 6 | import re |
97 | 7 | import shutil | ||
98 | 8 | import socket | 7 | import socket |
99 | 9 | import tempfile | ||
100 | 10 | 8 | ||
101 | 11 | from unittest import TestCase | ||
102 | 12 | 9 | ||
103 | 13 | import mock | 10 | import mock |
104 | 14 | from mock import call | 11 | from mock import call |
105 | @@ -16,6 +13,7 @@ | |||
106 | 16 | from curtin import util | 13 | from curtin import util |
107 | 17 | from curtin import gpg | 14 | from curtin import gpg |
108 | 18 | from curtin.commands import apt_config | 15 | from curtin.commands import apt_config |
109 | 16 | from .helpers import CiTestCase | ||
110 | 19 | 17 | ||
111 | 20 | 18 | ||
112 | 21 | EXPECTEDKEY = u"""-----BEGIN PGP PUBLIC KEY BLOCK----- | 19 | EXPECTEDKEY = u"""-----BEGIN PGP PUBLIC KEY BLOCK----- |
113 | @@ -62,14 +60,13 @@ | |||
114 | 62 | ChrootableTargetStr = "curtin.commands.apt_config.util.ChrootableTarget" | 60 | ChrootableTargetStr = "curtin.commands.apt_config.util.ChrootableTarget" |
115 | 63 | 61 | ||
116 | 64 | 62 | ||
118 | 65 | class TestAptSourceConfig(TestCase): | 63 | class TestAptSourceConfig(CiTestCase): |
119 | 66 | """ TestAptSourceConfig | 64 | """ TestAptSourceConfig |
120 | 67 | Main Class to test apt configs | 65 | Main Class to test apt configs |
121 | 68 | """ | 66 | """ |
122 | 69 | def setUp(self): | 67 | def setUp(self): |
123 | 70 | super(TestAptSourceConfig, self).setUp() | 68 | super(TestAptSourceConfig, self).setUp() |
126 | 71 | self.tmp = tempfile.mkdtemp() | 69 | self.tmp = self.tmp_dir() |
125 | 72 | self.addCleanup(shutil.rmtree, self.tmp) | ||
127 | 73 | self.aptlistfile = os.path.join(self.tmp, "single-deb.list") | 70 | self.aptlistfile = os.path.join(self.tmp, "single-deb.list") |
128 | 74 | self.aptlistfile2 = os.path.join(self.tmp, "single-deb2.list") | 71 | self.aptlistfile2 = os.path.join(self.tmp, "single-deb2.list") |
129 | 75 | self.aptlistfile3 = os.path.join(self.tmp, "single-deb3.list") | 72 | self.aptlistfile3 = os.path.join(self.tmp, "single-deb3.list") |
130 | @@ -930,7 +927,7 @@ | |||
131 | 930 | orig, apt_config.disable_suites(["proposed"], orig, rel)) | 927 | orig, apt_config.disable_suites(["proposed"], orig, rel)) |
132 | 931 | 928 | ||
133 | 932 | 929 | ||
135 | 933 | class TestDebconfSelections(TestCase): | 930 | class TestDebconfSelections(CiTestCase): |
136 | 934 | 931 | ||
137 | 935 | @mock.patch("curtin.commands.apt_config.debconf_set_selections") | 932 | @mock.patch("curtin.commands.apt_config.debconf_set_selections") |
138 | 936 | def test_no_set_sel_if_none_to_set(self, m_set_sel): | 933 | def test_no_set_sel_if_none_to_set(self, m_set_sel): |
139 | 937 | 934 | ||
140 | === modified file 'tests/unittests/test_basic.py' | |||
141 | --- tests/unittests/test_basic.py 2013-07-29 19:59:51 +0000 | |||
142 | +++ tests/unittests/test_basic.py 2017-08-03 19:32:06 +0000 | |||
143 | @@ -1,7 +1,7 @@ | |||
148 | 1 | from unittest import TestCase | 1 | from .helpers import CiTestCase |
149 | 2 | 2 | ||
150 | 3 | 3 | ||
151 | 4 | class TestImport(TestCase): | 4 | class TestImport(CiTestCase): |
152 | 5 | def test_import(self): | 5 | def test_import(self): |
153 | 6 | import curtin | 6 | import curtin |
154 | 7 | self.assertFalse(getattr(curtin, 'BOGUS_ENTRY', None)) | 7 | self.assertFalse(getattr(curtin, 'BOGUS_ENTRY', None)) |
155 | 8 | 8 | ||
156 | === modified file 'tests/unittests/test_block.py' | |||
157 | --- tests/unittests/test_block.py 2017-05-22 20:10:23 +0000 | |||
158 | +++ tests/unittests/test_block.py 2017-08-03 19:32:06 +0000 | |||
159 | @@ -1,19 +1,16 @@ | |||
160 | 1 | from unittest import TestCase | ||
161 | 2 | import functools | 1 | import functools |
162 | 3 | import os | 2 | import os |
163 | 4 | import mock | 3 | import mock |
164 | 5 | import tempfile | ||
165 | 6 | import shutil | ||
166 | 7 | import sys | 4 | import sys |
167 | 8 | 5 | ||
168 | 9 | from collections import OrderedDict | 6 | from collections import OrderedDict |
169 | 10 | 7 | ||
171 | 11 | from .helpers import simple_mocked_open | 8 | from .helpers import CiTestCase, simple_mocked_open |
172 | 12 | from curtin import util | 9 | from curtin import util |
173 | 13 | from curtin import block | 10 | from curtin import block |
174 | 14 | 11 | ||
175 | 15 | 12 | ||
177 | 16 | class TestBlock(TestCase): | 13 | class TestBlock(CiTestCase): |
178 | 17 | 14 | ||
179 | 18 | @mock.patch("curtin.block.util") | 15 | @mock.patch("curtin.block.util") |
180 | 19 | def test_get_volume_uuid(self, mock_util): | 16 | def test_get_volume_uuid(self, mock_util): |
181 | @@ -103,7 +100,7 @@ | |||
182 | 103 | block.lookup_disk(serial) | 100 | block.lookup_disk(serial) |
183 | 104 | 101 | ||
184 | 105 | 102 | ||
186 | 106 | class TestSysBlockPath(TestCase): | 103 | class TestSysBlockPath(CiTestCase): |
187 | 107 | @mock.patch("curtin.block.get_blockdev_for_partition") | 104 | @mock.patch("curtin.block.get_blockdev_for_partition") |
188 | 108 | @mock.patch("os.path.exists") | 105 | @mock.patch("os.path.exists") |
189 | 109 | def test_existing_valid_devname(self, m_os_path_exists, m_get_blk): | 106 | def test_existing_valid_devname(self, m_os_path_exists, m_get_blk): |
190 | @@ -177,19 +174,13 @@ | |||
191 | 177 | block.sys_block_path('/dev/cciss/c0d0p1')) | 174 | block.sys_block_path('/dev/cciss/c0d0p1')) |
192 | 178 | 175 | ||
193 | 179 | 176 | ||
195 | 180 | class TestWipeFile(TestCase): | 177 | class TestWipeFile(CiTestCase): |
196 | 181 | def __init__(self, *args, **kwargs): | 178 | def __init__(self, *args, **kwargs): |
197 | 182 | super(TestWipeFile, self).__init__(*args, **kwargs) | 179 | super(TestWipeFile, self).__init__(*args, **kwargs) |
198 | 183 | 180 | ||
199 | 184 | def tfile(self, *args): | ||
200 | 185 | # return a temp file in a dir that will be cleaned up | ||
201 | 186 | tmpdir = tempfile.mkdtemp() | ||
202 | 187 | self.addCleanup(shutil.rmtree, tmpdir) | ||
203 | 188 | return os.path.sep.join([tmpdir] + list(args)) | ||
204 | 189 | |||
205 | 190 | def test_non_exist_raises_file_not_found(self): | 181 | def test_non_exist_raises_file_not_found(self): |
206 | 191 | try: | 182 | try: |
208 | 192 | p = self.tfile("enofile") | 183 | p = self.tmp_path("enofile") |
209 | 193 | block.wipe_file(p) | 184 | block.wipe_file(p) |
210 | 194 | raise Exception("%s did not raise exception" % p) | 185 | raise Exception("%s did not raise exception" % p) |
211 | 195 | except Exception as e: | 186 | except Exception as e: |
212 | @@ -198,7 +189,7 @@ | |||
213 | 198 | 189 | ||
214 | 199 | def test_non_exist_dir_raises_file_not_found(self): | 190 | def test_non_exist_dir_raises_file_not_found(self): |
215 | 200 | try: | 191 | try: |
217 | 201 | p = self.tfile("enodir", "file") | 192 | p = self.tmp_path(os.path.sep.join(["enodir", "file"])) |
218 | 202 | block.wipe_file(p) | 193 | block.wipe_file(p) |
219 | 203 | raise Exception("%s did not raise exception" % p) | 194 | raise Exception("%s did not raise exception" % p) |
220 | 204 | except Exception as e: | 195 | except Exception as e: |
221 | @@ -207,7 +198,7 @@ | |||
222 | 207 | 198 | ||
223 | 208 | def test_default_is_zero(self): | 199 | def test_default_is_zero(self): |
224 | 209 | flen = 1024 | 200 | flen = 1024 |
226 | 210 | myfile = self.tfile("def_zero") | 201 | myfile = self.tmp_path("def_zero") |
227 | 211 | util.write_file(myfile, flen * b'\1', omode="wb") | 202 | util.write_file(myfile, flen * b'\1', omode="wb") |
228 | 212 | block.wipe_file(myfile) | 203 | block.wipe_file(myfile) |
229 | 213 | found = util.load_file(myfile, decode=False) | 204 | found = util.load_file(myfile, decode=False) |
230 | @@ -219,7 +210,7 @@ | |||
231 | 219 | def reader(size): | 210 | def reader(size): |
232 | 220 | return size * b'\1' | 211 | return size * b'\1' |
233 | 221 | 212 | ||
235 | 222 | myfile = self.tfile("reader_used") | 213 | myfile = self.tmp_path("reader_used") |
236 | 223 | # populate with nulls | 214 | # populate with nulls |
237 | 224 | util.write_file(myfile, flen * b'\0', omode="wb") | 215 | util.write_file(myfile, flen * b'\0', omode="wb") |
238 | 225 | block.wipe_file(myfile, reader=reader, buflen=flen) | 216 | block.wipe_file(myfile, reader=reader, buflen=flen) |
239 | @@ -236,15 +227,15 @@ | |||
240 | 236 | data['x'] = data['x'][size:] | 227 | data['x'] = data['x'][size:] |
241 | 237 | return buf | 228 | return buf |
242 | 238 | 229 | ||
244 | 239 | myfile = self.tfile("reader_twice") | 230 | myfile = self.tmp_path("reader_twice") |
245 | 240 | util.write_file(myfile, flen * b'\xff', omode="wb") | 231 | util.write_file(myfile, flen * b'\xff', omode="wb") |
246 | 241 | block.wipe_file(myfile, reader=reader, buflen=20) | 232 | block.wipe_file(myfile, reader=reader, buflen=20) |
247 | 242 | found = util.load_file(myfile, decode=False) | 233 | found = util.load_file(myfile, decode=False) |
248 | 243 | self.assertEqual(found, expected) | 234 | self.assertEqual(found, expected) |
249 | 244 | 235 | ||
250 | 245 | def test_reader_fhandle(self): | 236 | def test_reader_fhandle(self): |
253 | 246 | srcfile = self.tfile("fhandle_src") | 237 | srcfile = self.tmp_path("fhandle_src") |
254 | 247 | trgfile = self.tfile("fhandle_trg") | 238 | trgfile = self.tmp_path("fhandle_trg") |
255 | 248 | data = '\n'.join(["this is source file." for f in range(0, 10)] + []) | 239 | data = '\n'.join(["this is source file." for f in range(0, 10)] + []) |
256 | 249 | util.write_file(srcfile, data) | 240 | util.write_file(srcfile, data) |
257 | 250 | util.write_file(trgfile, 'a' * len(data)) | 241 | util.write_file(trgfile, 'a' * len(data)) |
258 | @@ -254,7 +245,7 @@ | |||
259 | 254 | self.assertEqual(data, found) | 245 | self.assertEqual(data, found) |
260 | 255 | 246 | ||
261 | 256 | def test_exclusive_open_raise_missing(self): | 247 | def test_exclusive_open_raise_missing(self): |
263 | 257 | myfile = self.tfile("no-such-file") | 248 | myfile = self.tmp_path("no-such-file") |
264 | 258 | 249 | ||
265 | 259 | with self.assertRaises(ValueError): | 250 | with self.assertRaises(ValueError): |
266 | 260 | with block.exclusive_open(myfile) as fp: | 251 | with block.exclusive_open(myfile) as fp: |
267 | @@ -265,7 +256,7 @@ | |||
268 | 265 | @mock.patch('os.open') | 256 | @mock.patch('os.open') |
269 | 266 | def test_exclusive_open(self, mock_os_open, mock_os_fdopen, mock_os_close): | 257 | def test_exclusive_open(self, mock_os_open, mock_os_fdopen, mock_os_close): |
270 | 267 | flen = 1024 | 258 | flen = 1024 |
272 | 268 | myfile = self.tfile("my_exclusive_file") | 259 | myfile = self.tmp_path("my_exclusive_file") |
273 | 269 | util.write_file(myfile, flen * b'\1', omode="wb") | 260 | util.write_file(myfile, flen * b'\1', omode="wb") |
274 | 270 | mock_fd = 3 | 261 | mock_fd = 3 |
275 | 271 | mock_os_open.return_value = mock_fd | 262 | mock_os_open.return_value = mock_fd |
276 | @@ -288,7 +279,7 @@ | |||
277 | 288 | mock_os_close, | 279 | mock_os_close, |
278 | 289 | mock_util_fuser): | 280 | mock_util_fuser): |
279 | 290 | flen = 1024 | 281 | flen = 1024 |
281 | 291 | myfile = self.tfile("my_exclusive_file") | 282 | myfile = self.tmp_path("my_exclusive_file") |
282 | 292 | util.write_file(myfile, flen * b'\1', omode="wb") | 283 | util.write_file(myfile, flen * b'\1', omode="wb") |
283 | 293 | mock_os_open.side_effect = OSError("NO_O_EXCL") | 284 | mock_os_open.side_effect = OSError("NO_O_EXCL") |
284 | 294 | mock_holders.return_value = ['md1'] | 285 | mock_holders.return_value = ['md1'] |
285 | @@ -310,7 +301,7 @@ | |||
286 | 310 | def test_exclusive_open_fdopen_failure(self, mock_os_open, | 301 | def test_exclusive_open_fdopen_failure(self, mock_os_open, |
287 | 311 | mock_os_fdopen, mock_os_close): | 302 | mock_os_fdopen, mock_os_close): |
288 | 312 | flen = 1024 | 303 | flen = 1024 |
290 | 313 | myfile = self.tfile("my_exclusive_file") | 304 | myfile = self.tmp_path("my_exclusive_file") |
291 | 314 | util.write_file(myfile, flen * b'\1', omode="wb") | 305 | util.write_file(myfile, flen * b'\1', omode="wb") |
292 | 315 | mock_fd = 3 | 306 | mock_fd = 3 |
293 | 316 | mock_os_open.return_value = mock_fd | 307 | mock_os_open.return_value = mock_fd |
294 | @@ -328,7 +319,7 @@ | |||
295 | 328 | self.assertEqual([], mock_os_close.call_args_list) | 319 | self.assertEqual([], mock_os_close.call_args_list) |
296 | 329 | 320 | ||
297 | 330 | 321 | ||
299 | 331 | class TestWipeVolume(TestCase): | 322 | class TestWipeVolume(CiTestCase): |
300 | 332 | dev = '/dev/null' | 323 | dev = '/dev/null' |
301 | 333 | 324 | ||
302 | 334 | @mock.patch('curtin.block.lvm') | 325 | @mock.patch('curtin.block.lvm') |
303 | @@ -366,7 +357,7 @@ | |||
304 | 366 | block.wipe_volume(self.dev, mode='invalidmode') | 357 | block.wipe_volume(self.dev, mode='invalidmode') |
305 | 367 | 358 | ||
306 | 368 | 359 | ||
308 | 369 | class TestBlockKnames(TestCase): | 360 | class TestBlockKnames(CiTestCase): |
309 | 370 | """Tests for some of the kname functions in block""" | 361 | """Tests for some of the kname functions in block""" |
310 | 371 | def test_determine_partition_kname(self): | 362 | def test_determine_partition_kname(self): |
311 | 372 | part_knames = [(('sda', 1), 'sda1'), | 363 | part_knames = [(('sda', 1), 'sda1'), |
312 | @@ -430,7 +421,7 @@ | |||
313 | 430 | block.kname_to_path(kname) | 421 | block.kname_to_path(kname) |
314 | 431 | 422 | ||
315 | 432 | 423 | ||
317 | 433 | class TestPartTableSignature(TestCase): | 424 | class TestPartTableSignature(CiTestCase): |
318 | 434 | blockdev = '/dev/null' | 425 | blockdev = '/dev/null' |
319 | 435 | dos_content = b'\x00' * 0x1fe + b'\x55\xAA' + b'\x00' * 0xf00 | 426 | dos_content = b'\x00' * 0x1fe + b'\x55\xAA' + b'\x00' * 0xf00 |
320 | 436 | gpt_content = b'\x00' * 0x200 + b'EFI PART' + b'\x00' * (0x200 - 8) | 427 | gpt_content = b'\x00' * 0x200 + b'EFI PART' + b'\x00' * (0x200 - 8) |
321 | @@ -493,7 +484,7 @@ | |||
322 | 493 | block.check_efi_signature(self.blockdev)) | 484 | block.check_efi_signature(self.blockdev)) |
323 | 494 | 485 | ||
324 | 495 | 486 | ||
326 | 496 | class TestNonAscii(TestCase): | 487 | class TestNonAscii(CiTestCase): |
327 | 497 | @mock.patch('curtin.block.util.subp') | 488 | @mock.patch('curtin.block.util.subp') |
328 | 498 | def test_lsblk(self, mock_subp): | 489 | def test_lsblk(self, mock_subp): |
329 | 499 | # lsblk can write non-ascii data, causing shlex to blow up | 490 | # lsblk can write non-ascii data, causing shlex to blow up |
330 | @@ -519,14 +510,7 @@ | |||
331 | 519 | block.blkid() | 510 | block.blkid() |
332 | 520 | 511 | ||
333 | 521 | 512 | ||
342 | 522 | class TestSlaveKnames(TestCase): | 513 | class TestSlaveKnames(CiTestCase): |
335 | 523 | def add_patch(self, target, attr, autospec=True): | ||
336 | 524 | """Patches specified target object and sets it as attr on test | ||
337 | 525 | instance also schedules cleanup""" | ||
338 | 526 | m = mock.patch(target, autospec=autospec) | ||
339 | 527 | p = m.start() | ||
340 | 528 | self.addCleanup(m.stop) | ||
341 | 529 | setattr(self, attr, p) | ||
343 | 530 | 514 | ||
344 | 531 | def setUp(self): | 515 | def setUp(self): |
345 | 532 | super(TestSlaveKnames, self).setUp() | 516 | super(TestSlaveKnames, self).setUp() |
346 | 533 | 517 | ||
347 | === modified file 'tests/unittests/test_block_iscsi.py' | |||
348 | --- tests/unittests/test_block_iscsi.py 2017-05-12 20:20:02 +0000 | |||
349 | +++ tests/unittests/test_block_iscsi.py 2017-08-03 19:32:06 +0000 | |||
350 | @@ -1,23 +1,11 @@ | |||
351 | 1 | import mock | 1 | import mock |
352 | 2 | 2 | ||
353 | 3 | from unittest import TestCase | ||
354 | 4 | from curtin.block import iscsi | 3 | from curtin.block import iscsi |
371 | 5 | 4 | from .helpers import CiTestCase | |
372 | 6 | 5 | ||
373 | 7 | class IscsiTestBase(TestCase): | 6 | |
374 | 8 | def setUp(self): | 7 | class TestBlockIscsiPortalParsing(CiTestCase): |
375 | 9 | super(IscsiTestBase, self).setUp() | 8 | |
360 | 10 | |||
361 | 11 | def add_patch(self, target, attr): | ||
362 | 12 | """Patches specified target object and sets it as attr on test | ||
363 | 13 | instance also schedules cleanup""" | ||
364 | 14 | m = mock.patch(target, autospec=True) | ||
365 | 15 | p = m.start() | ||
366 | 16 | self.addCleanup(m.stop) | ||
367 | 17 | setattr(self, attr, p) | ||
368 | 18 | |||
369 | 19 | |||
370 | 20 | class TestBlockIscsiPortalParsing(IscsiTestBase): | ||
376 | 21 | def test_iscsi_portal_parsing_string(self): | 9 | def test_iscsi_portal_parsing_string(self): |
377 | 22 | with self.assertRaisesRegexp(ValueError, 'not a string'): | 10 | with self.assertRaisesRegexp(ValueError, 'not a string'): |
378 | 23 | iscsi.assert_valid_iscsi_portal(1234) | 11 | iscsi.assert_valid_iscsi_portal(1234) |
379 | @@ -490,7 +478,7 @@ | |||
380 | 490 | self.assertEquals(i.target, 'iqn.2017-04.com.example.test:target-name') | 478 | self.assertEquals(i.target, 'iqn.2017-04.com.example.test:target-name') |
381 | 491 | 479 | ||
382 | 492 | 480 | ||
384 | 493 | class TestBlockIscsiVolPath(IscsiTestBase): | 481 | class TestBlockIscsiVolPath(CiTestCase): |
385 | 494 | # non-iscsi backed disk returns false | 482 | # non-iscsi backed disk returns false |
386 | 495 | # regular iscsi-backed disk returns true | 483 | # regular iscsi-backed disk returns true |
387 | 496 | # layered setup without an iscsi member returns false | 484 | # layered setup without an iscsi member returns false |
388 | 497 | 485 | ||
389 | === modified file 'tests/unittests/test_block_lvm.py' | |||
390 | --- tests/unittests/test_block_lvm.py 2016-08-15 14:52:56 +0000 | |||
391 | +++ tests/unittests/test_block_lvm.py 2017-08-03 19:32:06 +0000 | |||
392 | @@ -1,10 +1,10 @@ | |||
393 | 1 | from curtin.block import lvm | 1 | from curtin.block import lvm |
394 | 2 | 2 | ||
396 | 3 | from unittest import TestCase | 3 | from .helpers import CiTestCase |
397 | 4 | import mock | 4 | import mock |
398 | 5 | 5 | ||
399 | 6 | 6 | ||
401 | 7 | class TestBlockLvm(TestCase): | 7 | class TestBlockLvm(CiTestCase): |
402 | 8 | vg_name = 'ubuntu-volgroup' | 8 | vg_name = 'ubuntu-volgroup' |
403 | 9 | 9 | ||
404 | 10 | @mock.patch('curtin.block.lvm.util') | 10 | @mock.patch('curtin.block.lvm.util') |
405 | 11 | 11 | ||
406 | === modified file 'tests/unittests/test_block_mdadm.py' | |||
407 | --- tests/unittests/test_block_mdadm.py 2017-05-08 20:38:48 +0000 | |||
408 | +++ tests/unittests/test_block_mdadm.py 2017-08-03 19:32:06 +0000 | |||
409 | @@ -1,27 +1,15 @@ | |||
410 | 1 | from unittest import TestCase | ||
411 | 2 | from mock import call, patch | 1 | from mock import call, patch |
412 | 3 | from curtin.block import dev_short | 2 | from curtin.block import dev_short |
413 | 4 | from curtin.block import mdadm | 3 | from curtin.block import mdadm |
414 | 5 | from curtin import util | 4 | from curtin import util |
415 | 5 | from .helpers import CiTestCase | ||
416 | 6 | import os | 6 | import os |
417 | 7 | import subprocess | 7 | import subprocess |
418 | 8 | import textwrap | 8 | import textwrap |
419 | 9 | 9 | ||
420 | 10 | 10 | ||
435 | 11 | class MdadmTestBase(TestCase): | 11 | class TestBlockMdadmAssemble(CiTestCase): |
436 | 12 | def setUp(self): | 12 | |
423 | 13 | super(MdadmTestBase, self).setUp() | ||
424 | 14 | |||
425 | 15 | def add_patch(self, target, attr): | ||
426 | 16 | """Patches specified target object and sets it as attr on test | ||
427 | 17 | instance also schedules cleanup""" | ||
428 | 18 | m = patch(target, autospec=True) | ||
429 | 19 | p = m.start() | ||
430 | 20 | self.addCleanup(m.stop) | ||
431 | 21 | setattr(self, attr, p) | ||
432 | 22 | |||
433 | 23 | |||
434 | 24 | class TestBlockMdadmAssemble(MdadmTestBase): | ||
437 | 25 | def setUp(self): | 13 | def setUp(self): |
438 | 26 | super(TestBlockMdadmAssemble, self).setUp() | 14 | super(TestBlockMdadmAssemble, self).setUp() |
439 | 27 | self.add_patch('curtin.block.mdadm.util', 'mock_util') | 15 | self.add_patch('curtin.block.mdadm.util', 'mock_util') |
440 | @@ -94,7 +82,7 @@ | |||
441 | 94 | rcs=[0, 1, 2]) | 82 | rcs=[0, 1, 2]) |
442 | 95 | 83 | ||
443 | 96 | 84 | ||
445 | 97 | class TestBlockMdadmCreate(MdadmTestBase): | 85 | class TestBlockMdadmCreate(CiTestCase): |
446 | 98 | def setUp(self): | 86 | def setUp(self): |
447 | 99 | super(TestBlockMdadmCreate, self).setUp() | 87 | super(TestBlockMdadmCreate, self).setUp() |
448 | 100 | self.add_patch('curtin.block.mdadm.util', 'mock_util') | 88 | self.add_patch('curtin.block.mdadm.util', 'mock_util') |
449 | @@ -243,7 +231,7 @@ | |||
450 | 243 | self.mock_util.subp.assert_has_calls(expected_calls) | 231 | self.mock_util.subp.assert_has_calls(expected_calls) |
451 | 244 | 232 | ||
452 | 245 | 233 | ||
454 | 246 | class TestBlockMdadmExamine(MdadmTestBase): | 234 | class TestBlockMdadmExamine(CiTestCase): |
455 | 247 | def setUp(self): | 235 | def setUp(self): |
456 | 248 | super(TestBlockMdadmExamine, self).setUp() | 236 | super(TestBlockMdadmExamine, self).setUp() |
457 | 249 | self.add_patch('curtin.block.mdadm.util', 'mock_util') | 237 | self.add_patch('curtin.block.mdadm.util', 'mock_util') |
458 | @@ -328,7 +316,7 @@ | |||
459 | 328 | self.assertEqual(data, {}) | 316 | self.assertEqual(data, {}) |
460 | 329 | 317 | ||
461 | 330 | 318 | ||
463 | 331 | class TestBlockMdadmStop(MdadmTestBase): | 319 | class TestBlockMdadmStop(CiTestCase): |
464 | 332 | def setUp(self): | 320 | def setUp(self): |
465 | 333 | super(TestBlockMdadmStop, self).setUp() | 321 | super(TestBlockMdadmStop, self).setUp() |
466 | 334 | self.add_patch('curtin.block.mdadm.util.lsb_release', 'mock_util_lsb') | 322 | self.add_patch('curtin.block.mdadm.util.lsb_release', 'mock_util_lsb') |
467 | @@ -495,7 +483,7 @@ | |||
468 | 495 | self.mock_util_write_file.assert_has_calls(expected_writes) | 483 | self.mock_util_write_file.assert_has_calls(expected_writes) |
469 | 496 | 484 | ||
470 | 497 | 485 | ||
472 | 498 | class TestBlockMdadmRemove(MdadmTestBase): | 486 | class TestBlockMdadmRemove(CiTestCase): |
473 | 499 | def setUp(self): | 487 | def setUp(self): |
474 | 500 | super(TestBlockMdadmRemove, self).setUp() | 488 | super(TestBlockMdadmRemove, self).setUp() |
475 | 501 | self.add_patch('curtin.block.mdadm.util', 'mock_util') | 489 | self.add_patch('curtin.block.mdadm.util', 'mock_util') |
476 | @@ -521,7 +509,7 @@ | |||
477 | 521 | self.mock_util.subp.assert_has_calls(expected_calls) | 509 | self.mock_util.subp.assert_has_calls(expected_calls) |
478 | 522 | 510 | ||
479 | 523 | 511 | ||
481 | 524 | class TestBlockMdadmQueryDetail(MdadmTestBase): | 512 | class TestBlockMdadmQueryDetail(CiTestCase): |
482 | 525 | def setUp(self): | 513 | def setUp(self): |
483 | 526 | super(TestBlockMdadmQueryDetail, self).setUp() | 514 | super(TestBlockMdadmQueryDetail, self).setUp() |
484 | 527 | self.add_patch('curtin.block.mdadm.util', 'mock_util') | 515 | self.add_patch('curtin.block.mdadm.util', 'mock_util') |
485 | @@ -599,7 +587,7 @@ | |||
486 | 599 | '93a73e10:427f280b:b7076c02:204b8f7a') | 587 | '93a73e10:427f280b:b7076c02:204b8f7a') |
487 | 600 | 588 | ||
488 | 601 | 589 | ||
490 | 602 | class TestBlockMdadmDetailScan(MdadmTestBase): | 590 | class TestBlockMdadmDetailScan(CiTestCase): |
491 | 603 | def setUp(self): | 591 | def setUp(self): |
492 | 604 | super(TestBlockMdadmDetailScan, self).setUp() | 592 | super(TestBlockMdadmDetailScan, self).setUp() |
493 | 605 | self.add_patch('curtin.block.mdadm.util', 'mock_util') | 593 | self.add_patch('curtin.block.mdadm.util', 'mock_util') |
494 | @@ -634,7 +622,7 @@ | |||
495 | 634 | self.assertEqual(None, data) | 622 | self.assertEqual(None, data) |
496 | 635 | 623 | ||
497 | 636 | 624 | ||
499 | 637 | class TestBlockMdadmMdHelpers(MdadmTestBase): | 625 | class TestBlockMdadmMdHelpers(CiTestCase): |
500 | 638 | def setUp(self): | 626 | def setUp(self): |
501 | 639 | super(TestBlockMdadmMdHelpers, self).setUp() | 627 | super(TestBlockMdadmMdHelpers, self).setUp() |
502 | 640 | self.add_patch('curtin.block.mdadm.util', 'mock_util') | 628 | self.add_patch('curtin.block.mdadm.util', 'mock_util') |
503 | 641 | 629 | ||
504 | === modified file 'tests/unittests/test_block_mkfs.py' | |||
505 | --- tests/unittests/test_block_mkfs.py 2016-06-30 21:40:28 +0000 | |||
506 | +++ tests/unittests/test_block_mkfs.py 2017-08-03 19:32:06 +0000 | |||
507 | @@ -1,10 +1,10 @@ | |||
508 | 1 | from curtin.block import mkfs | 1 | from curtin.block import mkfs |
509 | 2 | 2 | ||
511 | 3 | from unittest import TestCase | 3 | from .helpers import CiTestCase |
512 | 4 | import mock | 4 | import mock |
513 | 5 | 5 | ||
514 | 6 | 6 | ||
516 | 7 | class TestBlockMkfs(TestCase): | 7 | class TestBlockMkfs(CiTestCase): |
517 | 8 | test_uuid = "fb26cc6c-ae73-11e5-9e38-2fb63f0c3155" | 8 | test_uuid = "fb26cc6c-ae73-11e5-9e38-2fb63f0c3155" |
518 | 9 | 9 | ||
519 | 10 | def _get_config(self, fstype): | 10 | def _get_config(self, fstype): |
520 | 11 | 11 | ||
521 | === modified file 'tests/unittests/test_clear_holders.py' | |||
522 | --- tests/unittests/test_clear_holders.py 2017-05-30 15:27:14 +0000 | |||
523 | +++ tests/unittests/test_clear_holders.py 2017-08-03 19:32:06 +0000 | |||
524 | @@ -1,12 +1,12 @@ | |||
525 | 1 | from unittest import TestCase | ||
526 | 2 | import mock | 1 | import mock |
527 | 3 | |||
528 | 4 | from curtin.block import clear_holders | ||
529 | 5 | import os | 2 | import os |
530 | 6 | import textwrap | 3 | import textwrap |
531 | 7 | 4 | ||
534 | 8 | 5 | from curtin.block import clear_holders | |
535 | 9 | class TestClearHolders(TestCase): | 6 | from .helpers import CiTestCase |
536 | 7 | |||
537 | 8 | |||
538 | 9 | class TestClearHolders(CiTestCase): | ||
539 | 10 | test_blockdev = '/dev/null' | 10 | test_blockdev = '/dev/null' |
540 | 11 | test_syspath = '/sys/class/block/null' | 11 | test_syspath = '/sys/class/block/null' |
541 | 12 | remove_retries = [0.2] * 150 # clear_holders defaults to 30 seconds | 12 | remove_retries = [0.2] * 150 # clear_holders defaults to 30 seconds |
542 | 13 | 13 | ||
543 | === modified file 'tests/unittests/test_commands_apply_net.py' | |||
544 | --- tests/unittests/test_commands_apply_net.py 2017-07-19 14:32:15 +0000 | |||
545 | +++ tests/unittests/test_commands_apply_net.py 2017-08-03 19:32:06 +0000 | |||
546 | @@ -1,26 +1,14 @@ | |||
547 | 1 | from unittest import TestCase | ||
548 | 2 | from mock import patch, call | 1 | from mock import patch, call |
549 | 3 | import copy | 2 | import copy |
550 | 4 | import os | 3 | import os |
551 | 5 | 4 | ||
552 | 6 | from curtin.commands import apply_net | 5 | from curtin.commands import apply_net |
553 | 7 | from curtin import util | 6 | from curtin import util |
570 | 8 | 7 | from .helpers import CiTestCase | |
571 | 9 | 8 | ||
572 | 10 | class ApplyNetTestBase(TestCase): | 9 | |
573 | 11 | def setUp(self): | 10 | class TestApplyNet(CiTestCase): |
574 | 12 | super(ApplyNetTestBase, self).setUp() | 11 | |
559 | 13 | |||
560 | 14 | def add_patch(self, target, attr): | ||
561 | 15 | """Patches specified target object and sets it as attr on test | ||
562 | 16 | instance also schedules cleanup""" | ||
563 | 17 | m = patch(target, autospec=True) | ||
564 | 18 | p = m.start() | ||
565 | 19 | self.addCleanup(m.stop) | ||
566 | 20 | setattr(self, attr, p) | ||
567 | 21 | |||
568 | 22 | |||
569 | 23 | class TestApplyNet(ApplyNetTestBase): | ||
575 | 24 | def setUp(self): | 12 | def setUp(self): |
576 | 25 | super(TestApplyNet, self).setUp() | 13 | super(TestApplyNet, self).setUp() |
577 | 26 | 14 | ||
578 | @@ -150,7 +138,7 @@ | |||
579 | 150 | self.m_ipv6_mtu.assert_called_with(self.target) | 138 | self.m_ipv6_mtu.assert_called_with(self.target) |
580 | 151 | 139 | ||
581 | 152 | 140 | ||
583 | 153 | class TestApplyNetPatchIfupdown(ApplyNetTestBase): | 141 | class TestApplyNetPatchIfupdown(CiTestCase): |
584 | 154 | 142 | ||
585 | 155 | @patch('curtin.util.write_file') | 143 | @patch('curtin.util.write_file') |
586 | 156 | def test_apply_ipv6_mtu_hook(self, mock_write): | 144 | def test_apply_ipv6_mtu_hook(self, mock_write): |
587 | @@ -218,7 +206,7 @@ | |||
588 | 218 | self.assertEqual(0, mock_write.call_count) | 206 | self.assertEqual(0, mock_write.call_count) |
589 | 219 | 207 | ||
590 | 220 | 208 | ||
592 | 221 | class TestApplyNetPatchIpv6Priv(ApplyNetTestBase): | 209 | class TestApplyNetPatchIpv6Priv(CiTestCase): |
593 | 222 | 210 | ||
594 | 223 | @patch('curtin.util.del_file') | 211 | @patch('curtin.util.del_file') |
595 | 224 | @patch('curtin.util.load_file') | 212 | @patch('curtin.util.load_file') |
596 | @@ -274,7 +262,7 @@ | |||
597 | 274 | self.assertEqual(0, mock_load.call_count) | 262 | self.assertEqual(0, mock_load.call_count) |
598 | 275 | 263 | ||
599 | 276 | 264 | ||
601 | 277 | class TestApplyNetRemoveLegacyEth0(ApplyNetTestBase): | 265 | class TestApplyNetRemoveLegacyEth0(CiTestCase): |
602 | 278 | 266 | ||
603 | 279 | @patch('curtin.util.del_file') | 267 | @patch('curtin.util.del_file') |
604 | 280 | @patch('curtin.util.load_file') | 268 | @patch('curtin.util.load_file') |
605 | 281 | 269 | ||
606 | === modified file 'tests/unittests/test_commands_block_meta.py' | |||
607 | --- tests/unittests/test_commands_block_meta.py 2017-03-22 15:34:21 +0000 | |||
608 | +++ tests/unittests/test_commands_block_meta.py 2017-08-03 19:32:06 +0000 | |||
609 | @@ -1,24 +1,11 @@ | |||
610 | 1 | from unittest import TestCase | ||
611 | 2 | from mock import patch, call | 1 | from mock import patch, call |
612 | 3 | from argparse import Namespace | 2 | from argparse import Namespace |
613 | 4 | 3 | ||
614 | 5 | from curtin.commands import block_meta | 4 | from curtin.commands import block_meta |
631 | 6 | 5 | from .helpers import CiTestCase | |
632 | 7 | 6 | ||
633 | 8 | class BlockMetaTestBase(TestCase): | 7 | |
634 | 9 | def setUp(self): | 8 | class TestBlockMetaSimple(CiTestCase): |
619 | 10 | super(BlockMetaTestBase, self).setUp() | ||
620 | 11 | |||
621 | 12 | def add_patch(self, target, attr): | ||
622 | 13 | """Patches specified target object and sets it as attr on test | ||
623 | 14 | instance also schedules cleanup""" | ||
624 | 15 | m = patch(target, autospec=True) | ||
625 | 16 | p = m.start() | ||
626 | 17 | self.addCleanup(m.stop) | ||
627 | 18 | setattr(self, attr, p) | ||
628 | 19 | |||
629 | 20 | |||
630 | 21 | class TestBlockMetaSimple(BlockMetaTestBase): | ||
635 | 22 | def setUp(self): | 9 | def setUp(self): |
636 | 23 | super(TestBlockMetaSimple, self).setUp() | 10 | super(TestBlockMetaSimple, self).setUp() |
637 | 24 | self.target = "my_target" | 11 | self.target = "my_target" |
638 | @@ -120,10 +107,10 @@ | |||
639 | 120 | [call(['mount', devname, self.target])]) | 107 | [call(['mount', devname, self.target])]) |
640 | 121 | 108 | ||
641 | 122 | 109 | ||
643 | 123 | class TestBlockMeta(BlockMetaTestBase): | 110 | class TestBlockMeta(CiTestCase): |
644 | 111 | |||
645 | 124 | def setUp(self): | 112 | def setUp(self): |
646 | 125 | super(TestBlockMeta, self).setUp() | 113 | super(TestBlockMeta, self).setUp() |
647 | 126 | # self.target = tempfile.mkdtemp() | ||
648 | 127 | 114 | ||
649 | 128 | basepath = 'curtin.commands.block_meta.' | 115 | basepath = 'curtin.commands.block_meta.' |
650 | 129 | self.add_patch(basepath + 'get_path_to_storage_volume', 'mock_getpath') | 116 | self.add_patch(basepath + 'get_path_to_storage_volume', 'mock_getpath') |
651 | 130 | 117 | ||
652 | === modified file 'tests/unittests/test_commands_install.py' | |||
653 | --- tests/unittests/test_commands_install.py 2017-07-21 20:57:06 +0000 | |||
654 | +++ tests/unittests/test_commands_install.py 2017-08-03 19:32:06 +0000 | |||
655 | @@ -1,10 +1,10 @@ | |||
656 | 1 | from unittest import TestCase | ||
657 | 2 | import copy | 1 | import copy |
658 | 3 | 2 | ||
659 | 4 | from curtin.commands import install | 3 | from curtin.commands import install |
663 | 5 | 4 | from .helpers import CiTestCase | |
664 | 6 | 5 | ||
665 | 7 | class TestMigrateProxy(TestCase): | 6 | |
666 | 7 | class TestMigrateProxy(CiTestCase): | ||
667 | 8 | def test_legacy_moved_over(self): | 8 | def test_legacy_moved_over(self): |
668 | 9 | """Legacy setting should get moved over.""" | 9 | """Legacy setting should get moved over.""" |
669 | 10 | proxy = "http://my.proxy:3128" | 10 | proxy = "http://my.proxy:3128" |
670 | 11 | 11 | ||
671 | === modified file 'tests/unittests/test_config.py' | |||
672 | --- tests/unittests/test_config.py 2015-09-02 17:17:45 +0000 | |||
673 | +++ tests/unittests/test_config.py 2017-08-03 19:32:06 +0000 | |||
674 | @@ -1,12 +1,12 @@ | |||
675 | 1 | from unittest import TestCase | ||
676 | 2 | import copy | 1 | import copy |
677 | 3 | import json | 2 | import json |
678 | 4 | import textwrap | 3 | import textwrap |
679 | 5 | 4 | ||
680 | 6 | from curtin import config | 5 | from curtin import config |
684 | 7 | 6 | from .helpers import CiTestCase | |
685 | 8 | 7 | ||
686 | 9 | class TestMerge(TestCase): | 8 | |
687 | 9 | class TestMerge(CiTestCase): | ||
688 | 10 | def test_merge_cfg_string(self): | 10 | def test_merge_cfg_string(self): |
689 | 11 | d1 = {'str1': 'str_one'} | 11 | d1 = {'str1': 'str_one'} |
690 | 12 | d2 = {'dict1': {'d1.e1': 'd1-e1'}} | 12 | d2 = {'dict1': {'d1.e1': 'd1-e1'}} |
691 | @@ -16,7 +16,7 @@ | |||
692 | 16 | self.assertEqual(d1, expected) | 16 | self.assertEqual(d1, expected) |
693 | 17 | 17 | ||
694 | 18 | 18 | ||
696 | 19 | class TestCmdArg2Cfg(TestCase): | 19 | class TestCmdArg2Cfg(CiTestCase): |
697 | 20 | def test_cmdarg_flat(self): | 20 | def test_cmdarg_flat(self): |
698 | 21 | self.assertEqual(config.cmdarg2cfg("foo=bar"), {'foo': 'bar'}) | 21 | self.assertEqual(config.cmdarg2cfg("foo=bar"), {'foo': 'bar'}) |
699 | 22 | 22 | ||
700 | @@ -50,7 +50,7 @@ | |||
701 | 50 | self.assertEqual(via_merge, via_merge_cmdarg) | 50 | self.assertEqual(via_merge, via_merge_cmdarg) |
702 | 51 | 51 | ||
703 | 52 | 52 | ||
705 | 53 | class TestConfigArchive(TestCase): | 53 | class TestConfigArchive(CiTestCase): |
706 | 54 | def test_archive_dict(self): | 54 | def test_archive_dict(self): |
707 | 55 | myarchive = _replace_consts(textwrap.dedent(""" | 55 | myarchive = _replace_consts(textwrap.dedent(""" |
708 | 56 | _ARCH_HEAD_ | 56 | _ARCH_HEAD_ |
709 | 57 | 57 | ||
710 | === modified file 'tests/unittests/test_curthooks.py' | |||
711 | --- tests/unittests/test_curthooks.py 2017-07-28 19:01:38 +0000 | |||
712 | +++ tests/unittests/test_curthooks.py 2017-08-03 19:32:06 +0000 | |||
713 | @@ -1,29 +1,14 @@ | |||
714 | 1 | import os | 1 | import os |
715 | 2 | from unittest import TestCase | ||
716 | 3 | from mock import call, patch, MagicMock | 2 | from mock import call, patch, MagicMock |
717 | 4 | import shutil | ||
718 | 5 | import tempfile | ||
719 | 6 | 3 | ||
720 | 7 | from curtin.commands import curthooks | 4 | from curtin.commands import curthooks |
721 | 8 | from curtin import util | 5 | from curtin import util |
722 | 9 | from curtin import config | 6 | from curtin import config |
723 | 10 | from curtin.reporter import events | 7 | from curtin.reporter import events |
740 | 11 | 8 | from .helpers import CiTestCase | |
741 | 12 | 9 | ||
742 | 13 | class CurthooksBase(TestCase): | 10 | |
743 | 14 | def setUp(self): | 11 | class TestGetFlashKernelPkgs(CiTestCase): |
728 | 15 | super(CurthooksBase, self).setUp() | ||
729 | 16 | |||
730 | 17 | def add_patch(self, target, attr, autospec=True): | ||
731 | 18 | """Patches specified target object and sets it as attr on test | ||
732 | 19 | instance also schedules cleanup""" | ||
733 | 20 | m = patch(target, autospec=autospec) | ||
734 | 21 | p = m.start() | ||
735 | 22 | self.addCleanup(m.stop) | ||
736 | 23 | setattr(self, attr, p) | ||
737 | 24 | |||
738 | 25 | |||
739 | 26 | class TestGetFlashKernelPkgs(CurthooksBase): | ||
744 | 27 | def setUp(self): | 12 | def setUp(self): |
745 | 28 | super(TestGetFlashKernelPkgs, self).setUp() | 13 | super(TestGetFlashKernelPkgs, self).setUp() |
746 | 29 | self.add_patch('curtin.util.subp', 'mock_subp') | 14 | self.add_patch('curtin.util.subp', 'mock_subp') |
747 | @@ -57,7 +42,7 @@ | |||
748 | 57 | self.mock_is_uefi_bootable.assert_called_once_with() | 42 | self.mock_is_uefi_bootable.assert_called_once_with() |
749 | 58 | 43 | ||
750 | 59 | 44 | ||
752 | 60 | class TestCurthooksInstallKernel(CurthooksBase): | 45 | class TestCurthooksInstallKernel(CiTestCase): |
753 | 61 | def setUp(self): | 46 | def setUp(self): |
754 | 62 | super(TestCurthooksInstallKernel, self).setUp() | 47 | super(TestCurthooksInstallKernel, self).setUp() |
755 | 63 | self.add_patch('curtin.util.has_pkg_available', 'mock_haspkg') | 48 | self.add_patch('curtin.util.has_pkg_available', 'mock_haspkg') |
756 | @@ -70,7 +55,7 @@ | |||
757 | 70 | 'fallback-package': 'mock-fallback', | 55 | 'fallback-package': 'mock-fallback', |
758 | 71 | 'mapping': {}}} | 56 | 'mapping': {}}} |
759 | 72 | # Tests don't actually install anything so we just need a name | 57 | # Tests don't actually install anything so we just need a name |
761 | 73 | self.target = tempfile.mktemp() | 58 | self.target = self.tmp_dir() |
762 | 74 | 59 | ||
763 | 75 | def test__installs_flash_kernel_packages_when_needed(self): | 60 | def test__installs_flash_kernel_packages_when_needed(self): |
764 | 76 | kernel_package = self.kernel_cfg.get('kernel', {}).get('package', {}) | 61 | kernel_package = self.kernel_cfg.get('kernel', {}).get('package', {}) |
765 | @@ -94,14 +79,11 @@ | |||
766 | 94 | [kernel_package], target=self.target) | 79 | [kernel_package], target=self.target) |
767 | 95 | 80 | ||
768 | 96 | 81 | ||
770 | 97 | class TestUpdateInitramfs(CurthooksBase): | 82 | class TestUpdateInitramfs(CiTestCase): |
771 | 98 | def setUp(self): | 83 | def setUp(self): |
772 | 99 | super(TestUpdateInitramfs, self).setUp() | 84 | super(TestUpdateInitramfs, self).setUp() |
773 | 100 | self.add_patch('curtin.util.subp', 'mock_subp') | 85 | self.add_patch('curtin.util.subp', 'mock_subp') |
778 | 101 | self.target = tempfile.mkdtemp() | 86 | self.target = self.tmp_dir() |
775 | 102 | |||
776 | 103 | def tearDown(self): | ||
777 | 104 | shutil.rmtree(self.target) | ||
779 | 105 | 87 | ||
780 | 106 | def _mnt_call(self, point): | 88 | def _mnt_call(self, point): |
781 | 107 | target = os.path.join(self.target, point) | 89 | target = os.path.join(self.target, point) |
782 | @@ -134,7 +116,7 @@ | |||
783 | 134 | self.mock_subp.assert_has_calls(subp_calls) | 116 | self.mock_subp.assert_has_calls(subp_calls) |
784 | 135 | 117 | ||
785 | 136 | 118 | ||
787 | 137 | class TestInstallMissingPkgs(CurthooksBase): | 119 | class TestInstallMissingPkgs(CiTestCase): |
788 | 138 | def setUp(self): | 120 | def setUp(self): |
789 | 139 | super(TestInstallMissingPkgs, self).setUp() | 121 | super(TestInstallMissingPkgs, self).setUp() |
790 | 140 | self.add_patch('platform.machine', 'mock_machine') | 122 | self.add_patch('platform.machine', 'mock_machine') |
791 | @@ -176,11 +158,11 @@ | |||
792 | 176 | self.assertEqual([], self.mock_install_packages.call_args_list) | 158 | self.assertEqual([], self.mock_install_packages.call_args_list) |
793 | 177 | 159 | ||
794 | 178 | 160 | ||
796 | 179 | class TestSetupZipl(CurthooksBase): | 161 | class TestSetupZipl(CiTestCase): |
797 | 180 | 162 | ||
798 | 181 | def setUp(self): | 163 | def setUp(self): |
799 | 182 | super(TestSetupZipl, self).setUp() | 164 | super(TestSetupZipl, self).setUp() |
801 | 183 | self.target = tempfile.mkdtemp() | 165 | self.target = self.tmp_dir() |
802 | 184 | 166 | ||
803 | 185 | @patch('curtin.block.get_devices_for_mp') | 167 | @patch('curtin.block.get_devices_for_mp') |
804 | 186 | @patch('platform.machine') | 168 | @patch('platform.machine') |
805 | @@ -203,11 +185,11 @@ | |||
806 | 203 | content) | 185 | content) |
807 | 204 | 186 | ||
808 | 205 | 187 | ||
810 | 206 | class TestSetupGrub(CurthooksBase): | 188 | class TestSetupGrub(CiTestCase): |
811 | 207 | 189 | ||
812 | 208 | def setUp(self): | 190 | def setUp(self): |
813 | 209 | super(TestSetupGrub, self).setUp() | 191 | super(TestSetupGrub, self).setUp() |
815 | 210 | self.target = tempfile.mkdtemp() | 192 | self.target = self.tmp_dir() |
816 | 211 | self.add_patch('curtin.util.lsb_release', 'mock_lsb_release') | 193 | self.add_patch('curtin.util.lsb_release', 'mock_lsb_release') |
817 | 212 | self.mock_lsb_release.return_value = { | 194 | self.mock_lsb_release.return_value = { |
818 | 213 | 'codename': 'xenial', | 195 | 'codename': 'xenial', |
819 | @@ -230,9 +212,6 @@ | |||
820 | 230 | self.mock_in_chroot_subp.side_effect = iter(self.in_chroot_subp_output) | 212 | self.mock_in_chroot_subp.side_effect = iter(self.in_chroot_subp_output) |
821 | 231 | self.mock_chroot.return_value = self.mock_in_chroot | 213 | self.mock_chroot.return_value = self.mock_in_chroot |
822 | 232 | 214 | ||
823 | 233 | def tearDown(self): | ||
824 | 234 | shutil.rmtree(self.target) | ||
825 | 235 | |||
826 | 236 | def test_uses_old_grub_install_devices_in_cfg(self): | 215 | def test_uses_old_grub_install_devices_in_cfg(self): |
827 | 237 | cfg = { | 216 | cfg = { |
828 | 238 | 'grub_install_devices': ['/dev/vdb'] | 217 | 'grub_install_devices': ['/dev/vdb'] |
829 | @@ -461,17 +440,13 @@ | |||
830 | 461 | self.mock_in_chroot_subp.call_args_list[0][0]) | 440 | self.mock_in_chroot_subp.call_args_list[0][0]) |
831 | 462 | 441 | ||
832 | 463 | 442 | ||
834 | 464 | class TestUbuntuCoreHooks(CurthooksBase): | 443 | class TestUbuntuCoreHooks(CiTestCase): |
835 | 465 | def setUp(self): | 444 | def setUp(self): |
836 | 466 | super(TestUbuntuCoreHooks, self).setUp() | 445 | super(TestUbuntuCoreHooks, self).setUp() |
837 | 467 | self.target = None | 446 | self.target = None |
838 | 468 | 447 | ||
839 | 469 | def tearDown(self): | ||
840 | 470 | if self.target: | ||
841 | 471 | shutil.rmtree(self.target) | ||
842 | 472 | |||
843 | 473 | def test_target_is_ubuntu_core(self): | 448 | def test_target_is_ubuntu_core(self): |
845 | 474 | self.target = tempfile.mkdtemp() | 449 | self.target = self.tmp_dir() |
846 | 475 | ubuntu_core_path = os.path.join(self.target, 'system-data', | 450 | ubuntu_core_path = os.path.join(self.target, 'system-data', |
847 | 476 | 'var/lib/snapd') | 451 | 'var/lib/snapd') |
848 | 477 | util.ensure_dir(ubuntu_core_path) | 452 | util.ensure_dir(ubuntu_core_path) |
849 | @@ -484,7 +459,7 @@ | |||
850 | 484 | self.assertFalse(is_core) | 459 | self.assertFalse(is_core) |
851 | 485 | 460 | ||
852 | 486 | def test_target_is_ubuntu_core_noncore_target(self): | 461 | def test_target_is_ubuntu_core_noncore_target(self): |
854 | 487 | self.target = tempfile.mkdtemp() | 462 | self.target = self.tmp_dir() |
855 | 488 | non_core_path = os.path.join(self.target, 'curtin') | 463 | non_core_path = os.path.join(self.target, 'curtin') |
856 | 489 | util.ensure_dir(non_core_path) | 464 | util.ensure_dir(non_core_path) |
857 | 490 | self.assertTrue(os.path.isdir(non_core_path)) | 465 | self.assertTrue(os.path.isdir(non_core_path)) |
858 | @@ -496,7 +471,7 @@ | |||
859 | 496 | @patch('curtin.commands.curthooks.handle_cloudconfig') | 471 | @patch('curtin.commands.curthooks.handle_cloudconfig') |
860 | 497 | def test_curthooks_no_config(self, mock_handle_cc, mock_del_file, | 472 | def test_curthooks_no_config(self, mock_handle_cc, mock_del_file, |
861 | 498 | mock_write_file): | 473 | mock_write_file): |
863 | 499 | self.target = tempfile.mkdtemp() | 474 | self.target = self.tmp_dir() |
864 | 500 | cfg = {} | 475 | cfg = {} |
865 | 501 | curthooks.ubuntu_core_curthooks(cfg, target=self.target) | 476 | curthooks.ubuntu_core_curthooks(cfg, target=self.target) |
866 | 502 | self.assertEqual(len(mock_handle_cc.call_args_list), 0) | 477 | self.assertEqual(len(mock_handle_cc.call_args_list), 0) |
867 | @@ -505,7 +480,7 @@ | |||
868 | 505 | 480 | ||
869 | 506 | @patch('curtin.commands.curthooks.handle_cloudconfig') | 481 | @patch('curtin.commands.curthooks.handle_cloudconfig') |
870 | 507 | def test_curthooks_cloud_config_remove_disabled(self, mock_handle_cc): | 482 | def test_curthooks_cloud_config_remove_disabled(self, mock_handle_cc): |
872 | 508 | self.target = tempfile.mkdtemp() | 483 | self.target = self.tmp_dir() |
873 | 509 | uc_cloud = os.path.join(self.target, 'system-data', 'etc/cloud') | 484 | uc_cloud = os.path.join(self.target, 'system-data', 'etc/cloud') |
874 | 510 | cc_disabled = os.path.join(uc_cloud, 'cloud-init.disabled') | 485 | cc_disabled = os.path.join(uc_cloud, 'cloud-init.disabled') |
875 | 511 | cc_path = os.path.join(uc_cloud, 'cloud.cfg.d') | 486 | cc_path = os.path.join(uc_cloud, 'cloud.cfg.d') |
876 | @@ -531,7 +506,7 @@ | |||
877 | 531 | @patch('curtin.commands.curthooks.handle_cloudconfig') | 506 | @patch('curtin.commands.curthooks.handle_cloudconfig') |
878 | 532 | def test_curthooks_cloud_config(self, mock_handle_cc, mock_del_file, | 507 | def test_curthooks_cloud_config(self, mock_handle_cc, mock_del_file, |
879 | 533 | mock_write_file): | 508 | mock_write_file): |
881 | 534 | self.target = tempfile.mkdtemp() | 509 | self.target = self.tmp_dir() |
882 | 535 | cfg = { | 510 | cfg = { |
883 | 536 | 'cloudconfig': { | 511 | 'cloudconfig': { |
884 | 537 | 'file1': { | 512 | 'file1': { |
885 | @@ -553,7 +528,7 @@ | |||
886 | 553 | @patch('curtin.commands.curthooks.handle_cloudconfig') | 528 | @patch('curtin.commands.curthooks.handle_cloudconfig') |
887 | 554 | def test_curthooks_net_config(self, mock_handle_cc, mock_del_file, | 529 | def test_curthooks_net_config(self, mock_handle_cc, mock_del_file, |
888 | 555 | mock_write_file): | 530 | mock_write_file): |
890 | 556 | self.target = tempfile.mkdtemp() | 531 | self.target = self.tmp_dir() |
891 | 557 | cfg = { | 532 | cfg = { |
892 | 558 | 'network': { | 533 | 'network': { |
893 | 559 | 'version': '1', | 534 | 'version': '1', |
894 | @@ -603,7 +578,7 @@ | |||
895 | 603 | curthooks.handle_cloudconfig([], base_dir="foobar") | 578 | curthooks.handle_cloudconfig([], base_dir="foobar") |
896 | 604 | 579 | ||
897 | 605 | 580 | ||
899 | 606 | class TestDetectRequiredPackages(TestCase): | 581 | class TestDetectRequiredPackages(CiTestCase): |
900 | 607 | test_config = { | 582 | test_config = { |
901 | 608 | 'storage': { | 583 | 'storage': { |
902 | 609 | 1: { | 584 | 1: { |
903 | 610 | 585 | ||
904 | === modified file 'tests/unittests/test_feature.py' | |||
905 | --- tests/unittests/test_feature.py 2017-07-28 19:22:14 +0000 | |||
906 | +++ tests/unittests/test_feature.py 2017-08-03 19:32:06 +0000 | |||
907 | @@ -1,9 +1,9 @@ | |||
909 | 1 | from unittest import TestCase | 1 | from .helpers import CiTestCase |
910 | 2 | 2 | ||
911 | 3 | import curtin | 3 | import curtin |
912 | 4 | 4 | ||
913 | 5 | 5 | ||
915 | 6 | class TestExportsFeatures(TestCase): | 6 | class TestExportsFeatures(CiTestCase): |
916 | 7 | def test_has_storage_v1(self): | 7 | def test_has_storage_v1(self): |
917 | 8 | self.assertIn('STORAGE_CONFIG_V1', curtin.FEATURES) | 8 | self.assertIn('STORAGE_CONFIG_V1', curtin.FEATURES) |
918 | 9 | 9 | ||
919 | 10 | 10 | ||
920 | === modified file 'tests/unittests/test_gpg.py' | |||
921 | --- tests/unittests/test_gpg.py 2017-02-03 16:02:29 +0000 | |||
922 | +++ tests/unittests/test_gpg.py 2017-08-03 19:32:06 +0000 | |||
923 | @@ -1,12 +1,12 @@ | |||
924 | 1 | from unittest import TestCase | ||
925 | 2 | from mock import call, patch | 1 | from mock import call, patch |
926 | 3 | import textwrap | 2 | import textwrap |
927 | 4 | 3 | ||
928 | 5 | from curtin import gpg | 4 | from curtin import gpg |
929 | 6 | from curtin import util | 5 | from curtin import util |
933 | 7 | 6 | from .helpers import CiTestCase | |
934 | 8 | 7 | ||
935 | 9 | class TestCurtinGpg(TestCase): | 8 | |
936 | 9 | class TestCurtinGpg(CiTestCase): | ||
937 | 10 | 10 | ||
938 | 11 | @patch('curtin.util.subp') | 11 | @patch('curtin.util.subp') |
939 | 12 | def test_export_armour(self, mock_subp): | 12 | def test_export_armour(self, mock_subp): |
940 | 13 | 13 | ||
941 | === modified file 'tests/unittests/test_make_dname.py' | |||
942 | --- tests/unittests/test_make_dname.py 2016-07-13 17:07:11 +0000 | |||
943 | +++ tests/unittests/test_make_dname.py 2017-08-03 19:32:06 +0000 | |||
944 | @@ -1,13 +1,13 @@ | |||
945 | 1 | from unittest import TestCase | ||
946 | 2 | import mock | 1 | import mock |
947 | 3 | 2 | ||
948 | 4 | import textwrap | 3 | import textwrap |
949 | 5 | import uuid | 4 | import uuid |
950 | 6 | 5 | ||
951 | 7 | from curtin.commands import block_meta | 6 | from curtin.commands import block_meta |
955 | 8 | 7 | from .helpers import CiTestCase | |
956 | 9 | 8 | ||
957 | 10 | class TestMakeDname(TestCase): | 9 | |
958 | 10 | class TestMakeDname(CiTestCase): | ||
959 | 11 | state = {'scratch': '/tmp/null'} | 11 | state = {'scratch': '/tmp/null'} |
960 | 12 | rules_d = '/tmp/null/rules.d' | 12 | rules_d = '/tmp/null/rules.d' |
961 | 13 | rule_file = '/tmp/null/rules.d/{}.rules' | 13 | rule_file = '/tmp/null/rules.d/{}.rules' |
962 | 14 | 14 | ||
963 | === modified file 'tests/unittests/test_net.py' | |||
964 | --- tests/unittests/test_net.py 2017-07-19 21:54:01 +0000 | |||
965 | +++ tests/unittests/test_net.py 2017-08-03 19:32:06 +0000 | |||
966 | @@ -1,16 +1,14 @@ | |||
967 | 1 | from unittest import TestCase | ||
968 | 2 | import mock | 1 | import mock |
969 | 3 | import os | 2 | import os |
970 | 4 | import shutil | ||
971 | 5 | import tempfile | ||
972 | 6 | import yaml | 3 | import yaml |
973 | 7 | 4 | ||
974 | 8 | from curtin import config, net, util | 5 | from curtin import config, net, util |
975 | 9 | import curtin.net.network_state as network_state | 6 | import curtin.net.network_state as network_state |
976 | 7 | from .helpers import CiTestCase | ||
977 | 10 | from textwrap import dedent | 8 | from textwrap import dedent |
978 | 11 | 9 | ||
979 | 12 | 10 | ||
981 | 13 | class TestNetParserData(TestCase): | 11 | class TestNetParserData(CiTestCase): |
982 | 14 | 12 | ||
983 | 15 | def test_parse_deb_config_data_ignores_comments(self): | 13 | def test_parse_deb_config_data_ignores_comments(self): |
984 | 16 | contents = dedent("""\ | 14 | contents = dedent("""\ |
985 | @@ -235,13 +233,11 @@ | |||
986 | 235 | }, ifaces) | 233 | }, ifaces) |
987 | 236 | 234 | ||
988 | 237 | 235 | ||
990 | 238 | class TestNetParser(TestCase): | 236 | class TestNetParser(CiTestCase): |
991 | 239 | 237 | ||
992 | 240 | def setUp(self): | 238 | def setUp(self): |
997 | 241 | self.target = tempfile.mkdtemp() | 239 | super(TestNetParser, self).setUp() |
998 | 242 | 240 | self.target = self.tmp_dir() | |
995 | 243 | def tearDown(self): | ||
996 | 244 | shutil.rmtree(self.target) | ||
999 | 245 | 241 | ||
1000 | 246 | def make_config(self, path=None, name=None, contents=None, | 242 | def make_config(self, path=None, name=None, contents=None, |
1001 | 247 | parse=True): | 243 | parse=True): |
1002 | @@ -387,9 +383,10 @@ | |||
1003 | 387 | self.assertEqual({}, observed) | 383 | self.assertEqual({}, observed) |
1004 | 388 | 384 | ||
1005 | 389 | 385 | ||
1007 | 390 | class TestNetConfig(TestCase): | 386 | class TestNetConfig(CiTestCase): |
1008 | 391 | def setUp(self): | 387 | def setUp(self): |
1010 | 392 | self.target = tempfile.mkdtemp() | 388 | super(TestNetConfig, self).setUp() |
1011 | 389 | self.target = self.tmp_dir() | ||
1012 | 393 | self.config_f = os.path.join(self.target, 'config') | 390 | self.config_f = os.path.join(self.target, 'config') |
1013 | 394 | self.config = ''' | 391 | self.config = ''' |
1014 | 395 | # YAML example of a simple network config | 392 | # YAML example of a simple network config |
1015 | @@ -436,9 +433,6 @@ | |||
1016 | 436 | ns.parse_config() | 433 | ns.parse_config() |
1017 | 437 | return ns | 434 | return ns |
1018 | 438 | 435 | ||
1019 | 439 | def tearDown(self): | ||
1020 | 440 | shutil.rmtree(self.target) | ||
1021 | 441 | |||
1022 | 442 | def test_parse_net_config_data(self): | 436 | def test_parse_net_config_data(self): |
1023 | 443 | ns = self.get_net_state() | 437 | ns = self.get_net_state() |
1024 | 444 | net_state_from_cls = ns.network_state | 438 | net_state_from_cls = ns.network_state |
1025 | 445 | 439 | ||
1026 | === modified file 'tests/unittests/test_partitioning.py' | |||
1027 | --- tests/unittests/test_partitioning.py 2015-08-10 16:34:02 +0000 | |||
1028 | +++ tests/unittests/test_partitioning.py 2017-08-03 19:32:06 +0000 | |||
1029 | @@ -1,6 +1,7 @@ | |||
1031 | 1 | import unittest | 1 | from unittest import skip |
1032 | 2 | import mock | 2 | import mock |
1033 | 3 | import curtin.commands.block_meta | 3 | import curtin.commands.block_meta |
1034 | 4 | from .helpers import CiTestCase | ||
1035 | 4 | 5 | ||
1036 | 5 | from sys import version_info | 6 | from sys import version_info |
1037 | 6 | if version_info.major == 2: | 7 | if version_info.major == 2: |
1038 | @@ -11,8 +12,8 @@ | |||
1039 | 11 | parted = None # FIXME: remove these tests entirely. This is here for flake8 | 12 | parted = None # FIXME: remove these tests entirely. This is here for flake8 |
1040 | 12 | 13 | ||
1041 | 13 | 14 | ||
1044 | 14 | @unittest.skip | 15 | @skip |
1045 | 15 | class TestBlock(unittest.TestCase): | 16 | class TestBlock(CiTestCase): |
1046 | 16 | storage_config = { | 17 | storage_config = { |
1047 | 17 | "sda": {"id": "sda", "type": "disk", "ptable": "msdos", | 18 | "sda": {"id": "sda", "type": "disk", "ptable": "msdos", |
1048 | 18 | "serial": "DISK_1", "grub_device": "True"}, | 19 | "serial": "DISK_1", "grub_device": "True"}, |
1049 | 19 | 20 | ||
1050 | === modified file 'tests/unittests/test_public.py' | |||
1051 | --- tests/unittests/test_public.py 2017-07-28 20:54:10 +0000 | |||
1052 | +++ tests/unittests/test_public.py 2017-08-03 19:32:06 +0000 | |||
1053 | @@ -1,4 +1,3 @@ | |||
1054 | 1 | from unittest import TestCase | ||
1055 | 2 | 1 | ||
1056 | 3 | from curtin import block | 2 | from curtin import block |
1057 | 4 | from curtin import config | 3 | from curtin import config |
1058 | @@ -6,9 +5,10 @@ | |||
1059 | 6 | from curtin import util | 5 | from curtin import util |
1060 | 7 | 6 | ||
1061 | 8 | from curtin.commands import curthooks | 7 | from curtin.commands import curthooks |
1065 | 9 | 8 | from .helpers import CiTestCase | |
1066 | 10 | 9 | ||
1067 | 11 | class TestPublicAPI(TestCase): | 10 | |
1068 | 11 | class TestPublicAPI(CiTestCase): | ||
1069 | 12 | """Test entry points known to be used externally. | 12 | """Test entry points known to be used externally. |
1070 | 13 | 13 | ||
1071 | 14 | Curtin's only known external library user is the curthooks | 14 | Curtin's only known external library user is the curthooks |
1072 | 15 | 15 | ||
1073 | === modified file 'tests/unittests/test_reporter.py' | |||
1074 | --- tests/unittests/test_reporter.py 2016-06-22 15:27:45 +0000 | |||
1075 | +++ tests/unittests/test_reporter.py 2017-08-03 19:32:06 +0000 | |||
1076 | @@ -21,7 +21,6 @@ | |||
1077 | 21 | unicode_literals, | 21 | unicode_literals, |
1078 | 22 | ) | 22 | ) |
1079 | 23 | 23 | ||
1080 | 24 | from unittest import TestCase | ||
1081 | 25 | from mock import patch | 24 | from mock import patch |
1082 | 26 | 25 | ||
1083 | 27 | from curtin.reporter.legacy import ( | 26 | from curtin.reporter.legacy import ( |
1084 | @@ -39,13 +38,12 @@ | |||
1085 | 39 | from curtin.reporter import handlers | 38 | from curtin.reporter import handlers |
1086 | 40 | from curtin import url_helper | 39 | from curtin import url_helper |
1087 | 41 | from curtin.reporter import events | 40 | from curtin.reporter import events |
1088 | 41 | from .helpers import CiTestCase | ||
1089 | 42 | 42 | ||
1090 | 43 | import os | ||
1091 | 44 | import tempfile | ||
1092 | 45 | import base64 | 43 | import base64 |
1093 | 46 | 44 | ||
1094 | 47 | 45 | ||
1096 | 48 | class TestLegacyReporter(TestCase): | 46 | class TestLegacyReporter(CiTestCase): |
1097 | 49 | 47 | ||
1098 | 50 | @patch('curtin.reporter.legacy.LOG') | 48 | @patch('curtin.reporter.legacy.LOG') |
1099 | 51 | def test_load_reporter_logs_empty_cfg(self, mock_LOG): | 49 | def test_load_reporter_logs_empty_cfg(self, mock_LOG): |
1100 | @@ -72,7 +70,7 @@ | |||
1101 | 72 | self.assertTrue(mock_LOG.error.called) | 70 | self.assertTrue(mock_LOG.error.called) |
1102 | 73 | 71 | ||
1103 | 74 | 72 | ||
1105 | 75 | class TestMAASReporter(TestCase): | 73 | class TestMAASReporter(CiTestCase): |
1106 | 76 | def test_load_factory_raises_exception_wrong_options(self): | 74 | def test_load_factory_raises_exception_wrong_options(self): |
1107 | 77 | options = {'wrong': 'wrong'} | 75 | options = {'wrong': 'wrong'} |
1108 | 78 | self.assertRaises( | 76 | self.assertRaises( |
1109 | @@ -86,7 +84,7 @@ | |||
1110 | 86 | self.assertIsInstance(reporter, MAASReporter) | 84 | self.assertIsInstance(reporter, MAASReporter) |
1111 | 87 | 85 | ||
1112 | 88 | 86 | ||
1114 | 89 | class TestReporter(TestCase): | 87 | class TestReporter(CiTestCase): |
1115 | 90 | config = {'element1': {'type': 'webhook', 'level': 'INFO', | 88 | config = {'element1': {'type': 'webhook', 'level': 'INFO', |
1116 | 91 | 'consumer_key': "ck_foo", | 89 | 'consumer_key': "ck_foo", |
1117 | 92 | 'consumer_secret': 'cs_foo', | 90 | 'consumer_secret': 'cs_foo', |
1118 | @@ -175,39 +173,32 @@ | |||
1119 | 175 | @patch('curtin.reporter.events.report_event') | 173 | @patch('curtin.reporter.events.report_event') |
1120 | 176 | def test_report_finished_post_files(self, mock_report_event): | 174 | def test_report_finished_post_files(self, mock_report_event): |
1121 | 177 | test_data = b'abcdefg' | 175 | test_data = b'abcdefg' |
1137 | 178 | tmp = tempfile.mkstemp() | 176 | tmpfname = self.tmp_path('testfile') |
1138 | 179 | try: | 177 | with open(tmpfname, 'wb') as fp: |
1139 | 180 | with open(tmp[1], 'wb') as fp: | 178 | fp.write(test_data) |
1140 | 181 | fp.write(test_data) | 179 | events.report_finish_event(self.ev_name, self.ev_desc, |
1141 | 182 | events.report_finish_event(self.ev_name, self.ev_desc, | 180 | post_files=[tmpfname]) |
1142 | 183 | post_files=[tmp[1]]) | 181 | event = self._get_reported_event(mock_report_event) |
1143 | 184 | event = self._get_reported_event(mock_report_event) | 182 | files = event.as_dict().get('files') |
1144 | 185 | files = event.as_dict().get('files') | 183 | self.assertTrue(len(files) == 1) |
1145 | 186 | self.assertTrue(len(files) == 1) | 184 | self.assertEqual(files[0].get('path'), tmpfname) |
1146 | 187 | self.assertEqual(files[0].get('path'), tmp[1]) | 185 | self.assertEqual(files[0].get('encoding'), 'base64') |
1147 | 188 | self.assertEqual(files[0].get('encoding'), 'base64') | 186 | self.assertEqual(files[0].get('content'), |
1148 | 189 | self.assertEqual(files[0].get('content'), | 187 | base64.b64encode(test_data).decode()) |
1134 | 190 | base64.b64encode(test_data).decode()) | ||
1135 | 191 | finally: | ||
1136 | 192 | os.remove(tmp[1]) | ||
1149 | 193 | 188 | ||
1150 | 194 | @patch('curtin.url_helper.OauthUrlHelper') | 189 | @patch('curtin.url_helper.OauthUrlHelper') |
1151 | 195 | def test_webhook_handler_post_files(self, mock_url_helper): | 190 | def test_webhook_handler_post_files(self, mock_url_helper): |
1152 | 196 | test_data = b'abcdefg' | 191 | test_data = b'abcdefg' |
1170 | 197 | tmp = tempfile.mkstemp() | 192 | tmpfname = self.tmp_path('testfile') |
1171 | 198 | tmpfname = tmp[1] | 193 | with open(tmpfname, 'wb') as fp: |
1172 | 199 | try: | 194 | fp.write(test_data) |
1173 | 200 | with open(tmpfname, 'wb') as fp: | 195 | event = events.FinishReportingEvent('test_event_name', |
1174 | 201 | fp.write(test_data) | 196 | 'test event description', |
1175 | 202 | event = events.FinishReportingEvent('test_event_name', | 197 | post_files=[tmpfname], |
1176 | 203 | 'test event description', | 198 | level='INFO') |
1177 | 204 | post_files=[tmpfname], | 199 | webhook_handler = handlers.WebHookHandler('127.0.0.1:8000', |
1178 | 205 | level='INFO') | 200 | level='INFO') |
1179 | 206 | webhook_handler = handlers.WebHookHandler('127.0.0.1:8000', | 201 | webhook_handler.publish_event(event) |
1180 | 207 | level='INFO') | 202 | webhook_handler.oauth_helper.geturl.assert_called_with( |
1181 | 208 | webhook_handler.publish_event(event) | 203 | url='127.0.0.1:8000', data=event.as_dict(), |
1182 | 209 | webhook_handler.oauth_helper.geturl.assert_called_with( | 204 | headers=webhook_handler.headers, retries=None) |
1166 | 210 | url='127.0.0.1:8000', data=event.as_dict(), | ||
1167 | 211 | headers=webhook_handler.headers, retries=None) | ||
1168 | 212 | finally: | ||
1169 | 213 | os.remove(tmpfname) | ||
1183 | 214 | 205 | ||
1184 | === modified file 'tests/unittests/test_util.py' | |||
1185 | --- tests/unittests/test_util.py 2017-06-09 20:54:25 +0000 | |||
1186 | +++ tests/unittests/test_util.py 2017-08-03 19:32:06 +0000 | |||
1187 | @@ -1,16 +1,14 @@ | |||
1189 | 1 | from unittest import TestCase, skipIf | 1 | from unittest import skipIf |
1190 | 2 | import mock | 2 | import mock |
1191 | 3 | import os | 3 | import os |
1192 | 4 | import stat | 4 | import stat |
1193 | 5 | import shutil | ||
1194 | 6 | import tempfile | ||
1195 | 7 | from textwrap import dedent | 5 | from textwrap import dedent |
1196 | 8 | 6 | ||
1197 | 9 | from curtin import util | 7 | from curtin import util |
1202 | 10 | from .helpers import simple_mocked_open | 8 | from .helpers import CiTestCase, simple_mocked_open |
1203 | 11 | 9 | ||
1204 | 12 | 10 | ||
1205 | 13 | class TestLogTimer(TestCase): | 11 | class TestLogTimer(CiTestCase): |
1206 | 14 | def test_logger_called(self): | 12 | def test_logger_called(self): |
1207 | 15 | data = {} | 13 | data = {} |
1208 | 16 | 14 | ||
1209 | @@ -24,16 +22,14 @@ | |||
1210 | 24 | self.assertIn("mymessage", data['msg']) | 22 | self.assertIn("mymessage", data['msg']) |
1211 | 25 | 23 | ||
1212 | 26 | 24 | ||
1214 | 27 | class TestDisableDaemons(TestCase): | 25 | class TestDisableDaemons(CiTestCase): |
1215 | 28 | prcpath = "usr/sbin/policy-rc.d" | 26 | prcpath = "usr/sbin/policy-rc.d" |
1216 | 29 | 27 | ||
1217 | 30 | def setUp(self): | 28 | def setUp(self): |
1219 | 31 | self.target = tempfile.mkdtemp() | 29 | super(TestDisableDaemons, self).setUp() |
1220 | 30 | self.target = self.tmp_dir() | ||
1221 | 32 | self.temp_prc = os.path.join(self.target, self.prcpath) | 31 | self.temp_prc = os.path.join(self.target, self.prcpath) |
1222 | 33 | 32 | ||
1223 | 34 | def tearDown(self): | ||
1224 | 35 | shutil.rmtree(self.target) | ||
1225 | 36 | |||
1226 | 37 | def test_disable_daemons_in_root_works(self): | 33 | def test_disable_daemons_in_root_works(self): |
1227 | 38 | ret = util.disable_daemons_in_root(self.target) | 34 | ret = util.disable_daemons_in_root(self.target) |
1228 | 39 | self.assertTrue(ret) | 35 | self.assertTrue(ret) |
1229 | @@ -55,8 +51,10 @@ | |||
1230 | 55 | self.assertTrue(os.path.exists(self.temp_prc)) | 51 | self.assertTrue(os.path.exists(self.temp_prc)) |
1231 | 56 | 52 | ||
1232 | 57 | 53 | ||
1234 | 58 | class TestWhich(TestCase): | 54 | class TestWhich(CiTestCase): |
1235 | 55 | |||
1236 | 59 | def setUp(self): | 56 | def setUp(self): |
1237 | 57 | super(TestWhich, self).setUp() | ||
1238 | 60 | self.orig_is_exe = util.is_exe | 58 | self.orig_is_exe = util.is_exe |
1239 | 61 | util.is_exe = self.my_is_exe | 59 | util.is_exe = self.my_is_exe |
1240 | 62 | self.orig_path = os.environ.get("PATH") | 60 | self.orig_path = os.environ.get("PATH") |
1241 | @@ -103,8 +101,10 @@ | |||
1242 | 103 | self.assertEqual(found, "/usr/bin2/fuzz") | 101 | self.assertEqual(found, "/usr/bin2/fuzz") |
1243 | 104 | 102 | ||
1244 | 105 | 103 | ||
1246 | 106 | class TestLsbRelease(TestCase): | 104 | class TestLsbRelease(CiTestCase): |
1247 | 105 | |||
1248 | 107 | def setUp(self): | 106 | def setUp(self): |
1249 | 107 | super(TestLsbRelease, self).setUp() | ||
1250 | 108 | self._reset_cache() | 108 | self._reset_cache() |
1251 | 109 | 109 | ||
1252 | 110 | def _reset_cache(self): | 110 | def _reset_cache(self): |
1253 | @@ -143,7 +143,7 @@ | |||
1254 | 143 | self.assertEqual(util.lsb_release(), expected) | 143 | self.assertEqual(util.lsb_release(), expected) |
1255 | 144 | 144 | ||
1256 | 145 | 145 | ||
1258 | 146 | class TestSubp(TestCase): | 146 | class TestSubp(CiTestCase): |
1259 | 147 | 147 | ||
1260 | 148 | stdin2err = ['bash', '-c', 'cat >&2'] | 148 | stdin2err = ['bash', '-c', 'cat >&2'] |
1261 | 149 | stdin2out = ['cat'] | 149 | stdin2out = ['cat'] |
1262 | @@ -162,10 +162,9 @@ | |||
1263 | 162 | 162 | ||
1264 | 163 | def setUp(self): | 163 | def setUp(self): |
1265 | 164 | super(TestSubp, self).setUp() | 164 | super(TestSubp, self).setUp() |
1270 | 165 | mock_getunsh = mock.patch( | 165 | self.add_patch( |
1271 | 166 | "curtin.util._get_unshare_pid_args", return_value=[]) | 166 | 'curtin.util._get_unshare_pid_args', 'mock_get_unshare_pid_args', |
1272 | 167 | self.mock_get_unshare_pid_args = mock_getunsh.start() | 167 | return_value=[]) |
1269 | 168 | self.addCleanup(mock_getunsh.stop) | ||
1273 | 169 | 168 | ||
1274 | 170 | def printf_cmd(self, *args): | 169 | def printf_cmd(self, *args): |
1275 | 171 | # bash's printf supports \xaa. So does /usr/bin/printf | 170 | # bash's printf supports \xaa. So does /usr/bin/printf |
1276 | @@ -382,19 +381,17 @@ | |||
1277 | 382 | self.assertEqual(expected, args[0]) | 381 | self.assertEqual(expected, args[0]) |
1278 | 383 | 382 | ||
1279 | 384 | 383 | ||
1281 | 385 | class TestGetUnsharePidArgs(TestCase): | 384 | class TestGetUnsharePidArgs(CiTestCase): |
1282 | 386 | """Test the internal implementation for when to unshare.""" | 385 | """Test the internal implementation for when to unshare.""" |
1283 | 387 | 386 | ||
1284 | 388 | def setUp(self): | 387 | def setUp(self): |
1285 | 389 | super(TestGetUnsharePidArgs, self).setUp() | 388 | super(TestGetUnsharePidArgs, self).setUp() |
1294 | 390 | mock_hasunsh = mock.patch( | 389 | self.add_patch('curtin.util._has_unshare_pid', 'mock_has_unshare_pid', |
1295 | 391 | "curtin.util._has_unshare_pid", return_value=True) | 390 | return_value=True) |
1296 | 392 | self.mock_has_unshare_pid = mock_hasunsh.start() | 391 | # our trusty tox environment with mock 1.0.1 will stack trace |
1297 | 393 | self.addCleanup(mock_hasunsh.stop) | 392 | # if autospec is not disabled here. |
1298 | 394 | mock_geteuid = mock.patch( | 393 | self.add_patch('curtin.util.os.geteuid', 'mock_geteuid', |
1299 | 395 | "curtin.util.os.geteuid", return_value=0) | 394 | autospec=False, return_value=0) |
1292 | 396 | self.mock_geteuid = mock_geteuid.start() | ||
1293 | 397 | self.addCleanup(mock_geteuid.stop) | ||
1300 | 398 | 395 | ||
1301 | 399 | def assertOff(self, result): | 396 | def assertOff(self, result): |
1302 | 400 | self.assertEqual([], result) | 397 | self.assertEqual([], result) |
1303 | @@ -455,7 +452,7 @@ | |||
1304 | 455 | self.assertOff(util._get_unshare_pid_args("", "/target", 0)) | 452 | self.assertOff(util._get_unshare_pid_args("", "/target", 0)) |
1305 | 456 | 453 | ||
1306 | 457 | 454 | ||
1308 | 458 | class TestHuman2Bytes(TestCase): | 455 | class TestHuman2Bytes(CiTestCase): |
1309 | 459 | GB = 1024 * 1024 * 1024 | 456 | GB = 1024 * 1024 * 1024 |
1310 | 460 | MB = 1024 * 1024 | 457 | MB = 1024 * 1024 |
1311 | 461 | 458 | ||
1312 | @@ -509,52 +506,42 @@ | |||
1313 | 509 | util.bytes2human(util.human2bytes(size_str)), size_str) | 506 | util.bytes2human(util.human2bytes(size_str)), size_str) |
1314 | 510 | 507 | ||
1315 | 511 | 508 | ||
1317 | 512 | class TestSetUnExecutable(TestCase): | 509 | class TestSetUnExecutable(CiTestCase): |
1318 | 513 | tmpf = None | 510 | tmpf = None |
1319 | 514 | tmpd = None | 511 | tmpd = None |
1320 | 515 | 512 | ||
1336 | 516 | def tearDown(self): | 513 | def setUp(self): |
1337 | 517 | if self.tmpf: | 514 | super(CiTestCase, self).setUp() |
1338 | 518 | if os.path.exists(self.tmpf): | 515 | self.tmpd = self.tmp_dir() |
1324 | 519 | os.unlink(self.tmpf) | ||
1325 | 520 | self.tmpf = None | ||
1326 | 521 | if self.tmpd: | ||
1327 | 522 | shutil.rmtree(self.tmpd) | ||
1328 | 523 | self.tmpd = None | ||
1329 | 524 | |||
1330 | 525 | def tempfile(self, data=None): | ||
1331 | 526 | fp, self.tmpf = tempfile.mkstemp() | ||
1332 | 527 | if data: | ||
1333 | 528 | fp.write(data) | ||
1334 | 529 | os.close(fp) | ||
1335 | 530 | return self.tmpf | ||
1339 | 531 | 516 | ||
1340 | 532 | def test_change_needed_returns_original_mode(self): | 517 | def test_change_needed_returns_original_mode(self): |
1342 | 533 | tmpf = self.tempfile() | 518 | tmpf = self.tmp_path('testfile') |
1343 | 519 | util.write_file(tmpf, '') | ||
1344 | 534 | os.chmod(tmpf, 0o755) | 520 | os.chmod(tmpf, 0o755) |
1345 | 535 | ret = util.set_unexecutable(tmpf) | 521 | ret = util.set_unexecutable(tmpf) |
1346 | 536 | self.assertEqual(ret, 0o0755) | 522 | self.assertEqual(ret, 0o0755) |
1347 | 537 | 523 | ||
1348 | 538 | def test_no_change_needed_returns_none(self): | 524 | def test_no_change_needed_returns_none(self): |
1350 | 539 | tmpf = self.tempfile() | 525 | tmpf = self.tmp_path('testfile') |
1351 | 526 | util.write_file(tmpf, '') | ||
1352 | 540 | os.chmod(tmpf, 0o600) | 527 | os.chmod(tmpf, 0o600) |
1353 | 541 | ret = util.set_unexecutable(tmpf) | 528 | ret = util.set_unexecutable(tmpf) |
1354 | 542 | self.assertEqual(ret, None) | 529 | self.assertEqual(ret, None) |
1355 | 543 | 530 | ||
1356 | 544 | def test_change_does_as_expected(self): | 531 | def test_change_does_as_expected(self): |
1358 | 545 | tmpf = self.tempfile() | 532 | tmpf = self.tmp_path('testfile') |
1359 | 533 | util.write_file(tmpf, '') | ||
1360 | 546 | os.chmod(tmpf, 0o755) | 534 | os.chmod(tmpf, 0o755) |
1361 | 547 | ret = util.set_unexecutable(tmpf) | 535 | ret = util.set_unexecutable(tmpf) |
1362 | 548 | self.assertEqual(ret, 0o0755) | 536 | self.assertEqual(ret, 0o0755) |
1363 | 549 | self.assertEqual(stat.S_IMODE(os.stat(tmpf).st_mode), 0o0644) | 537 | self.assertEqual(stat.S_IMODE(os.stat(tmpf).st_mode), 0o0644) |
1364 | 550 | 538 | ||
1365 | 551 | def test_strict_no_exists_raises_exception(self): | 539 | def test_strict_no_exists_raises_exception(self): |
1366 | 552 | self.tmpd = tempfile.mkdtemp() | ||
1367 | 553 | bogus = os.path.join(self.tmpd, 'bogus') | 540 | bogus = os.path.join(self.tmpd, 'bogus') |
1368 | 554 | self.assertRaises(ValueError, util.set_unexecutable, bogus, True) | 541 | self.assertRaises(ValueError, util.set_unexecutable, bogus, True) |
1369 | 555 | 542 | ||
1370 | 556 | 543 | ||
1372 | 557 | class TestTargetPath(TestCase): | 544 | class TestTargetPath(CiTestCase): |
1373 | 558 | def test_target_empty_string(self): | 545 | def test_target_empty_string(self): |
1374 | 559 | self.assertEqual("/etc/passwd", util.target_path("", "/etc/passwd")) | 546 | self.assertEqual("/etc/passwd", util.target_path("", "/etc/passwd")) |
1375 | 560 | 547 | ||
1376 | @@ -596,7 +583,7 @@ | |||
1377 | 596 | util.target_path("/target/", "///my/path/")) | 583 | util.target_path("/target/", "///my/path/")) |
1378 | 597 | 584 | ||
1379 | 598 | 585 | ||
1381 | 599 | class TestRunInChroot(TestCase): | 586 | class TestRunInChroot(CiTestCase): |
1382 | 600 | """Test the legacy 'RunInChroot'. | 587 | """Test the legacy 'RunInChroot'. |
1383 | 601 | 588 | ||
1384 | 602 | The test works by mocking ChrootableTarget's __enter__ to do nothing. | 589 | The test works by mocking ChrootableTarget's __enter__ to do nothing. |
1385 | @@ -626,7 +613,7 @@ | |||
1386 | 626 | m_subp.assert_called_with(cmd, target=target) | 613 | m_subp.assert_called_with(cmd, target=target) |
1387 | 627 | 614 | ||
1388 | 628 | 615 | ||
1390 | 629 | class TestLoadFile(TestCase): | 616 | class TestLoadFile(CiTestCase): |
1391 | 630 | """Test utility 'load_file'""" | 617 | """Test utility 'load_file'""" |
1392 | 631 | 618 | ||
1393 | 632 | def test_load_file_simple(self): | 619 | def test_load_file_simple(self): |
1394 | @@ -657,7 +644,7 @@ | |||
1395 | 657 | self.assertEqual(loaded_contents, contents) | 644 | self.assertEqual(loaded_contents, contents) |
1396 | 658 | 645 | ||
1397 | 659 | 646 | ||
1399 | 660 | class TestIpAddress(TestCase): | 647 | class TestIpAddress(CiTestCase): |
1400 | 661 | """Test utility 'is_valid_ip{,v4,v6}_address'""" | 648 | """Test utility 'is_valid_ip{,v4,v6}_address'""" |
1401 | 662 | 649 | ||
1402 | 663 | def test_is_valid_ipv6_address(self): | 650 | def test_is_valid_ipv6_address(self): |
1403 | @@ -682,10 +669,11 @@ | |||
1404 | 682 | '2002:4559:1FE2:0000:0000:0000:4559:1FE2')) | 669 | '2002:4559:1FE2:0000:0000:0000:4559:1FE2')) |
1405 | 683 | 670 | ||
1406 | 684 | 671 | ||
1408 | 685 | class TestLoadCommandEnvironment(TestCase): | 672 | class TestLoadCommandEnvironment(CiTestCase): |
1409 | 673 | |||
1410 | 686 | def setUp(self): | 674 | def setUp(self): |
1413 | 687 | self.tmpd = tempfile.mkdtemp() | 675 | super(TestLoadCommandEnvironment, self).setUp() |
1414 | 688 | self.addCleanup(shutil.rmtree, self.tmpd) | 676 | self.tmpd = self.tmp_dir() |
1415 | 689 | all_names = { | 677 | all_names = { |
1416 | 690 | 'CONFIG', | 678 | 'CONFIG', |
1417 | 691 | 'OUTPUT_FSTAB', | 679 | 'OUTPUT_FSTAB', |
1418 | @@ -728,7 +716,7 @@ | |||
1419 | 728 | self.fail("unexpected key error raised: %s" % e) | 716 | self.fail("unexpected key error raised: %s" % e) |
1420 | 729 | 717 | ||
1421 | 730 | 718 | ||
1423 | 731 | class TestWaitForRemoval(TestCase): | 719 | class TestWaitForRemoval(CiTestCase): |
1424 | 732 | def test_wait_for_removal_missing_path(self): | 720 | def test_wait_for_removal_missing_path(self): |
1425 | 733 | with self.assertRaises(ValueError): | 721 | with self.assertRaises(ValueError): |
1426 | 734 | util.wait_for_removal(None) | 722 | util.wait_for_removal(None) |
1427 | @@ -796,14 +784,12 @@ | |||
1428 | 796 | ]) | 784 | ]) |
1429 | 797 | 785 | ||
1430 | 798 | 786 | ||
1432 | 799 | class TestGetEFIBootMGR(TestCase): | 787 | class TestGetEFIBootMGR(CiTestCase): |
1433 | 800 | 788 | ||
1434 | 801 | def setUp(self): | 789 | def setUp(self): |
1435 | 802 | super(TestGetEFIBootMGR, self).setUp() | 790 | super(TestGetEFIBootMGR, self).setUp() |
1440 | 803 | mock_chroot = mock.patch( | 791 | self.add_patch( |
1441 | 804 | 'curtin.util.ChrootableTarget', autospec=False) | 792 | 'curtin.util.ChrootableTarget', 'mock_chroot', autospec=False) |
1438 | 805 | self.mock_chroot = mock_chroot.start() | ||
1439 | 806 | self.addCleanup(mock_chroot.stop) | ||
1442 | 807 | self.mock_in_chroot = mock.MagicMock() | 793 | self.mock_in_chroot = mock.MagicMock() |
1443 | 808 | self.mock_in_chroot.__enter__.return_value = self.mock_in_chroot | 794 | self.mock_in_chroot.__enter__.return_value = self.mock_in_chroot |
1444 | 809 | self.in_chroot_subp_output = [] | 795 | self.in_chroot_subp_output = [] |
1445 | 810 | 796 | ||
1446 | === modified file 'tests/unittests/test_version.py' | |||
1447 | --- tests/unittests/test_version.py 2017-02-06 22:49:33 +0000 | |||
1448 | +++ tests/unittests/test_version.py 2017-08-03 19:32:06 +0000 | |||
1449 | @@ -1,28 +1,16 @@ | |||
1450 | 1 | from unittest import TestCase | ||
1451 | 2 | import mock | 1 | import mock |
1452 | 3 | import subprocess | 2 | import subprocess |
1453 | 4 | import os | 3 | import os |
1454 | 5 | 4 | ||
1455 | 6 | from curtin import version | 5 | from curtin import version |
1456 | 7 | from curtin import __version__ as old_version | 6 | from curtin import __version__ as old_version |
1475 | 8 | 7 | from .helpers import CiTestCase | |
1476 | 9 | 8 | ||
1477 | 10 | class CurtinVersionBase(TestCase): | 9 | |
1478 | 11 | def setUp(self): | 10 | class TestCurtinVersion(CiTestCase): |
1479 | 12 | super(CurtinVersionBase, self).setUp() | 11 | |
1480 | 13 | 12 | def setUp(self): | |
1481 | 14 | def add_patch(self, target, attr): | 13 | super(TestCurtinVersion, self).setUp() |
1464 | 15 | """Patches specified target object and sets it as attr on test | ||
1465 | 16 | instance also schedules cleanup""" | ||
1466 | 17 | m = mock.patch(target, autospec=True) | ||
1467 | 18 | p = m.start() | ||
1468 | 19 | self.addCleanup(m.stop) | ||
1469 | 20 | setattr(self, attr, p) | ||
1470 | 21 | |||
1471 | 22 | |||
1472 | 23 | class TestCurtinVersion(CurtinVersionBase): | ||
1473 | 24 | |||
1474 | 25 | def setUp(self): | ||
1482 | 26 | self.add_patch('subprocess.check_output', 'mock_subp') | 14 | self.add_patch('subprocess.check_output', 'mock_subp') |
1483 | 27 | self.add_patch('os.path', 'mock_path') | 15 | self.add_patch('os.path', 'mock_path') |
1484 | 28 | 16 |
PASSED: Continuous integration, rev:517 /jenkins. ubuntu. com/server/ job/curtin- ci/580/ /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= metal-amd64/ 580 /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= metal-arm64/ 580 /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= metal-ppc64el/ 580 /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= metal-s390x/ 580 /jenkins. ubuntu. com/server/ job/curtin- ci/nodes= vm-i386/ 580
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild: /jenkins. ubuntu. com/server/ job/curtin- ci/580/ rebuild
https:/