Merge ~adam-collard/maas:less-testtools into maas:master
- Git
- lp:~adam-collard/maas
- less-testtools
- Merge into master
Proposed by
Adam Collard
Status: | Merged |
---|---|
Approved by: | Adam Collard |
Approved revision: | f396ae1444bf35946305debd1af614d955b77778 |
Merge reported by: | MAAS Lander |
Merged at revision: | not available |
Proposed branch: | ~adam-collard/maas:less-testtools |
Merge into: | maas:master |
Diff against target: |
1173 lines (+237/-425) 10 files modified
src/maasserver/api/tests/test_partitions.py (+6/-2) src/provisioningserver/boot/tests/test_boot.py (+6/-7) src/provisioningserver/boot/tests/test_grub.py (+46/-106) src/provisioningserver/boot/tests/test_ipxe.py (+24/-42) src/provisioningserver/boot/tests/test_powernv.py (+20/-38) src/provisioningserver/boot/tests/test_pxe.py (+66/-112) src/provisioningserver/boot/tests/test_s390x.py (+18/-28) src/provisioningserver/boot/tests/test_s390x_partition.py (+28/-50) src/provisioningserver/boot/tests/test_tftppath.py (+5/-8) src/provisioningserver/boot/tests/test_windows.py (+18/-32) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
MAAS Lander | Approve | ||
Anton Troyanov | Approve | ||
Review via email: mp+456782@code.launchpad.net |
Commit message
refactor(
Description of the change
To post a comment you must log in.
Revision history for this message
Anton Troyanov (troyanov) : | # |
review:
Approve
Revision history for this message
MAAS Lander (maas-lander) wrote : | # |
LANDING
-b less-testtools lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas
STATUS: FAILED BUILD
LOG: http://
Revision history for this message
MAAS Lander (maas-lander) wrote : | # |
LANDING
-b less-testtools lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas
STATUS: FAILED BUILD
LOG: http://
- f396ae1... by Adam Collard
-
fix(api/
test_partitions ): avoid creating disks in partition tests Missing partitions shouldn't rely on happening to not find a partition
id that exists.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/src/maasserver/api/tests/test_partitions.py b/src/maasserver/api/tests/test_partitions.py |
2 | index 8962259..fdd51a3 100644 |
3 | --- a/src/maasserver/api/tests/test_partitions.py |
4 | +++ b/src/maasserver/api/tests/test_partitions.py |
5 | @@ -375,7 +375,9 @@ class TestPartitions(APITestCase.ForUser): |
6 | |
7 | def test_format_missing_partition(self): |
8 | self.become_admin() |
9 | - node = factory.make_Node(status=NODE_STATUS.READY) |
10 | + node = factory.make_Node( |
11 | + status=NODE_STATUS.READY, with_boot_disk=False |
12 | + ) |
13 | device = factory.make_PhysicalBlockDevice( |
14 | node=node, |
15 | size=(MIN_PARTITION_SIZE * 4) + PARTITION_TABLE_EXTRA_SPACE, |
16 | @@ -491,7 +493,9 @@ class TestPartitions(APITestCase.ForUser): |
17 | |
18 | def test_unformat_missing_partition(self): |
19 | self.become_admin() |
20 | - node = factory.make_Node(status=NODE_STATUS.READY) |
21 | + node = factory.make_Node( |
22 | + status=NODE_STATUS.READY, with_boot_disk=False |
23 | + ) |
24 | device = factory.make_PhysicalBlockDevice( |
25 | node=node, |
26 | size=(MIN_PARTITION_SIZE * 4) + PARTITION_TABLE_EXTRA_SPACE, |
27 | diff --git a/src/provisioningserver/boot/tests/test_boot.py b/src/provisioningserver/boot/tests/test_boot.py |
28 | index f3568a6..ef6b51c 100644 |
29 | --- a/src/provisioningserver/boot/tests/test_boot.py |
30 | +++ b/src/provisioningserver/boot/tests/test_boot.py |
31 | @@ -15,7 +15,6 @@ from twisted.python import context |
32 | |
33 | from maastesting import get_testing_timeout |
34 | from maastesting.factory import factory |
35 | -from maastesting.matchers import MockCalledOnce, MockCalledOnceWith |
36 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest |
37 | from provisioningserver import boot |
38 | from provisioningserver.boot import ( |
39 | @@ -71,7 +70,7 @@ class TestBootMethod(MAASTestCase): |
40 | |
41 | mock_find = self.patch(boot, "find_mac_via_arp") |
42 | yield context.call(call_context, get_remote_mac) |
43 | - self.assertThat(mock_find, MockCalledOnceWith(remote_host)) |
44 | + mock_find.assert_called_once_with(remote_host) |
45 | |
46 | def test_gen_template_filenames(self): |
47 | purpose = factory.make_name("purpose") |
48 | @@ -132,7 +131,7 @@ class TestBootMethod(MAASTestCase): |
49 | method.get_template, |
50 | *factory.make_names("purpose", "arch", "subarch"), |
51 | ) |
52 | - self.assertThat(mock_try_send_rack_event, MockCalledOnce()) |
53 | + mock_try_send_rack_event.assert_called_once() |
54 | |
55 | def test_get_templates_only_suppresses_ENOENT(self): |
56 | # The IOError arising from trying to load a template that doesn't |
57 | @@ -183,8 +182,8 @@ class TestBootMethod(MAASTestCase): |
58 | |
59 | method.link_bootloader(tmp) |
60 | |
61 | - self.assertThat(mock_maaslog, MockCalledOnce()) |
62 | - self.assertThat(mock_try_send_rack_event, MockCalledOnce()) |
63 | + mock_maaslog.assert_called_once() |
64 | + mock_try_send_rack_event.assert_called_once() |
65 | |
66 | def test_link_bootloader_copies_previous_downloaded_files(self): |
67 | method = FakeBootMethod() |
68 | @@ -237,8 +236,8 @@ class TestBootMethod(MAASTestCase): |
69 | |
70 | method.link_bootloader(new_dir) |
71 | |
72 | - self.assertThat(mock_maaslog, MockCalledOnce()) |
73 | - self.assertThat(mock_try_send_rack_event, MockCalledOnce()) |
74 | + mock_maaslog.assert_called_once() |
75 | + mock_try_send_rack_event.assert_called_once() |
76 | |
77 | def test_compose_template_namespace(self): |
78 | kernel_params = make_kernel_parameters() |
79 | diff --git a/src/provisioningserver/boot/tests/test_grub.py b/src/provisioningserver/boot/tests/test_grub.py |
80 | index ce7064d..2dbc405 100644 |
81 | --- a/src/provisioningserver/boot/tests/test_grub.py |
82 | +++ b/src/provisioningserver/boot/tests/test_grub.py |
83 | @@ -8,15 +8,7 @@ import os |
84 | import random |
85 | import re |
86 | |
87 | -from testtools.matchers import ( |
88 | - ContainsAll, |
89 | - MatchesAll, |
90 | - MatchesRegex, |
91 | - StartsWith, |
92 | -) |
93 | - |
94 | from maastesting.factory import factory |
95 | -from maastesting.matchers import FileContains, MockAnyCall, MockCalledOnce |
96 | from maastesting.testcase import MAASTestCase |
97 | from provisioningserver import boot |
98 | from provisioningserver.boot import BytesReader |
99 | @@ -77,8 +69,8 @@ class TestUEFIAMD64BootMethodRender(MAASTestCase): |
100 | # correctly rendered. |
101 | method = UEFIAMD64BootMethod() |
102 | params = make_kernel_parameters(arch="amd64", purpose="xinstall") |
103 | - fs_host = "(http,%s:5248)/images" % ( |
104 | - convert_host_to_uri_str(params.fs_host) |
105 | + fs_host = re.escape( |
106 | + "(http,%s:5248)/images" % (convert_host_to_uri_str(params.fs_host)) |
107 | ) |
108 | output = method.get_reader( |
109 | backend=None, kernel_params=params, protocol="tftp" |
110 | @@ -88,44 +80,24 @@ class TestUEFIAMD64BootMethodRender(MAASTestCase): |
111 | output = output.read(10000).decode("utf-8") |
112 | # The template has rendered without error. UEFI configurations |
113 | # typically start with a DEFAULT line. |
114 | - self.assertThat(output, StartsWith('set default="0"')) |
115 | + self.assertTrue(output.startswith('set default="0"')) |
116 | # The UEFI parameters are all set according to the options. |
117 | - image_dir = compose_image_path( |
118 | - osystem=params.kernel_osystem, |
119 | - arch=params.arch, |
120 | - subarch=params.subarch, |
121 | - release=params.kernel_release, |
122 | - label=params.kernel_label, |
123 | + image_dir = re.escape( |
124 | + compose_image_path( |
125 | + osystem=params.kernel_osystem, |
126 | + arch=params.arch, |
127 | + subarch=params.subarch, |
128 | + release=params.kernel_release, |
129 | + label=params.kernel_label, |
130 | + ) |
131 | ) |
132 | |
133 | - self.assertThat( |
134 | - output, |
135 | - MatchesAll( |
136 | - MatchesRegex( |
137 | - r".*\s+lin.*cc:\\{\'datasource_list\':" |
138 | - r" \[\'MAAS\'\]\\}end_cc.*", |
139 | - re.MULTILINE | re.DOTALL, |
140 | - ), |
141 | - MatchesRegex( |
142 | - r".*^\s+linux %s/%s/%s .+?$" |
143 | - % ( |
144 | - re.escape(fs_host), |
145 | - re.escape(image_dir), |
146 | - params.kernel, |
147 | - ), |
148 | - re.MULTILINE | re.DOTALL, |
149 | - ), |
150 | - MatchesRegex( |
151 | - r".*^\s+initrd %s/%s/%s$" |
152 | - % ( |
153 | - re.escape(fs_host), |
154 | - re.escape(image_dir), |
155 | - params.initrd, |
156 | - ), |
157 | - re.MULTILINE | re.DOTALL, |
158 | - ), |
159 | - ), |
160 | - ) |
161 | + for regex in [ |
162 | + r"(?ms).*\s+lin.*cc:\\{\'datasource_list\': \[\'MAAS\'\]\\}end_cc.*", |
163 | + rf"(?ms).*^\s+linux {fs_host}/{image_dir}/{params.kernel} .+?$", |
164 | + rf"(?ms).*^\s+initrd {fs_host}/{image_dir}/{params.initrd}$", |
165 | + ]: |
166 | + self.assertRegex(output, regex) |
167 | |
168 | def test_get_reader_http(self): |
169 | # Given the right configuration options, the UEFI configuration is |
170 | @@ -140,7 +112,7 @@ class TestUEFIAMD64BootMethodRender(MAASTestCase): |
171 | output = output.read(10000).decode("utf-8") |
172 | # The template has rendered without error. UEFI configurations |
173 | # typically start with a DEFAULT line. |
174 | - self.assertThat(output, StartsWith('set default="0"')) |
175 | + self.assertTrue(output.startswith('set default="0"')) |
176 | # The UEFI parameters are all set according to the options. |
177 | image_dir = compose_image_path( |
178 | osystem=params.kernel_osystem, |
179 | @@ -150,32 +122,12 @@ class TestUEFIAMD64BootMethodRender(MAASTestCase): |
180 | label=params.kernel_label, |
181 | ) |
182 | |
183 | - self.assertThat( |
184 | - output, |
185 | - MatchesAll( |
186 | - MatchesRegex( |
187 | - r".*\s+lin.*cc:\\{\'datasource_list\':" |
188 | - r" \[\'MAAS\'\]\\}end_cc.*", |
189 | - re.MULTILINE | re.DOTALL, |
190 | - ), |
191 | - MatchesRegex( |
192 | - r".*^\s+linux /images/%s/%s .+?$" |
193 | - % ( |
194 | - re.escape(image_dir), |
195 | - params.kernel, |
196 | - ), |
197 | - re.MULTILINE | re.DOTALL, |
198 | - ), |
199 | - MatchesRegex( |
200 | - r".*^\s+initrd /images/%s/%s$" |
201 | - % ( |
202 | - re.escape(image_dir), |
203 | - params.initrd, |
204 | - ), |
205 | - re.MULTILINE | re.DOTALL, |
206 | - ), |
207 | - ), |
208 | - ) |
209 | + for regex in [ |
210 | + r"(?ms).*\s+lin.*cc:\\{\'datasource_list\': \[\'MAAS\'\]\\}end_cc.*", |
211 | + rf"(?ms).*^\s+linux /images/{image_dir}/{params.kernel} .+?$", |
212 | + rf"(?ms).*^\s+initrd /images/{image_dir}/{params.initrd}$", |
213 | + ]: |
214 | + self.assertRegex(output, regex) |
215 | |
216 | def test_get_reader_with_extra_arguments_does_not_affect_output(self): |
217 | # get_reader() allows any keyword arguments as a safety valve. |
218 | @@ -225,16 +177,12 @@ class TestUEFIAMD64BootMethodRender(MAASTestCase): |
219 | "protocol": random.choice(["tftp", "http"]), |
220 | } |
221 | output = method.get_reader(**options).read(10000).decode("utf-8") |
222 | - self.assertThat( |
223 | - output, |
224 | - ContainsAll( |
225 | - [ |
226 | - "menuentry 'Ephemeral'", |
227 | - f"{params.osystem}/{params.arch}/{params.subarch}", |
228 | - params.kernel, |
229 | - ] |
230 | - ), |
231 | - ) |
232 | + for needle in [ |
233 | + "menuentry 'Ephemeral'", |
234 | + f"{params.osystem}/{params.arch}/{params.subarch}", |
235 | + params.kernel, |
236 | + ]: |
237 | + self.assertIn(needle, output) |
238 | |
239 | def test_get_reader_with_commissioning_purpose(self): |
240 | # If purpose is "commissioning", the config.commissioning.template |
241 | @@ -247,16 +195,12 @@ class TestUEFIAMD64BootMethodRender(MAASTestCase): |
242 | "protocol": random.choice(["tftp", "http"]), |
243 | } |
244 | output = method.get_reader(**options).read(10000).decode("utf-8") |
245 | - self.assertThat( |
246 | - output, |
247 | - ContainsAll( |
248 | - [ |
249 | - "menuentry 'Ephemeral'", |
250 | - f"{params.osystem}/{params.arch}/{params.subarch}", |
251 | - params.kernel, |
252 | - ] |
253 | - ), |
254 | - ) |
255 | + for needle in [ |
256 | + "menuentry 'Ephemeral'", |
257 | + f"{params.osystem}/{params.arch}/{params.subarch}", |
258 | + params.kernel, |
259 | + ]: |
260 | + self.assertIn(needle, output) |
261 | |
262 | |
263 | class TestUEFIAMD64BootMethodRegex(MAASTestCase): |
264 | @@ -459,7 +403,9 @@ class TestUEFIAMD64BootMethod(MAASTestCase): |
265 | bootloader_file_path = os.path.join(tmp, bootloader_file) |
266 | self.assertTrue(os.path.islink(bootloader_file_path)) |
267 | grub_file_path = os.path.join(tmp, "grub", "grub.cfg") |
268 | - self.assertTrue(grub_file_path, FileContains(CONFIG_FILE)) |
269 | + with open(grub_file_path, "r") as fh: |
270 | + contents = fh.read() |
271 | + self.assertIn(CONFIG_FILE, contents) |
272 | |
273 | def test_link_bootloader_copies_previous_downloaded_files(self): |
274 | method = UEFIAMD64BootMethod() |
275 | @@ -501,19 +447,13 @@ class TestUEFIAMD64BootMethod(MAASTestCase): |
276 | |
277 | method._find_and_copy_bootloaders(bootloader_dir) |
278 | |
279 | - self.assertThat( |
280 | - mock_atomic_symlink, |
281 | - MockAnyCall( |
282 | - "/usr/lib/shim/shim.efi.signed", |
283 | - os.path.join(bootloader_dir, "bootx64.efi"), |
284 | - ), |
285 | + mock_atomic_symlink.assert_any_call( |
286 | + "/usr/lib/shim/shim.efi.signed", |
287 | + os.path.join(bootloader_dir, "bootx64.efi"), |
288 | ) |
289 | - self.assertThat( |
290 | - mock_atomic_symlink, |
291 | - MockAnyCall( |
292 | - "/usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed", |
293 | - os.path.join(bootloader_dir, "grubx64.efi"), |
294 | - ), |
295 | + mock_atomic_symlink.assert_any_call( |
296 | + "/usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed", |
297 | + os.path.join(bootloader_dir, "grubx64.efi"), |
298 | ) |
299 | |
300 | def test_link_bootloader_logs_missing_bootloader_files(self): |
301 | @@ -524,4 +464,4 @@ class TestUEFIAMD64BootMethod(MAASTestCase): |
302 | "snapshot" |
303 | ) |
304 | method._find_and_copy_bootloaders(bootloader_dir) |
305 | - self.assertThat(mock_maaslog, MockCalledOnce()) |
306 | + mock_maaslog.assert_called_once() |
307 | diff --git a/src/provisioningserver/boot/tests/test_ipxe.py b/src/provisioningserver/boot/tests/test_ipxe.py |
308 | index c36f97a..0e12406 100644 |
309 | --- a/src/provisioningserver/boot/tests/test_ipxe.py |
310 | +++ b/src/provisioningserver/boot/tests/test_ipxe.py |
311 | @@ -7,7 +7,6 @@ |
312 | import os |
313 | import re |
314 | |
315 | -from testtools.matchers import MatchesAll, MatchesRegex, Not, StartsWith |
316 | from twisted.python.filepath import FilePath |
317 | |
318 | from maastesting.factory import factory |
319 | @@ -56,9 +55,8 @@ class TestIPXEBootMethod(MAASTestCase): |
320 | def test_compose_config_path_does_not_include_tftp_root(self): |
321 | tftproot = self.make_tftp_root().asBytesMode() |
322 | mac = factory.make_mac_address() |
323 | - self.assertThat( |
324 | - compose_config_path(mac), Not(StartsWith(tftproot.path)) |
325 | - ) |
326 | + config_path = compose_config_path(mac) |
327 | + self.assertFalse(config_path.startswith(tftproot.path)) |
328 | |
329 | def test_bootloader_path(self): |
330 | method = IPXEBootMethod() |
331 | @@ -67,7 +65,7 @@ class TestIPXEBootMethod(MAASTestCase): |
332 | def test_bootloader_path_does_not_include_tftp_root(self): |
333 | tftproot = self.make_tftp_root() |
334 | method = IPXEBootMethod() |
335 | - self.assertThat(method.bootloader_path, Not(StartsWith(tftproot.path))) |
336 | + self.assertFalse(method.bootloader_path.startswith(tftproot.path)) |
337 | |
338 | def test_name(self): |
339 | method = IPXEBootMethod() |
340 | @@ -102,8 +100,8 @@ class TestIPXEBootMethodRender(MAASTestCase): |
341 | # correctly rendered. |
342 | method = IPXEBootMethod() |
343 | params = make_kernel_parameters(self, purpose="xinstall") |
344 | - fs_host = "http://%s:5248/images" % ( |
345 | - convert_host_to_uri_str(params.fs_host) |
346 | + fs_host = re.escape( |
347 | + "http://%s:5248/images" % (convert_host_to_uri_str(params.fs_host)) |
348 | ) |
349 | output = method.get_reader(backend=None, kernel_params=params) |
350 | # The output is a BytesReader. |
351 | @@ -111,39 +109,23 @@ class TestIPXEBootMethodRender(MAASTestCase): |
352 | output = output.read(10000).decode("utf-8") |
353 | # The template has rendered without error. iPXE configurations |
354 | # start with #ipxe. |
355 | - self.assertThat(output, StartsWith("#!ipxe")) |
356 | + self.assertTrue(output.startswith("#!ipxe")) |
357 | # The iPXE parameters are all set according to the options. |
358 | - image_dir = compose_image_path( |
359 | - osystem=params.kernel_osystem, |
360 | - arch=params.arch, |
361 | - subarch=params.subarch, |
362 | - release=params.kernel_release, |
363 | - label=params.kernel_label, |
364 | - ) |
365 | - self.assertThat( |
366 | - output, |
367 | - MatchesAll( |
368 | - MatchesRegex( |
369 | - r".*^\s*kernel %s/%s/%s$" |
370 | - % ( |
371 | - re.escape(fs_host), |
372 | - re.escape(image_dir), |
373 | - params.kernel, |
374 | - ), |
375 | - re.MULTILINE | re.DOTALL, |
376 | - ), |
377 | - MatchesRegex( |
378 | - r".*^\s*initrd %s/%s/%s$" |
379 | - % ( |
380 | - re.escape(fs_host), |
381 | - re.escape(image_dir), |
382 | - params.initrd, |
383 | - ), |
384 | - re.MULTILINE | re.DOTALL, |
385 | - ), |
386 | - MatchesRegex(r".*^\s*imgargs .+?$", re.MULTILINE | re.DOTALL), |
387 | - ), |
388 | + image_dir = re.escape( |
389 | + compose_image_path( |
390 | + osystem=params.kernel_osystem, |
391 | + arch=params.arch, |
392 | + subarch=params.subarch, |
393 | + release=params.kernel_release, |
394 | + label=params.kernel_label, |
395 | + ) |
396 | ) |
397 | + for regex in [ |
398 | + rf"(?ms).*^\s*kernel {fs_host}/{image_dir}/{params.kernel}$", |
399 | + rf"(?ms).*^\s*initrd {fs_host}/{image_dir}/{params.initrd}$", |
400 | + r"(?ms).*^\s*imgargs .+?$", |
401 | + ]: |
402 | + self.assertRegex(output, regex) |
403 | |
404 | def test_get_reader_with_local_purpose(self): |
405 | # If purpose is "local", the config.localboot.template should be |
406 | @@ -213,7 +195,7 @@ class TestIPXEBootMethodRegex(MAASTestCase): |
407 | mac = b"aa:bb:cc:dd:ee:ff" |
408 | match = re_config_file.match(b"ipxe.cfg-%s" % mac) |
409 | self.assertIsNotNone(match) |
410 | - self.assertDictEqual( |
411 | + self.assertEqual( |
412 | {"mac": mac, "arch": None, "subarch": None}, match.groupdict() |
413 | ) |
414 | |
415 | @@ -221,7 +203,7 @@ class TestIPXEBootMethodRegex(MAASTestCase): |
416 | mac = b"aa:bb:cc:dd:ee:ff" |
417 | match = re_config_file.match(b"/ipxe.cfg-%s" % mac) |
418 | self.assertIsNotNone(match) |
419 | - self.assertDictEqual( |
420 | + self.assertEqual( |
421 | {"mac": mac, "arch": None, "subarch": None}, match.groupdict() |
422 | ) |
423 | |
424 | @@ -235,7 +217,7 @@ class TestIPXEBootMethodRegex(MAASTestCase): |
425 | arch = factory.make_name("arch", sep="").encode("ascii") |
426 | match = re_config_file.match(b"ipxe.cfg-default-%s" % arch) |
427 | self.assertIsNotNone(match) |
428 | - self.assertDictEqual( |
429 | + self.assertEqual( |
430 | {"mac": None, "arch": arch, "subarch": None}, match.groupdict() |
431 | ) |
432 | |
433 | @@ -246,6 +228,6 @@ class TestIPXEBootMethodRegex(MAASTestCase): |
434 | b"ipxe.cfg-default-%s-%s" % (arch, subarch) |
435 | ) |
436 | self.assertIsNotNone(match) |
437 | - self.assertDictEqual( |
438 | + self.assertEqual( |
439 | {"mac": None, "arch": arch, "subarch": subarch}, match.groupdict() |
440 | ) |
441 | diff --git a/src/provisioningserver/boot/tests/test_powernv.py b/src/provisioningserver/boot/tests/test_powernv.py |
442 | index 869784a..421a48f 100644 |
443 | --- a/src/provisioningserver/boot/tests/test_powernv.py |
444 | +++ b/src/provisioningserver/boot/tests/test_powernv.py |
445 | @@ -7,7 +7,6 @@ |
446 | import re |
447 | from unittest.mock import Mock |
448 | |
449 | -from testtools.matchers import MatchesAll, MatchesRegex, Not, StartsWith |
450 | from twisted.python.filepath import FilePath |
451 | |
452 | from maastesting.factory import factory |
453 | @@ -75,9 +74,8 @@ class TestPowerNVBootMethod(MAASTestCase): |
454 | def test_compose_config_path_does_not_include_tftp_root(self): |
455 | tftproot = self.make_tftp_root().asBytesMode() |
456 | mac = factory.make_mac_address("-") |
457 | - self.assertThat( |
458 | - compose_config_path(mac), Not(StartsWith(tftproot.path)) |
459 | - ) |
460 | + config_path = compose_config_path(mac) |
461 | + self.assertFalse(config_path.startswith(tftproot.path)) |
462 | |
463 | def test_bootloader_path(self): |
464 | method = PowerNVBootMethod() |
465 | @@ -86,7 +84,7 @@ class TestPowerNVBootMethod(MAASTestCase): |
466 | def test_bootloader_path_does_not_include_tftp_root(self): |
467 | tftproot = self.make_tftp_root() |
468 | method = PowerNVBootMethod() |
469 | - self.assertThat(method.bootloader_path, Not(StartsWith(tftproot.path))) |
470 | + self.assertFalse(method.bootloader_path.startswith(tftproot.path)) |
471 | |
472 | def test_name(self): |
473 | method = PowerNVBootMethod() |
474 | @@ -153,8 +151,8 @@ class TestPowerNVBootMethodRenderConfig(MAASTestCase): |
475 | params = make_kernel_parameters( |
476 | self, arch="ppc64el", purpose="xinstall" |
477 | ) |
478 | - fs_host = "http://%s:5248/images" % ( |
479 | - convert_host_to_uri_str(params.fs_host) |
480 | + fs_host = re.escape( |
481 | + "http://%s:5248/images" % (convert_host_to_uri_str(params.fs_host)) |
482 | ) |
483 | output = method.get_reader(backend=None, kernel_params=params) |
484 | # The output is a BytesReader. |
485 | @@ -162,39 +160,23 @@ class TestPowerNVBootMethodRenderConfig(MAASTestCase): |
486 | output = output.read(10000).decode("utf-8") |
487 | # The template has rendered without error. PXELINUX configurations |
488 | # typically start with a DEFAULT line. |
489 | - self.assertThat(output, StartsWith("DEFAULT ")) |
490 | + self.assertTrue(output.startswith("DEFAULT ")) |
491 | # The PXE parameters are all set according to the options. |
492 | - image_dir = compose_image_path( |
493 | - osystem=params.kernel_osystem, |
494 | - arch=params.arch, |
495 | - subarch=params.subarch, |
496 | - release=params.kernel_release, |
497 | - label=params.kernel_label, |
498 | - ) |
499 | - self.assertThat( |
500 | - output, |
501 | - MatchesAll( |
502 | - MatchesRegex( |
503 | - r".*^\s+KERNEL %s/%s/%s$" |
504 | - % ( |
505 | - re.escape(fs_host), |
506 | - re.escape(image_dir), |
507 | - params.kernel, |
508 | - ), |
509 | - re.MULTILINE | re.DOTALL, |
510 | - ), |
511 | - MatchesRegex( |
512 | - r".*^\s+INITRD %s/%s/%s$" |
513 | - % ( |
514 | - re.escape(fs_host), |
515 | - re.escape(image_dir), |
516 | - params.initrd, |
517 | - ), |
518 | - re.MULTILINE | re.DOTALL, |
519 | - ), |
520 | - MatchesRegex(r".*^\s+APPEND .+?$", re.MULTILINE | re.DOTALL), |
521 | - ), |
522 | + image_dir = re.escape( |
523 | + compose_image_path( |
524 | + osystem=params.kernel_osystem, |
525 | + arch=params.arch, |
526 | + subarch=params.subarch, |
527 | + release=params.kernel_release, |
528 | + label=params.kernel_label, |
529 | + ) |
530 | ) |
531 | + for regex in [ |
532 | + rf"(?ms).*^\s+KERNEL {fs_host}/{image_dir}/{params.kernel}$", |
533 | + rf"(?ms).*^\s+INITRD {fs_host}/{image_dir}/{params.initrd}$", |
534 | + r"(?ms).*^\s+APPEND .+?$", |
535 | + ]: |
536 | + self.assertRegex(output, regex) |
537 | |
538 | def test_get_reader_with_extra_arguments_does_not_affect_output(self): |
539 | # get_reader() allows any keyword arguments as a safety valve. |
540 | diff --git a/src/provisioningserver/boot/tests/test_pxe.py b/src/provisioningserver/boot/tests/test_pxe.py |
541 | index cdd8c8c..6a8b6a4 100644 |
542 | --- a/src/provisioningserver/boot/tests/test_pxe.py |
543 | +++ b/src/provisioningserver/boot/tests/test_pxe.py |
544 | @@ -8,17 +8,9 @@ from collections import OrderedDict |
545 | import os |
546 | import re |
547 | |
548 | -from testtools.matchers import ( |
549 | - ContainsAll, |
550 | - MatchesAll, |
551 | - MatchesRegex, |
552 | - Not, |
553 | - StartsWith, |
554 | -) |
555 | from twisted.python.filepath import FilePath |
556 | |
557 | from maastesting.factory import factory |
558 | -from maastesting.matchers import MockAnyCall, MockNotCalled |
559 | from maastesting.testcase import MAASTestCase |
560 | from provisioningserver import kernel_opts |
561 | from provisioningserver.boot import BytesReader |
562 | @@ -86,9 +78,8 @@ class TestPXEBootMethod(MAASTestCase): |
563 | def test_compose_config_path_does_not_include_tftp_root(self): |
564 | tftproot = self.make_tftp_root().asBytesMode() |
565 | mac = factory.make_mac_address("-") |
566 | - self.assertThat( |
567 | - compose_config_path(mac), Not(StartsWith(tftproot.path)) |
568 | - ) |
569 | + config_path = compose_config_path(mac) |
570 | + self.assertFalse(config_path.startswith(tftproot.path)) |
571 | |
572 | def test_bootloader_path(self): |
573 | method = PXEBootMethod() |
574 | @@ -97,7 +88,7 @@ class TestPXEBootMethod(MAASTestCase): |
575 | def test_bootloader_path_does_not_include_tftp_root(self): |
576 | tftproot = self.make_tftp_root() |
577 | method = PXEBootMethod() |
578 | - self.assertThat(method.bootloader_path, Not(StartsWith(tftproot.path))) |
579 | + self.assertFalse(method.bootloader_path.startswith(tftproot.path)) |
580 | |
581 | def test_name(self): |
582 | method = PXEBootMethod() |
583 | @@ -198,23 +189,17 @@ class TestPXEBootMethod(MAASTestCase): |
584 | |
585 | method.link_bootloader(bootloader_dir) |
586 | |
587 | - self.assertThat(mock_atomic_copy, MockNotCalled()) |
588 | - self.assertThat(mock_shutil_copy, MockNotCalled()) |
589 | + mock_atomic_copy.assert_not_called() |
590 | + mock_shutil_copy.assert_not_called() |
591 | for bootloader_file in method.bootloader_files: |
592 | bootloader_src = os.path.join( |
593 | "/usr/lib/syslinux/modules/bios", bootloader_file |
594 | ) |
595 | bootloader_dst = os.path.join(bootloader_dir, bootloader_file) |
596 | - self.assertThat( |
597 | - mock_atomic_symlink, |
598 | - MockAnyCall(bootloader_src, bootloader_dst), |
599 | - ) |
600 | - self.assertThat( |
601 | - mock_atomic_symlink, |
602 | - MockAnyCall( |
603 | - "/usr/lib/syslinux/modules/bios", |
604 | - os.path.join(bootloader_dir, "syslinux"), |
605 | - ), |
606 | + mock_atomic_symlink.assert_any_call(bootloader_src, bootloader_dst) |
607 | + mock_atomic_symlink.assert_any_call( |
608 | + "/usr/lib/syslinux/modules/bios", |
609 | + os.path.join(bootloader_dir, "syslinux"), |
610 | ) |
611 | |
612 | def test_link_bootloader_logs_missing_files(self): |
613 | @@ -281,8 +266,8 @@ class TestPXEBootMethodRender(MAASTestCase): |
614 | # correctly rendered. |
615 | method = PXEBootMethod() |
616 | params = make_kernel_parameters(self, purpose="xinstall") |
617 | - fs_host = "http://%s:5248/images" % ( |
618 | - convert_host_to_uri_str(params.fs_host) |
619 | + fs_host = re.escape( |
620 | + "http://%s:5248/images" % (convert_host_to_uri_str(params.fs_host)) |
621 | ) |
622 | output = method.get_reader(backend=None, kernel_params=params) |
623 | # The output is a BytesReader. |
624 | @@ -290,40 +275,25 @@ class TestPXEBootMethodRender(MAASTestCase): |
625 | output = output.read(10000).decode("utf-8") |
626 | # The template has rendered without error. PXELINUX configurations |
627 | # typically start with a DEFAULT line. |
628 | - self.assertThat(output, StartsWith("DEFAULT ")) |
629 | + self.assertTrue(output.startswith("DEFAULT ")) |
630 | # The PXE parameters are all set according to the options. |
631 | - image_dir = compose_image_path( |
632 | - osystem=params.kernel_osystem, |
633 | - arch=params.arch, |
634 | - subarch=params.subarch, |
635 | - release=params.kernel_release, |
636 | - label=params.kernel_label, |
637 | - ) |
638 | - self.assertThat( |
639 | - output, |
640 | - MatchesAll( |
641 | - MatchesRegex( |
642 | - r".*^\s+KERNEL %s/%s/%s$" |
643 | - % ( |
644 | - re.escape(fs_host), |
645 | - re.escape(image_dir), |
646 | - params.kernel, |
647 | - ), |
648 | - re.MULTILINE | re.DOTALL, |
649 | - ), |
650 | - MatchesRegex( |
651 | - r".*^\s+INITRD %s/%s/%s$" |
652 | - % ( |
653 | - re.escape(fs_host), |
654 | - re.escape(image_dir), |
655 | - params.initrd, |
656 | - ), |
657 | - re.MULTILINE | re.DOTALL, |
658 | - ), |
659 | - MatchesRegex(r".*^\s+APPEND .+?$", re.MULTILINE | re.DOTALL), |
660 | - ), |
661 | + image_dir = re.escape( |
662 | + compose_image_path( |
663 | + osystem=params.kernel_osystem, |
664 | + arch=params.arch, |
665 | + subarch=params.subarch, |
666 | + release=params.kernel_release, |
667 | + label=params.kernel_label, |
668 | + ) |
669 | ) |
670 | |
671 | + for regex in [ |
672 | + rf"(?ms).*^\s+KERNEL {fs_host}/{image_dir}/{params.kernel}$", |
673 | + rf"(?ms).*^\s+INITRD {fs_host}/{image_dir}/{params.initrd}$", |
674 | + r"(?ms).*^\s+APPEND .+?$", |
675 | + ]: |
676 | + self.assertRegex(output, regex) |
677 | + |
678 | def test_get_reader_install_mustang_dtb(self): |
679 | # Architecture specific test. |
680 | # Given the right configuration options, the PXE configuration is |
681 | @@ -342,7 +312,7 @@ class TestPXEBootMethodRender(MAASTestCase): |
682 | output = output.read(10000).decode("utf-8") |
683 | # The template has rendered without error. PXELINUX configurations |
684 | # typically start with a DEFAULT line. |
685 | - self.assertThat(output, StartsWith("DEFAULT ")) |
686 | + self.assertTrue(output.startswith("DEFAULT ")) |
687 | # The PXE parameters are all set according to the options. |
688 | image_dir = compose_image_path( |
689 | osystem=params.kernel_osystem, |
690 | @@ -351,27 +321,13 @@ class TestPXEBootMethodRender(MAASTestCase): |
691 | release=params.kernel_release, |
692 | label=params.kernel_label, |
693 | ) |
694 | - self.assertThat( |
695 | - output, |
696 | - MatchesAll( |
697 | - MatchesRegex( |
698 | - r".*^\s+KERNEL %s/%s$" |
699 | - % (re.escape(image_dir), params.kernel), |
700 | - re.MULTILINE | re.DOTALL, |
701 | - ), |
702 | - MatchesRegex( |
703 | - r".*^\s+INITRD %s/%s$" |
704 | - % (re.escape(image_dir), params.initrd), |
705 | - re.MULTILINE | re.DOTALL, |
706 | - ), |
707 | - MatchesRegex( |
708 | - r".*^\s+FDT %s/%s$" |
709 | - % (re.escape(image_dir), params.boot_dtb), |
710 | - re.MULTILINE | re.DOTALL, |
711 | - ), |
712 | - MatchesRegex(r".*^\s+APPEND .+?$", re.MULTILINE | re.DOTALL), |
713 | - ), |
714 | - ) |
715 | + for regex in [ |
716 | + rf"(?ms).*^\s+KERNEL {image_dir}/{params.kernel}$", |
717 | + rf"(?ms).*^\s+INITRD {image_dir}/{params.initrd}$", |
718 | + rf"(?ms).*^\s+FDT {image_dir}/{params.boot_dtb}$", |
719 | + r"(?ms).*^\s+APPEND .+?$", |
720 | + ]: |
721 | + self.assertRegex(output, regex) |
722 | |
723 | def test_get_reader_xinstall_mustang_dtb(self): |
724 | # Architecture specific test. |
725 | @@ -391,7 +347,7 @@ class TestPXEBootMethodRender(MAASTestCase): |
726 | output = output.read(10000).decode("utf-8") |
727 | # The template has rendered without error. PXELINUX configurations |
728 | # typically start with a DEFAULT line. |
729 | - self.assertThat(output, StartsWith("DEFAULT ")) |
730 | + self.assertTrue(output.startswith("DEFAULT ")) |
731 | # The PXE parameters are all set according to the options. |
732 | image_dir = compose_image_path( |
733 | osystem=params.kernel_osystem, |
734 | @@ -400,27 +356,13 @@ class TestPXEBootMethodRender(MAASTestCase): |
735 | release=params.kernel_release, |
736 | label=params.kernel_label, |
737 | ) |
738 | - self.assertThat( |
739 | - output, |
740 | - MatchesAll( |
741 | - MatchesRegex( |
742 | - r".*^\s+KERNEL %s/%s$" |
743 | - % (re.escape(image_dir), params.kernel), |
744 | - re.MULTILINE | re.DOTALL, |
745 | - ), |
746 | - MatchesRegex( |
747 | - r".*^\s+INITRD %s/%s$" |
748 | - % (re.escape(image_dir), params.initrd), |
749 | - re.MULTILINE | re.DOTALL, |
750 | - ), |
751 | - MatchesRegex( |
752 | - r".*^\s+FDT %s/%s$" |
753 | - % (re.escape(image_dir), params.boot_dtb), |
754 | - re.MULTILINE | re.DOTALL, |
755 | - ), |
756 | - MatchesRegex(r".*^\s+APPEND .+?$", re.MULTILINE | re.DOTALL), |
757 | - ), |
758 | - ) |
759 | + for regex in [ |
760 | + rf"(?ms).*^\s+KERNEL {image_dir}/{params.kernel}$", |
761 | + rf"(?ms).*^\s+INITRD {image_dir}/{params.initrd}$", |
762 | + rf"(?ms).*^\s+FDT {image_dir}/{params.boot_dtb}$", |
763 | + r"(?ms).*^\s+APPEND .+?$", |
764 | + ]: |
765 | + self.assertRegex(output, regex) |
766 | |
767 | def test_get_reader_with_extra_arguments_does_not_affect_output(self): |
768 | # get_reader() allows any keyword arguments as a safety valve. |
769 | @@ -517,11 +459,16 @@ class TestPXEBootMethodRenderConfigScenarios(MAASTestCase): |
770 | self.assertIn(default_section_label, config) |
771 | default_section = dict(config[default_section_label]) |
772 | |
773 | - contains_arch_path = StartsWith( |
774 | - f"{fs_host}/{osystem}/{arch}/{subarch}" |
775 | + self.assertTrue( |
776 | + default_section["KERNEL"].startswith( |
777 | + f"{fs_host}/{osystem}/{arch}/{subarch}" |
778 | + ) |
779 | + ) |
780 | + self.assertTrue( |
781 | + default_section["INITRD"].startswith( |
782 | + f"{fs_host}/{osystem}/{arch}/{subarch}" |
783 | + ) |
784 | ) |
785 | - self.assertThat(default_section["KERNEL"], contains_arch_path) |
786 | - self.assertThat(default_section["INITRD"], contains_arch_path) |
787 | self.assertEqual("2", default_section["IPAPPEND"]) |
788 | |
789 | |
790 | @@ -565,20 +512,27 @@ class TestPXEBootMethodRenderConfigScenariosEnlist(MAASTestCase): |
791 | ["amd64", "--", "i386"], default_section["APPEND"].split() |
792 | ) |
793 | # Both "i386" and "amd64" sections exist. |
794 | - self.assertThat(config, ContainsAll(("i386", "amd64"))) |
795 | + self.assertIn("i386", config) |
796 | + self.assertIn("amd64", config) |
797 | + |
798 | # Each section defines KERNEL, INITRD, and APPEND settings. The |
799 | # KERNEL and INITRD ones contain paths referring to their |
800 | # architectures. |
801 | for section_label in ("i386", "amd64"): |
802 | section = config[section_label] |
803 | - self.assertThat( |
804 | - section, ContainsAll(("KERNEL", "INITRD", "APPEND")) |
805 | + self.assertGreaterEqual( |
806 | + section.keys(), {"KERNEL", "INITRD", "APPEND"} |
807 | + ) |
808 | + self.assertTrue( |
809 | + section["KERNEL"].startswith( |
810 | + f"{fs_host}/{osystem}/{section_label}" |
811 | + ) |
812 | ) |
813 | - contains_arch_path = StartsWith( |
814 | - f"{fs_host}/{osystem}/{section_label}/" |
815 | + self.assertTrue( |
816 | + section["INITRD"].startswith( |
817 | + f"{fs_host}/{osystem}/{section_label}" |
818 | + ) |
819 | ) |
820 | - self.assertThat(section["KERNEL"], contains_arch_path) |
821 | - self.assertThat(section["INITRD"], contains_arch_path) |
822 | self.assertIn("APPEND", section) |
823 | |
824 | |
825 | diff --git a/src/provisioningserver/boot/tests/test_s390x.py b/src/provisioningserver/boot/tests/test_s390x.py |
826 | index 4b4d522..63e05fa 100644 |
827 | --- a/src/provisioningserver/boot/tests/test_s390x.py |
828 | +++ b/src/provisioningserver/boot/tests/test_s390x.py |
829 | @@ -7,7 +7,6 @@ |
830 | import re |
831 | from unittest.mock import Mock |
832 | |
833 | -from testtools.matchers import MatchesAll, MatchesRegex, Not, StartsWith |
834 | from twisted.python.filepath import FilePath |
835 | |
836 | from maastesting.factory import factory |
837 | @@ -74,9 +73,8 @@ class TestS390XBootMethod(MAASTestCase): |
838 | def test_compose_config_path_does_not_include_tftp_root(self): |
839 | tftproot = self.make_tftp_root().asBytesMode() |
840 | mac = factory.make_mac_address("-") |
841 | - self.assertThat( |
842 | - compose_config_path(mac), Not(StartsWith(tftproot.path)) |
843 | - ) |
844 | + config_path = compose_config_path(mac) |
845 | + self.assertFalse(config_path.startswith(tftproot.path)) |
846 | |
847 | def test_bootloader_path(self): |
848 | method = S390XBootMethod() |
849 | @@ -85,7 +83,7 @@ class TestS390XBootMethod(MAASTestCase): |
850 | def test_bootloader_path_does_not_include_tftp_root(self): |
851 | tftproot = self.make_tftp_root() |
852 | method = S390XBootMethod() |
853 | - self.assertThat(method.bootloader_path, Not(StartsWith(tftproot.path))) |
854 | + self.assertFalse(method.bootloader_path.startswith(tftproot.path)) |
855 | |
856 | def test_name(self): |
857 | method = S390XBootMethod() |
858 | @@ -156,31 +154,23 @@ class TestS390XBootMethodRenderConfig(MAASTestCase): |
859 | output = output.read(10000).decode("utf-8") |
860 | # The template has rendered without error. PXELINUX configurations |
861 | # typically start with a DEFAULT line. |
862 | - self.assertThat(output, StartsWith("DEFAULT ")) |
863 | + self.assertTrue(output.startswith("DEFAULT ")) |
864 | # The PXE parameters are all set according to the options. |
865 | - image_dir = compose_image_path( |
866 | - osystem=params.kernel_osystem, |
867 | - arch=params.arch, |
868 | - subarch=params.subarch, |
869 | - release=params.kernel_release, |
870 | - label=params.kernel_label, |
871 | - ) |
872 | - self.assertThat( |
873 | - output, |
874 | - MatchesAll( |
875 | - MatchesRegex( |
876 | - r".*^\s+KERNEL %s/%s$" |
877 | - % (re.escape(image_dir), params.kernel), |
878 | - re.MULTILINE | re.DOTALL, |
879 | - ), |
880 | - MatchesRegex( |
881 | - r".*^\s+INITRD %s/%s$" |
882 | - % (re.escape(image_dir), params.initrd), |
883 | - re.MULTILINE | re.DOTALL, |
884 | - ), |
885 | - MatchesRegex(r".*^\s+APPEND .+?$", re.MULTILINE | re.DOTALL), |
886 | - ), |
887 | + image_dir = re.escape( |
888 | + compose_image_path( |
889 | + osystem=params.kernel_osystem, |
890 | + arch=params.arch, |
891 | + subarch=params.subarch, |
892 | + release=params.kernel_release, |
893 | + label=params.kernel_label, |
894 | + ) |
895 | ) |
896 | + for regex in [ |
897 | + rf"(?ms).*^\s+KERNEL {image_dir}/{params.kernel}$", |
898 | + rf"(?ms).*^\s+INITRD {image_dir}/{params.initrd}$", |
899 | + r"(?ms).*^\s+APPEND .+?$", |
900 | + ]: |
901 | + self.assertRegex(output, regex) |
902 | |
903 | def test_get_reader_with_extra_arguments_does_not_affect_output(self): |
904 | # get_reader() allows any keyword arguments as a safety valve. |
905 | diff --git a/src/provisioningserver/boot/tests/test_s390x_partition.py b/src/provisioningserver/boot/tests/test_s390x_partition.py |
906 | index 790d29f..102d6ae 100644 |
907 | --- a/src/provisioningserver/boot/tests/test_s390x_partition.py |
908 | +++ b/src/provisioningserver/boot/tests/test_s390x_partition.py |
909 | @@ -7,8 +7,6 @@ |
910 | import random |
911 | import re |
912 | |
913 | -from testtools.matchers import MatchesAll, MatchesRegex |
914 | - |
915 | from maastesting.factory import factory |
916 | from maastesting.testcase import MAASTestCase |
917 | from provisioningserver.boot import s390x_partition as s390x_partition_module |
918 | @@ -69,33 +67,22 @@ class TestS390XPartitionBootMethod(MAASTestCase): |
919 | |
920 | output = s390x_partition.get_reader(None, params, mac) |
921 | output = output.read(output.size).decode() |
922 | - image_dir = compose_image_path( |
923 | - osystem=params.kernel_osystem, |
924 | - arch=params.arch, |
925 | - subarch=params.subarch, |
926 | - release=params.kernel_release, |
927 | - label=params.kernel_label, |
928 | + image_dir = re.escape( |
929 | + compose_image_path( |
930 | + osystem=params.kernel_osystem, |
931 | + arch=params.arch, |
932 | + subarch=params.subarch, |
933 | + release=params.kernel_release, |
934 | + label=params.kernel_label, |
935 | + ) |
936 | ) |
937 | |
938 | - self.assertThat( |
939 | - output, |
940 | - MatchesAll( |
941 | - MatchesRegex( |
942 | - r".*^\s+kernel=%s/%s$" |
943 | - % (re.escape(image_dir), params.kernel), |
944 | - re.MULTILINE | re.DOTALL, |
945 | - ), |
946 | - MatchesRegex( |
947 | - r".*^\s+initrd=%s/%s$" |
948 | - % (re.escape(image_dir), params.initrd), |
949 | - re.MULTILINE | re.DOTALL, |
950 | - ), |
951 | - MatchesRegex( |
952 | - r".*^\s+append=.*BOOTIF=%s$" % format_bootif(mac), |
953 | - re.MULTILINE | re.DOTALL, |
954 | - ), |
955 | - ), |
956 | - ) |
957 | + for regex in [ |
958 | + rf"(?ms).*^\s+kernel={image_dir}/{params.kernel}$", |
959 | + rf"(?ms).*^\s+initrd={image_dir}/{params.initrd}$", |
960 | + rf"(?ms).*^\s+append=.*BOOTIF={format_bootif(mac)}+?$", |
961 | + ]: |
962 | + self.assertRegex(output, regex) |
963 | |
964 | def test_get_reader_ephemeral_no_mac(self): |
965 | s390x_partition = S390XPartitionBootMethod() |
966 | @@ -109,30 +96,21 @@ class TestS390XPartitionBootMethod(MAASTestCase): |
967 | |
968 | output = s390x_partition.get_reader(None, params) |
969 | output = output.read(output.size).decode() |
970 | - image_dir = compose_image_path( |
971 | - osystem=params.kernel_osystem, |
972 | - arch=params.arch, |
973 | - subarch=params.subarch, |
974 | - release=params.kernel_release, |
975 | - label=params.kernel_label, |
976 | - ) |
977 | - |
978 | - self.assertThat( |
979 | - output, |
980 | - MatchesAll( |
981 | - MatchesRegex( |
982 | - r".*^\s+kernel=%s/%s$" |
983 | - % (re.escape(image_dir), params.kernel), |
984 | - re.MULTILINE | re.DOTALL, |
985 | - ), |
986 | - MatchesRegex( |
987 | - r".*^\s+initrd=%s/%s$" |
988 | - % (re.escape(image_dir), params.initrd), |
989 | - re.MULTILINE | re.DOTALL, |
990 | - ), |
991 | - MatchesRegex(r".*^\s+append=.*$", re.MULTILINE | re.DOTALL), |
992 | - ), |
993 | + image_dir = re.escape( |
994 | + compose_image_path( |
995 | + osystem=params.kernel_osystem, |
996 | + arch=params.arch, |
997 | + subarch=params.subarch, |
998 | + release=params.kernel_release, |
999 | + label=params.kernel_label, |
1000 | + ) |
1001 | ) |
1002 | + for regex in [ |
1003 | + rf"(?ms).*^\s+kernel={image_dir}/{params.kernel}$", |
1004 | + rf"(?ms).*^\s+initrd={image_dir}/{params.initrd}$", |
1005 | + r"(?ms).*^\s+append=.*$", |
1006 | + ]: |
1007 | + self.assertRegex(output, regex) |
1008 | |
1009 | def test_get_reader_poweroff(self): |
1010 | s390x_partition = S390XPartitionBootMethod() |
1011 | diff --git a/src/provisioningserver/boot/tests/test_tftppath.py b/src/provisioningserver/boot/tests/test_tftppath.py |
1012 | index d14069b..dd3f57d 100644 |
1013 | --- a/src/provisioningserver/boot/tests/test_tftppath.py |
1014 | +++ b/src/provisioningserver/boot/tests/test_tftppath.py |
1015 | @@ -8,9 +8,6 @@ import errno |
1016 | import os.path |
1017 | from unittest.mock import Mock |
1018 | |
1019 | -from testtools.matchers import Not, StartsWith |
1020 | -from testtools.testcase import ExpectedException |
1021 | - |
1022 | from maastesting.factory import factory |
1023 | from maastesting.testcase import MAASTestCase |
1024 | from provisioningserver.boot import tftppath |
1025 | @@ -116,10 +113,8 @@ class TestTFTPPath(MAASTestCase): |
1026 | subarch = factory.make_name("subarch") |
1027 | release = factory.make_name("release") |
1028 | label = factory.make_name("label") |
1029 | - self.assertThat( |
1030 | - compose_image_path(osystem, arch, subarch, release, label), |
1031 | - Not(StartsWith(self.tftproot)), |
1032 | - ) |
1033 | + image_path = compose_image_path(osystem, arch, subarch, release, label) |
1034 | + self.assertFalse(image_path.startswith(self.tftproot)) |
1035 | |
1036 | def test_list_boot_images_copes_with_missing_directory(self): |
1037 | self.assertEqual([], list_boot_images(factory.make_string())) |
1038 | @@ -129,7 +124,9 @@ class TestTFTPPath(MAASTestCase): |
1039 | # PermissionError. It's a subclass of OSError. |
1040 | error = OSError(errno.EACCES, "Deliberate error for testing.") |
1041 | self.patch(tftppath, "list_subdirs", Mock(side_effect=error)) |
1042 | - with ExpectedException(PermissionError): |
1043 | + with self.assertRaisesRegex( |
1044 | + PermissionError, "Deliberate error for testing." |
1045 | + ): |
1046 | list_boot_images(factory.make_string()) |
1047 | |
1048 | def test_list_boot_images_copes_with_empty_directory(self): |
1049 | diff --git a/src/provisioningserver/boot/tests/test_windows.py b/src/provisioningserver/boot/tests/test_windows.py |
1050 | index a82cebf..2db5890 100644 |
1051 | --- a/src/provisioningserver/boot/tests/test_windows.py |
1052 | +++ b/src/provisioningserver/boot/tests/test_windows.py |
1053 | @@ -17,7 +17,6 @@ from twisted.internet.defer import inlineCallbacks |
1054 | |
1055 | from maastesting import get_testing_timeout |
1056 | from maastesting.factory import factory |
1057 | -from maastesting.matchers import MockCalledOnceWith |
1058 | from maastesting.testcase import MAASTestCase, MAASTwistedRunTest |
1059 | from maastesting.twisted import ( |
1060 | always_fail_with, |
1061 | @@ -76,10 +75,9 @@ class TestBcd(MAASTestCase): |
1062 | bcd.hive.value_multiple_strings.return_value = [mock_string] |
1063 | |
1064 | response = bcd._get_loader(bootmgr_elems) |
1065 | - self.assertThat(bcd.hive.node_values, MockCalledOnceWith(mock_elem)) |
1066 | - self.assertThat( |
1067 | - bcd.hive.value_multiple_strings, |
1068 | - MockCalledOnceWith(mock_node_value), |
1069 | + bcd.hive.node_values.assert_called_once_with(mock_elem) |
1070 | + bcd.hive.value_multiple_strings.assert_called_once_with( |
1071 | + mock_node_value |
1072 | ) |
1073 | self.assertEqual(mock_string, response) |
1074 | |
1075 | @@ -94,8 +92,8 @@ class TestBcd(MAASTestCase): |
1076 | bcd.hive.node_name.return_value = mock_name |
1077 | |
1078 | response = bcd._get_loader_elems() |
1079 | - self.assertThat(bcd.hive.node_children, MockCalledOnceWith(mock_uid_1)) |
1080 | - self.assertThat(bcd.hive.node_name, MockCalledOnceWith(mock_child)) |
1081 | + bcd.hive.node_children.assert_called_once_with(mock_uid_1) |
1082 | + bcd.hive.node_name.assert_called_once_with(mock_child) |
1083 | self.assertEqual(response, {mock_name: mock_child}) |
1084 | |
1085 | def test_get_load_options_key(self): |
1086 | @@ -109,10 +107,8 @@ class TestBcd(MAASTestCase): |
1087 | mock_get_loader_elems.return_value = mock_load_elem |
1088 | |
1089 | response = bcd._get_load_options_key() |
1090 | - self.assertThat(mock_get_loader_elems, MockCalledOnceWith()) |
1091 | - self.assertThat( |
1092 | - mock_load_elem.get, MockCalledOnceWith(bcd.LOAD_OPTIONS, None) |
1093 | - ) |
1094 | + mock_get_loader_elems.assert_called_once_with() |
1095 | + mock_load_elem.get.assert_called_once_with(bcd.LOAD_OPTIONS, None) |
1096 | self.assertEqual(response, fake_load_elem) |
1097 | |
1098 | def test_set_load_options(self): |
1099 | @@ -133,15 +129,12 @@ class TestBcd(MAASTestCase): |
1100 | "key": "Element", |
1101 | "value": fake_value.decode("utf-8").encode("utf-16le"), |
1102 | } |
1103 | - self.assertThat(mock_get_load_options_key, MockCalledOnceWith()) |
1104 | - self.assertThat( |
1105 | - bcd.hive.node_add_child, |
1106 | - MockCalledOnceWith(mock_uid_1, bcd.LOAD_OPTIONS), |
1107 | - ) |
1108 | - self.assertThat( |
1109 | - bcd.hive.node_set_value, MockCalledOnceWith(fake_child, compare) |
1110 | + mock_get_load_options_key.assert_called_once_with() |
1111 | + bcd.hive.node_add_child.assert_called_once_with( |
1112 | + mock_uid_1, bcd.LOAD_OPTIONS |
1113 | ) |
1114 | - self.assertThat(bcd.hive.commit, MockCalledOnceWith(None)) |
1115 | + bcd.hive.node_set_value.assert_called_once_with(fake_child, compare) |
1116 | + bcd.hive.commit.assert_called_once_with(None) |
1117 | |
1118 | |
1119 | class TestRequestNodeInfoByMACAddress(MAASTestCase): |
1120 | @@ -163,11 +156,8 @@ class TestRequestNodeInfoByMACAddress(MAASTestCase): |
1121 | client.side_effect = always_succeed_with(sentinel.node_info) |
1122 | d = windows_module.request_node_info_by_mac_address(sentinel.mac) |
1123 | self.assertIs(extract_result(d), sentinel.node_info) |
1124 | - self.assertThat( |
1125 | - client, |
1126 | - MockCalledOnceWith( |
1127 | - RequestNodeInfoByMACAddress, mac_address=sentinel.mac |
1128 | - ), |
1129 | + client.assert_called_once_with( |
1130 | + RequestNodeInfoByMACAddress, mac_address=sentinel.mac |
1131 | ) |
1132 | |
1133 | |
1134 | @@ -200,7 +190,7 @@ class TestWindowsPXEBootMethod(MAASTestCase): |
1135 | windows_module, "request_node_info_by_mac_address" |
1136 | ) |
1137 | method.get_node_info() |
1138 | - self.assertThat(mock_request_node_info, MockCalledOnceWith(mac)) |
1139 | + mock_request_node_info.assert_called_once_with(mac) |
1140 | |
1141 | @inlineCallbacks |
1142 | def test_match_path_pxelinux(self): |
1143 | @@ -377,9 +367,7 @@ class TestWindowsPXEBootMethod(MAASTestCase): |
1144 | method.get_reader( |
1145 | None, kernel_params, path="bcd", local_host=local_host |
1146 | ) |
1147 | - self.assertThat( |
1148 | - mock_compose_bcd, MockCalledOnceWith(kernel_params, local_host) |
1149 | - ) |
1150 | + mock_compose_bcd.assert_called_once_with(kernel_params, local_host) |
1151 | |
1152 | def test_get_reader_static_file(self): |
1153 | method = WindowsPXEBootMethod() |
1154 | @@ -388,9 +376,7 @@ class TestWindowsPXEBootMethod(MAASTestCase): |
1155 | kernel_params = make_kernel_parameters(osystem="windows") |
1156 | |
1157 | method.get_reader(None, kernel_params, path=mock_path) |
1158 | - self.assertThat( |
1159 | - mock_output_static, MockCalledOnceWith(kernel_params, mock_path) |
1160 | - ) |
1161 | + mock_output_static.assert_called_once_with(kernel_params, mock_path) |
1162 | |
1163 | def test_compose_preseed_url(self): |
1164 | url = "http://localhost/MAAS" |
1165 | @@ -414,7 +400,7 @@ class TestWindowsPXEBootMethod(MAASTestCase): |
1166 | self.patch(windows_module, "open") |
1167 | windows_module.open.return_value = io.BytesIO(fake_output) |
1168 | output = method.compose_bcd(kernel_params, local_host) |
1169 | - self.assertThat(windows_module.open, MockCalledOnceWith(ANY, "rb")) |
1170 | + windows_module.open.assert_called_once_with(ANY, "rb") |
1171 | |
1172 | self.assertIsInstance(output, BytesReader) |
1173 | self.assertEqual(fake_output, output.read(-1)) |
UNIT TESTS
-b less-testtools lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas
STATUS: SUCCESS 9e0ad8e19ad9a2a 616c2bd32c
COMMIT: 467a88fab56ba24