Debian Codegraph @

test/verify/check-storage-btrfs

raw
1 #!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)
2
3 #
4 # Copyright (C) 2023 Red Hat, Inc.
5 # SPDX-License-Identifier: LGPL-2.1-or-later
6
7
8 import os.path
9
10 import storagelib
11 import testlib
12
13
14 @testlib.nondestructive
15 @testlib.skipImage('no btrfs support', 'rhel-*', 'centos-*')
16 class TestStorageBtrfs(storagelib.StorageCase):
17 def setUp(self):
18 super().setUp()
19 self.allow_browser_errors("unable to obtain subvolumes for mount point.*")
20 self.allow_browser_errors("unable to obtain default subvolume for mount point.*")
21 self.allow_browser_errors("error: unable to run findmnt.*")
22 self.allow_browser_errors("error: findmnt.*")
23
24 def checkTeardownAction(self, row, label, text):
25 self.browser.wait_in_text(f".modal-footer-teardown tbody:nth-of-type({row}) td[data-label='{label}']", text)
26
27 def testBasic(self):
28 m = self.machine
29 b = self.browser
30
31 mount_point = "/run/butter"
32 # btrfs requires a 128 MB
33 dev_1 = self.add_ram_disk(size=128)
34
35 self.login_and_go("/storage")
36 with b.wait_timeout(30):
37 b.wait_visible(self.card_row("Storage", name="sda"))
38
39 self.click_dropdown(self.card_row("Storage", name=dev_1), "Format")
40 self.dialog({"name": "butter", "type": "btrfs", "mount_point": mount_point, "mount_options.ro": True})
41
42 # disk(s) are part of the volume card
43 b.wait_visible(self.card_row("Storage", location=mount_point))
44 self.assertIn("subvol=/", m.execute(f"findmnt --fstab -n -o OPTIONS {mount_point}"))
45 self.click_card_row("Storage", name="sda")
46
47 b.wait_text(self.card_desc("btrfs filesystem", "Label"), "butter")
48
49 # Can't relabel a filesystem that is mounted read-only
50 b.wait_visible(self.card_desc_action("btrfs filesystem", "Label") + ":disabled")
51
52 # Unmount to change label
53 self.click_dropdown(self.card_row("btrfs filesystem", name="top-level"), "Unmount")
54 self.confirm()
55 b.wait_visible(self.card_row("btrfs filesystem", location=f"{mount_point} (not mounted)"))
56
57 label = "margarine"
58 b.click(self.card_desc_action("btrfs filesystem", "Label"))
59 self.dialog({"name": label})
60 b.wait_text(self.card_desc("btrfs filesystem", "Label"), label)
61
62 # Mount writable for the rest of the test
63 self.click_dropdown(self.card_row("btrfs filesystem", name="top-level"), "Mount")
64 self.dialog({"mount_options.ro": False})
65 b.wait_visible(self.card_row("btrfs filesystem", location=f"{mount_point}"))
66
67 # Change label
68 label = "butter"
69 b.click(self.card_desc_action("btrfs filesystem", "Label"))
70 self.dialog({"name": label})
71 b.wait_text(self.card_desc("btrfs filesystem", "Label"), label)
72
73 # detect new subvolume
74 subvol = "/run/butter/cake"
75 m.execute(f"btrfs subvolume create {subvol}")
76 b.wait_visible(self.card_row("btrfs filesystem", name=os.path.basename(subvol)))
77
78 self.click_dropdown(self.card_row("btrfs filesystem", location=mount_point), "Unmount")
79 self.confirm()
80
81 b.wait_visible(self.card_row("btrfs filesystem", location=f"{mount_point} (not mounted)"))
82 self.click_dropdown(self.card_row("btrfs filesystem", name="top-level"), "Mount")
83 self.confirm()
84
85 b.wait_visible(self.card_row("btrfs filesystem", location=mount_point))
86 # try to mount a subvol
87 subvol_mount_point = "/run/kitchen"
88 self.click_dropdown(self.card_row("btrfs filesystem", name=os.path.basename(subvol)), "Mount")
89 self.dialog({"mount_point": subvol_mount_point})
90
91 b.wait_in_text(self.card_row("btrfs filesystem", location=subvol_mount_point), "cake")
92 b.wait_visible(self.card_row("btrfs filesystem", location=mount_point))
93
94 b.go("#/")
95 b.wait_visible(self.card("Storage"))
96
97 # podman subvolumes are hidden, Cockpit hides everything matching "containers/storage/btrfs/subvolumes"
98 m.execute(f"""
99 mkdir -p /run/kitchen/containers/storage/btrfs/subvolumes
100 btrfs subvolume create /run/kitchen/containers/storage/btrfs/subvolumes/containername
101
102 mkdir -p /run/kitchen/.local/share/containers/storage/btrfs/subvolumes
103 btrfs subvolume create /run/kitchen/.local/share/containers/storage/btrfs/subvolumes/grafana
104
105 btrfs subvolume create {subvol_mount_point}/pancake
106 """)
107
108 b.wait_in_text(self.card_row("Storage", name="pancake"), "btrfs subvolume")
109 b.wait_not_in_text("div[data-test-card-title='Storage']", "containername")
110 b.wait_not_in_text("div[data-test-card-title='Storage']", "grafana")
111
112 m.execute(f"""
113 btrfs subvolume create {mount_point}/candy
114 echo '{dev_1} /run/fstab auto nofail,subvol=/candy 0 0' >> /etc/fstab
115 """)
116
117 b.wait_visible(self.card_row("Storage", location="/run/fstab (not mounted)"))
118
119 # mount outside of fstab, should be cleaned up when re-formatting
120 m.execute(f"""
121 btrfs subvolume create {mount_point}/nonfstab
122 mkdir -p /run/basement
123 mount -o subvol=nonfstab {dev_1} /run/basement
124 """)
125
126 b.wait_visible(self.card_row("Storage", name="nonfstab"))
127
128 # Format the btrfs device
129 # The mount of /run/basement might take some time to be recognized by Cockpit
130 self.dialog_open_with_retry(lambda: self.click_dropdown(self.card_row("Storage", name="sda"), "Format"),
131 lambda: "/run/basement" in b.text("#dialog"))
132 self.checkTeardownAction(1, "Device", os.path.basename(dev_1))
133 self.checkTeardownAction(1, "Location", "/run/basement")
134 self.checkTeardownAction(1, "Action", "unmount, format")
135 self.checkTeardownAction(2, "Location", mount_point)
136 self.checkTeardownAction(2, "Action", "unmount, format")
137 self.checkTeardownAction(3, "Location", subvol_mount_point)
138 self.checkTeardownAction(3, "Action", "unmount, format")
139 self.dialog_set_val("type", "empty")
140 self.dialog_apply()
141
142 # subvolume is gone
143 b.wait_not_present(self.card_row("Storage", name="nonfstab"))
144
145 # All mounts should be gone
146 m.execute(f"! findmnt -n | grep {dev_1}")
147
148 def testCreateSubvolume(self):
149 m = self.machine
150 b = self.browser
151
152 self.login_and_go("/storage")
153
154 disk1 = self.add_ram_disk(size=140)
155 label = "test_subvol"
156 mount_point = "/run/butter"
157 subvol = "cake"
158
159 m.execute(f"mkfs.btrfs -L {label} {disk1}")
160 self.login_and_go("/storage")
161
162 # creation of btrfs partition can take a while on TF.
163 with b.wait_timeout(30):
164 b.wait_visible(self.card_row("Storage", name="sda"))
165
166 root_sel = self.card_row("Storage", name="sda") + " + tr"
167 self.check_dropdown_action_disabled(root_sel, "Create subvolume", "At least one subvolume needs to be mounted")
168
169 self.click_dropdown(root_sel, "Mount")
170 self.dialog({"mount_point": mount_point})
171 self.addCleanupMount(mount_point)
172 b.wait_in_text(self.card_row("Storage", location=mount_point), "btrfs subvolume")
173 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
174
175 # Validation
176 self.dialog_wait_open()
177 self.dialog_apply_secondary()
178 self.dialog_wait_error("name", "Name cannot be empty")
179 self.dialog_set_val("name", "foo/bar")
180 self.dialog_apply_secondary()
181 self.dialog_wait_error("name", "Name cannot contain the character '/'.")
182 self.dialog_set_val("name", "a" * 256)
183 self.dialog_apply_secondary()
184 self.dialog_wait_error("name", "Name cannot be longer than 255 characters.")
185
186 # Without mount point
187 self.dialog_set_val("name", subvol)
188 self.dialog_apply_secondary()
189 self.dialog_wait_close()
190 b.wait_visible(self.card_row("Storage", name=subvol))
191 # no fstab entry
192 m.execute(f"! findmnt --fstab -n | grep subvol={subvol}")
193
194 subvol_mount = "quiche"
195 subvol_mount_point = "/run/oven"
196 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
197
198 # With mount point
199 self.dialog_wait_open()
200 self.dialog_set_val("name", subvol_mount)
201 self.dialog_apply()
202 self.dialog_wait_error("mount_point", "Mount point cannot be empty")
203 self.dialog_set_val("mount_point", mount_point)
204 self.dialog_apply()
205 self.dialog_wait_error("mount_point", "Mount point is already used for btrfs subvolume top-level of test_subvol")
206 self.dialog_set_val("mount_point", subvol_mount_point)
207 self.dialog_apply()
208 self.dialog_wait_close()
209 self.addCleanupMount(subvol_mount_point)
210 b.wait_in_text(self.card_row("Storage", location=subvol_mount_point), "btrfs subvolume")
211
212 # Finding the correct subvolume parent from a non-mounted subvolume
213 m.execute(f"btrfs subvolume create {subvol_mount_point}/pizza")
214 self.click_dropdown(self.card_row("Storage", name="pizza"), "Create subvolume")
215 self.dialog({"name": "pineapple"}, secondary=True)
216 b.wait_in_text(self.card_row("Storage", name="pineapple"), "btrfs subvolume")
217
218 left_subvol_mount = "/run/left"
219 right_subvol_mount = "/run/right"
220
221 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
222 self.dialog({"name": os.path.basename(left_subvol_mount), "mount_point": left_subvol_mount})
223 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
224 self.dialog({"name": os.path.basename(right_subvol_mount), "mount_point": right_subvol_mount})
225 self.addCleanupMount(left_subvol_mount)
226 self.addCleanupMount(right_subvol_mount)
227
228 b.wait_in_text(self.card_row("Storage", location=left_subvol_mount), "btrfs subvolume")
229 b.wait_in_text(self.card_row("Storage", location=right_subvol_mount), "btrfs subvolume")
230
231 self.click_dropdown(self.card_row("Storage", location=left_subvol_mount), "Create subvolume")
232 self.dialog({"name": "links"}, secondary=True)
233 b.wait_in_text(self.card_row("Storage", name="links"), "btrfs subvolume")
234
235 self.click_dropdown(self.card_row("Storage", location=right_subvol_mount), "Create subvolume")
236 self.dialog({"name": "rechts"}, secondary=True)
237 b.wait_in_text(self.card_row("Storage", name="rechts"), "btrfs subvolume")
238
239 # Read only mount, cannot create subvolumes once /run/butter
240 # is unmounted.
241
242 ro_subvol = "/run/ro"
243 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
244 self.dialog({"name": os.path.basename(ro_subvol), "mount_point": ro_subvol, "mount_options.ro": True})
245
246 # We can always create subvolumes as long as a single one is
247 # mounted, even read-only.
248
249 self.click_dropdown(self.card_row("Storage", location="/run/butter"), "Unmount")
250 self.confirm()
251
252 self.click_dropdown(self.card_row("Storage", location=ro_subvol), "Create subvolume")
253 self.dialog({"name": "bot"}, secondary=True)
254 b.wait_visible(self.card_row("Storage", name="bot"))
255
256 def testDeleteSubvolume(self):
257 m = self.machine
258 b = self.browser
259
260 self.login_and_go("/storage")
261
262 disk1 = self.add_ram_disk(size=140)
263 label = "test_subvol"
264 mount_point = "/run/butter"
265 m.execute(f"mkfs.btrfs -L {label} {disk1}")
266 self.login_and_go("/storage")
267
268 # creation of btrfs partition can take a while on TF.
269 with b.wait_timeout(30):
270 b.wait_visible(self.card_row("Storage", name="sda"))
271
272 root_sel = self.card_row("Storage", name="sda") + " + tr"
273 self.click_dropdown(root_sel, "Mount")
274 self.dialog({"mount_point": mount_point})
275 self.addCleanupMount(mount_point)
276
277 # No Delete button for the root subvolume
278 b.click(self.dropdown_toggle(root_sel))
279 b.wait_not_present(self.dropdown_action("Delete"))
280 b.click(self.dropdown_toggle(root_sel))
281
282 # Delete subvolume
283 subvol = "subvol"
284 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
285 self.dialog({"name": subvol}, secondary=True)
286 b.wait_visible(self.card_row("Storage", name=subvol))
287
288 self.click_dropdown(self.card_row("Storage", name=subvol), "Delete")
289 self.checkTeardownAction(1, "Device", subvol)
290 self.checkTeardownAction(1, "Action", "delete")
291 self.confirm()
292 b.wait_not_present(self.card_row("Storage", name=subvol))
293
294 # Delete with subvolume with children
295 child_subvol = "child-subvol"
296 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
297 self.dialog({"name": subvol}, secondary=True)
298 b.wait_visible(self.card_row("Storage", name=subvol))
299
300 self.click_dropdown(self.card_row("Storage", name=subvol), "Create subvolume")
301 self.dialog({"name": child_subvol}, secondary=True)
302 b.wait_visible(self.card_row("Storage", name=child_subvol))
303
304 self.click_dropdown(self.card_row("Storage", name=subvol), "Delete")
305 self.checkTeardownAction(1, "Device", child_subvol)
306 self.checkTeardownAction(1, "Action", "delete")
307 self.checkTeardownAction(2, "Device", subvol)
308 self.checkTeardownAction(2, "Action", "delete")
309 self.confirm()
310
311 b.wait_not_present(self.card_row("Storage", name=child_subvol))
312 b.wait_not_present(self.card_row("Storage", name=subvol))
313
314 # Delete with subvolume with children and self mounted
315 child_subvol = "child-subvol"
316 subvol_mount_point = "/run/delete"
317 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
318 self.dialog({"name": subvol, "mount_point": subvol_mount_point})
319 b.wait_visible(self.card_row("Storage", location=subvol_mount_point))
320
321 self.click_dropdown(self.card_row("Storage", name=subvol), "Create subvolume")
322 self.dialog({"name": child_subvol}, secondary=True)
323 b.wait_visible(self.card_row("Storage", name=child_subvol))
324
325 # Unmount root subvolume and delete child-subvol. That will use the mountpoint of "subvol"
326 self.click_dropdown(root_sel, "Unmount")
327 self.confirm()
328
329 self.click_dropdown(self.card_row("Storage", name=child_subvol), "Delete")
330 self.confirm()
331 b.wait_not_present(self.card_row("Storage", name=child_subvol))
332
333 # Creating inside subvol will also use its mountpoint now
334 self.click_dropdown(self.card_row("Storage", name=subvol), "Create subvolume")
335 self.dialog({"name": child_subvol}, secondary=True)
336 b.wait_visible(self.card_row("Storage", name=child_subvol))
337
338 # Mount the root subvolume again so that we can delete the lot
339 self.click_dropdown(root_sel, "Mount")
340 self.confirm()
341
342 self.click_dropdown(self.card_row("Storage", name=subvol), "Delete")
343 self.checkTeardownAction(1, "Device", child_subvol)
344 self.checkTeardownAction(1, "Action", "delete")
345 self.checkTeardownAction(1, "Device", subvol)
346 self.checkTeardownAction(2, "Location", subvol_mount_point)
347 self.checkTeardownAction(2, "Action", "unmount, delete")
348 self.confirm()
349
350 b.wait_not_present(self.card_row("Storage", location=subvol_mount_point))
351 b.wait_not_present(self.card_row("Storage", name=subvol))
352
353 # Delete with subvolume which is mounted and busy
354 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
355 self.dialog({"name": subvol, "mount_point": subvol_mount_point})
356 b.wait_visible(self.card_row("Storage", location=subvol_mount_point))
357 sleep_pid = m.spawn(f"cd {subvol_mount_point}; sleep infinity", "sleep")
358
359 self.click_dropdown(self.card_row("Storage", location=subvol_mount_point), "Delete")
360 self.checkTeardownAction(1, "Location", subvol_mount_point)
361 self.checkTeardownAction(1, "Action", "unmount, delete")
362 b.wait_in_text(".modal-footer-teardown tbody:nth-of-type(1)", "Currently in use")
363 b.click(".modal-footer-teardown tbody:nth-of-type(1) button")
364 b.wait_in_text(".pf-v6-c-popover", str(sleep_pid))
365
366 self.confirm()
367 b.wait_not_present(self.card_row("Storage", location=subvol_mount_point))
368
369 subvol = "new-subvol"
370 self.click_dropdown(self.card_row("Storage", location=mount_point), "Create subvolume")
371 self.dialog({"name": subvol, "mount_point": subvol_mount_point})
372
373 # We can not delete the last mounted subvolume
374
375 self.click_dropdown(root_sel, "Unmount")
376 self.confirm()
377
378 sel = self.card_row("Storage", location=subvol_mount_point)
379 self.check_dropdown_action_disabled(sel, "Delete", "The last mounted subvolume can not be deleted")
380
381 subvol2 = "subvol2"
382 subvol2_mount_point = "/run/subvol2"
383 child_subvol = "child-subvol"
384 self.click_dropdown(self.card_row("Storage", location=mount_point + " (not mounted)"), "Create subvolume")
385 self.dialog({"name": subvol2, "mount_point": subvol2_mount_point, "mount_options.ro": True})
386 b.wait_visible(self.card_row("Storage", location=subvol2_mount_point))
387 self.assertIn("ro", m.execute(f"findmnt -s -n -o OPTIONS {subvol2_mount_point}"))
388
389 self.click_dropdown(self.card_row("Storage", name=subvol2), "Create subvolume")
390 self.dialog({"name": child_subvol}, secondary=True)
391 b.wait_visible(self.card_row("Storage", name=child_subvol))
392
393 # Now we can delete "new-subvol"
394 self.click_dropdown(self.card_row("Storage", location=subvol_mount_point), "Delete")
395 self.confirm()
396
397 # And also "child-subvol". The readonly-ness of "subvol2" should not matter
398 self.click_dropdown(self.card_row("Storage", name=child_subvol), "Delete")
399 self.confirm()
400
401 def testMultiDevice(self):
402 m = self.machine
403 b = self.browser
404
405 self.login_and_go("/storage")
406
407 disk1 = self.add_ram_disk(size=140)
408 disk2 = self.add_loopback_disk(size=140)
409 label = "raid1"
410 mount_point = "/run/butter"
411 subvol_mount_point = "/run/cake"
412 subvol = "/run/butter/cake"
413 subvol2 = "/run/butter/bread"
414 subvol_name = os.path.basename(subvol)
415
416 m.execute(f"mkfs.btrfs -L {label} -d raid1 {disk1} {disk2}")
417 self.login_and_go("/storage")
418
419 # creation of btrfs partition can take a while on TF.
420 with b.wait_timeout(30):
421 b.wait_visible(self.card_row("Storage", name=label))
422
423 b.wait_in_text(self.card_row("Storage", name=os.path.basename(disk1)), "btrfs device")
424 b.wait_in_text(self.card_row("Storage", name=os.path.basename(disk2)), "btrfs device")
425
426 # We don't allow formatting of multi device btrfs filesystems
427 self.click_dropdown(self.card_row("Storage", name=os.path.basename(disk1)), "Format")
428 self.dialog_wait_open()
429 self.dialog_wait_title(f"{disk1} is in use")
430 self.dialog_cancel()
431 self.dialog_wait_close()
432
433 # mount /
434 self.click_dropdown(self.card_row("Storage", name=label) + " + tr", "Mount")
435 self.dialog({"mount_point": mount_point})
436 b.wait_visible(self.card_row("Storage", location=mount_point))
437 self.addCleanup(m.execute, f"while mountpoint -q {mount_point} && ! umount {mount_point}; do sleep 0.2; done;")
438
439 # create subvolume
440 m.execute(f"""
441 btrfs subvolume create {subvol}
442 btrfs subvolume create {subvol2}
443 """)
444 b.wait_visible(self.card_row("Storage", name=os.path.basename(subvol)))
445
446 self.click_dropdown(self.card_row("Storage", name=os.path.basename(subvol)), "Mount")
447 self.dialog({"mount_point": subvol_mount_point})
448 b.wait_visible(self.card_row("Storage", location=subvol_mount_point))
449 self.addCleanup(m.execute, f"while mountpoint -q {subvol_mount_point} && ! umount {subvol_mount_point}; do sleep 0.2; done;")
450
451 # devices overview
452 self.click_card_row("Storage", name=label)
453 b.wait_visible(self.card_row("btrfs volume", name=disk1))
454 b.wait_visible(self.card_row("btrfs volume", name=disk2))
455
456 # device details page
457 self.click_card_row("btrfs volume", name="sda")
458 b.wait_visible(self.card("btrfs device"))
459 b.wait_text(self.card_desc("btrfs device", "btrfs volume"), "raid1")
460 b.click(self.card_desc("btrfs device", "btrfs volume") + " button")
461 b.wait_visible(self.card("btrfs volume"))
462 b.wait_text(self.card_desc("btrfs volume", "Label"), label)
463
464 # unmount via main page
465 b.go("#/")
466 b.wait_visible(self.card("Storage"))
467
468 self.click_dropdown(self.card_row("Storage", location=subvol_mount_point), "Unmount")
469 self.confirm()
470 b.wait_visible(self.card_row("Storage", location=f"{subvol_mount_point} (not mounted)"))
471
472 self.click_dropdown(self.card_row("Storage", name=os.path.basename(subvol)), "Mount")
473 self.dialog({"mount_point": subvol_mount_point})
474 b.wait_visible(self.card_row("Storage", location=subvol_mount_point))
475
476 mount_options = m.execute(f"findmnt --fstab -n -o OPTIONS {subvol_mount_point}").strip()
477 self.assertIn(f"subvol={subvol_name}", mount_options)
478 self.assertEqual(mount_options.count(subvol_name), 1)
479
480 self.click_dropdown(self.card_row("Storage", name=os.path.basename(subvol2)), "Mount")
481 self.dialog_wait_open()
482 self.dialog_set_val("mount_point", subvol_mount_point)
483 self.dialog_apply()
484 self.dialog_wait_error("mount_point", f"Mount point is already used for btrfs subvolume {os.path.basename(subvol)} of raid1")
485 self.dialog_cancel()
486
487 self.click_dropdown(self.card_row("Storage", location=subvol_mount_point), "Unmount")
488 self.confirm()
489 b.wait_visible(self.card_row("Storage", location=f"{subvol_mount_point} (not mounted)"))
490
491 # Make sure we still have btrfs on both disks and have the entries in fstab
492 self.assertIn('TYPE="btrfs"', m.execute(f"blkid -p {disk1}"))
493 self.assertIn('TYPE="btrfs"', m.execute(f"blkid -p {disk2}"))
494 m.execute(f"findmnt --fstab -n {mount_point}")
495 m.execute(f"findmnt --fstab -n {subvol_mount_point}")
496
497 # Delete the whole thing
498 self.click_dropdown(self.card_row("Storage", name=label), "Delete filesystem")
499 self.confirm()
500
501 # Disks should be empty, fstab entries should be gone
502 m.execute(f"! findmnt --fstab -n {mount_point}")
503 m.execute(f"! findmnt --fstab -n {subvol_mount_point}")
504 m.execute(f"! blkid -p {disk1}")
505 m.execute(f"! blkid -p {disk2}")
506
507 def testDefaultSubvolume(self):
508 m = self.machine
509 b = self.browser
510
511 disk1 = self.add_ram_disk(size=140)
512 label = "test_subvol"
513 mount_point = "/run/butter"
514 subvol = "cake"
515 subvol_path = f"{mount_point}/{subvol}"
516
517 m.execute(f"mkfs.btrfs -L {label} {disk1}")
518 self.login_and_go("/storage")
519
520 # creation of btrfs partition can take a while on TF.
521 with b.wait_timeout(30):
522 b.wait_visible(self.card_row("Storage", name="sda"))
523
524 b.wait_in_text(self.card_row("Storage", name=os.path.basename(disk1)), "btrfs filesystem")
525
526 # Create a new btrfs subvolume and set it as default and mount it.
527 m.execute(f"""
528 mkdir -p {mount_point}
529 mount {disk1} {mount_point}
530 btrfs subvolume create {subvol_path}
531 btrfs subvolume set-default {subvol_path}
532 while mountpoint -q {mount_point} && ! umount {mount_point}; do sleep 0.2; done;
533 mount {disk1} {mount_point}
534 """)
535
536 # Show a warning for mismounting in details.
537 b.wait_visible(self.card_row("Storage", name=subvol))
538 b.wait_visible(self.card_row("Storage", name=subvol) + ' .ct-icon-exclamation-triangle')
539 self.click_card_row("Storage", name=subvol)
540 b.wait_text(self.card_desc("btrfs subvolume", "Name"), subvol)
541
542 # Mount automatically on /run/butter on boot
543 b.click(self.card_button("btrfs subvolume", f"Mount automatically on {mount_point} on boot"))
544 b.wait_not_present(self.card_button("btrfs subvolume", f"Mount automatically on {mount_point} on boot"))
545
546 # No warnings for either subvolume
547 b.go("#/")
548 self.click_card_row("Storage", name=disk1)
549 b.wait_visible(self.card("btrfs filesystem"))
550 b.wait_not_present(self.card_row("btrfs filesystem", name=subvol) + ' .ct-icon-exclamation-triangle')
551 b.wait_not_present(self.card_row("btrfs filesystem", name="/") + ' .ct-icon-exclamation-triangle')
552
553 def testLuksEncrypted(self):
554 m = self.machine
555 b = self.browser
556
557 disk = self.add_ram_disk(size=128)
558 label = "butter"
559 mount_point = "/run/butter"
560 passphrase = "einszweidrei"
561
562 m.execute(f"""
563 echo {passphrase} | cryptsetup luksFormat --pbkdf-memory 32768 {disk}
564 echo {passphrase} | cryptsetup luksOpen {disk} btrfs-test
565 mkfs.btrfs -L {label} /dev/mapper/btrfs-test
566 """)
567
568 self.login_and_go("/storage")
569 # creation of btrfs partition can take a while on TF.
570 with b.wait_timeout(30):
571 b.wait_visible(self.card_row("Storage", name="sda"))
572
573 # Make sure Cockpit hasn't mounted it in a secret
574 # place. This should only happen in Anaconda mode.
575 self.assertNotIn("/dev/mapper/btrfs-test", m.execute("findmnt"))
576
577 b.wait_in_text(self.card_row("Storage", name="sda"), "btrfs filesystem (encrypted)")
578 self.click_dropdown(self.card_row("Storage", name="sda") + " + tr", "Mount")
579 self.dialog({"mount_point": mount_point})
580
581 m.execute(f"""
582 umount {mount_point}
583 cryptsetup luksClose /dev/mapper/btrfs-test
584 """)
585 b.wait_in_text(self.card_row("Storage", name="sda"), "Locked data (encrypted)")
586 self.click_dropdown(self.card_row("Storage", name="sda"), "Unlock")
587 self.dialog({"passphrase": "einszweidrei"})
588 b.wait_in_text(self.card_row("Storage", name="sda"), "btrfs filesystem (encrypted)")
589
590 self.click_dropdown(self.card_row("Storage", name="sda") + " + tr", "Mount")
591 self.confirm()
592 b.wait_in_text(self.card_row("Storage", location=mount_point), "btrfs subvolume")
593
594 def testNoSubvolMount(self):
595 m = self.machine
596 b = self.browser
597
598 disk = self.add_ram_disk(size=128)
599 mount_point = "/run/butter"
600
601 m.execute(f"""
602 mkfs.btrfs -L butter {disk}
603 mkdir -p {mount_point}
604 mount {disk} {mount_point}
605 echo '{disk} {mount_point} auto defaults 0 0' >> /etc/fstab
606 """)
607
608 self.login_and_go("/storage")
609
610 self.click_card_row("Storage", name="sda")
611 b.wait_visible(self.card_row("btrfs filesystem", name="top-level"))
612
613 def testNothingMounted(self):
614 m = self.machine
615 b = self.browser
616
617 disk = self.add_ram_disk(size=128)
618
619 m.execute(f"mkfs.btrfs -L butter {disk}; mount {disk} {self.mnt_dir}; btrfs subvolume create {self.mnt_dir}/home; btrfs subvolume create {self.mnt_dir}/home/backups")
620 m.execute(f"while mountpoint -q {self.mnt_dir} && ! umount {self.mnt_dir}; do sleep 0.2; done;")
621
622 self.login_and_go("/storage")
623
624 self.click_card_row("Storage", name="sda")
625 b.wait_not_present(self.card_row("btrfs filesystem", name="home"))
626 b.wait_not_present(self.card_row("btrfs filesystem", name="backups"))
627
628 # Add some fstab entries. Cockpit should pick up the
629 # subvolumes mentioned in them and show them.
630
631 m.execute(f"echo >>/etc/fstab '{disk} {self.mnt_dir}/home auto noauto,subvol=home 0 0'")
632 m.execute(f"echo >>/etc/fstab '{disk} {self.mnt_dir}/backups auto noauto,subvol=home/backups 0 0'")
633
634 b.wait_text(self.card_row_col("btrfs filesystem", row_name="home", col_index=3), f"{self.mnt_dir}/home (not mounted)")
635 b.wait_text(self.card_row_col("btrfs filesystem", row_name="backups", col_index=3), f"{self.mnt_dir}/backups (not mounted)")
636
637 def testSnapshot(self):
638 m = self.machine
639 b = self.browser
640
641 disk = self.add_ram_disk(size=128)
642 mount_point = "/run/butter"
643
644 snapshot_dir = f"{mount_point}/snapshots"
645 subdir = f"{mount_point}/subdir"
646
647 m.execute(f"""
648 mkfs.btrfs -L butter {disk}
649 mkdir -p {mount_point}
650 mount {disk} {mount_point}
651 echo '{disk} {mount_point} auto defaults 0 0' >> /etc/fstab
652 btrfs subvolume create {subdir} {subdir}/foo {snapshot_dir}
653 btrfs subvolume snapshot {subdir} {snapshot_dir}/snap-1
654 btrfs subvolume snapshot {mount_point} {snapshot_dir}/snap-2
655 """)
656
657 self.login_and_go("/storage")
658
659 self.click_card_row("Storage", name=os.path.basename(subdir))
660 b.wait_text(self.card_desc("btrfs subvolume", "Name"), "subdir")
661 b.wait_visible(self.card_row("btrfs subvolume", table_index=2, name="snap-1"))
662
663 # Normal subvolume does not show under snapshots
664 b.wait_visible(self.card_row("btrfs subvolume", name="foo"))
665 b.wait_not_present(self.card_row("btrfs subvolume", table_index=2, name="foo"))
666
667 # Snapshot details
668 self.click_card_row("btrfs subvolume", table_index=2, name="snap-1")
669 b.wait_text(self.card_desc("btrfs subvolume", "Name"), "snapshots/snap-1")
670 b.wait_text(self.card_desc("btrfs subvolume", "Snapshot origin"), "subdir")
671
672 # Origin link works
673 b.click(self.card_button("btrfs subvolume", "subdir"))
674 b.wait_text(self.card_desc("btrfs subvolume", "Name"), "subdir")
675
676 def testOverMounting(self):
677 # Add a disk and make a btrfs with two subvolumes on it and
678 # then try to mount one in a way that would hide the other.
679
680 disk = self.add_ram_disk(size=128)
681
682 self.login_and_go("/storage")
683 self.click_dropdown(self.card_row("Storage", name=disk), "Format")
684 self.dialog({"name": "butter", "type": "btrfs", "mount_point": "/butter"})
685 self.click_dropdown(self.card_row("Storage", location="/butter"), "Create subvolume")
686 self.dialog({"name": "foo", "mount_point": "/foo"}, secondary=True)
687 self.click_dropdown(self.card_row("Storage", location="/butter"), "Create subvolume")
688 self.dialog({"name": "bar", "mount_point": "/foo/bar"}, secondary=True)
689
690 self.click_dropdown(self.card_row("Storage", location="/foo/bar (not mounted)"), "Mount")
691 self.confirm()
692 self.click_dropdown(self.card_row("Storage", location="/foo (not mounted)"), "Mount")
693 self.dialog_wait_open()
694 self.dialog_apply()
695 self.dialog_wait_error("mount_point", "Filesystems are already mounted below this mountpoint.")
696 self.dialog_wait_error("mount_point", f"{disk} on /foo/bar")
697 self.dialog_cancel()
698
699 self.click_dropdown(self.card_row("Storage", location="/foo/bar"), "Unmount")
700 self.confirm()
701
702
703 if __name__ == '__main__':
704 testlib.test_main()