Debian Codegraph @

test/verify/check-storage-mounting

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) 2015 Red Hat, Inc.
5 # SPDX-License-Identifier: LGPL-2.1-or-later
6
7
8 import storagelib
9 import testlib
10
11
12 @testlib.nondestructive
13 class TestStorageMounting(storagelib.StorageCase):
14
15 def _navigate_root_subvolume(self):
16 b = self.browser
17
18 b.wait_visible(self.card("btrfs filesystem"))
19 self.click_card_row("btrfs filesystem", name="top-level")
20 b.wait_visible(self.card("btrfs subvolume"))
21
22 def testMounting(self):
23 self._testMounting()
24
25 @testlib.skipImage('no btrfs support', 'rhel-*', 'centos-*')
26 def testMountingBtrfs(self):
27 self._testMounting("btrfs", "btrfs subvolume")
28
29 def _testMounting(self, fstype="ext4", filesystem="ext4 filesystem"):
30 m = self.machine
31 b = self.browser
32
33 mount_point_foo = f"{self.mnt_dir}/foo"
34 mount_point_bar = f"{self.mnt_dir}/bar"
35
36 self.login_and_go("/storage")
37
38 # Add a disk
39 disk_size = 128
40 disk = self.add_ram_disk(size=disk_size)
41 self.click_card_row("Storage", name=disk)
42
43 # Format it
44
45 self.click_card_dropdown("Unformatted data", "Format")
46 self.dialog_wait_open()
47 self.dialog_set_val("type", fstype)
48 self.dialog_set_val("name", "FILESYSTEM")
49 self.dialog_set_val("mount_point", "")
50 self.dialog_apply()
51 self.dialog_wait_error("mount_point", "Mount point cannot be empty")
52 self.dialog_set_val("mount_point", mount_point_foo)
53 self.dialog_apply()
54 self.dialog_wait_close()
55 self.assert_in_configuration("/dev/sda", "fstab", "dir", mount_point_foo)
56 if fstype == "btrfs":
57 self._navigate_root_subvolume()
58 else:
59 b.wait_text(self.card_desc(filesystem, "Name"), "FILESYSTEM")
60
61 b.wait_in_text(self.card_desc(filesystem, "Mount point"), mount_point_foo)
62
63 # Keep the mount point busy
64 sleep_pid = m.spawn(f"cd {mount_point_foo}; sleep infinity", "sleep")
65 self.write_file("/etc/systemd/system/keep-mnt-busy.service",
66 f"""
67 [Unit]
68 Description=Test Service
69
70 [Service]
71 WorkingDirectory={mount_point_foo}
72 ExecStart=/usr/bin/sleep infinity
73 """)
74 m.execute("systemctl start keep-mnt-busy")
75
76 b.click(self.card_button(filesystem, "Unmount"))
77 b.wait_in_text("#dialog", str(sleep_pid))
78 b.wait_in_text("#dialog", "sleep infinity")
79 b.wait_in_text("#dialog", "keep-mnt-busy")
80 b.wait_in_text("#dialog", "Test Service")
81 b.wait_in_text("#dialog", "/usr/bin/sleep infinity")
82 b.wait_in_text("#dialog", "The listed processes and services will be forcefully stopped.")
83 if fstype != "btrfs":
84 b.assert_pixels("#dialog", "busy-unmount", mock={"td[data-label='PID']": "1234",
85 "td[data-label='Started']": "a little while ago"})
86 self.confirm()
87 b.wait_in_text(self.card_desc(filesystem, "Mount point"), "The filesystem is not mounted")
88
89 m.execute("! systemctl --quiet is-active keep-mnt-busy")
90
91 if fstype != "btrfs": # tested in test-storage-btrfs
92 b.click(self.card_desc_action(filesystem, "Name"))
93 self.dialog({"name": "filesystem"})
94 b.wait_text(self.card_desc(filesystem, "Name"), "filesystem")
95
96 b.click(self.card_desc(filesystem, "Mount point") + " button")
97 self.dialog(expect={"mount_point": mount_point_foo},
98 values={"mount_point": mount_point_bar})
99 self.assert_in_configuration("/dev/sda", "fstab", "dir", mount_point_bar)
100 b.wait_in_text(self.card_desc(filesystem, "Mount point"), mount_point_bar)
101
102 b.click(self.card_button(filesystem, "Mount"))
103 self.dialog_wait_open()
104 self.dialog_wait_val("mount_point", mount_point_bar)
105 self.dialog_set_val("mount_point", "")
106 self.dialog_apply()
107 self.dialog_wait_error("mount_point", "Mount point cannot be empty")
108 self.dialog_set_val("mount_point", mount_point_bar)
109 self.dialog_apply()
110 self.dialog_wait_close()
111 b.wait_not_in_text(self.card_desc(filesystem, "Mount point"), "The filesystem is not mounted")
112
113 # Set the "Never unlock at boot option"
114 b.click(self.card_desc(filesystem, "Mount point") + " button")
115 self.dialog({"at_boot": "never"})
116 self.assertIn("noauto", m.execute(f"findmnt -s -n -o OPTIONS {mount_point_bar}"))
117 self.assertIn("x-cockpit-never-auto", m.execute(f"findmnt -s -n -o OPTIONS {mount_point_bar}"))
118
119 # Go to overview page and check that the filesystem usage is
120 # displayed correctly.
121
122 if fstype == "btrfs": # TODO: Cockpit/UDisks reports the wrong usage for btrfs subvolumes
123 return
124
125 def wait_ratio_in_range(sel, low, high):
126 b.wait_js_func("""(function (sel, low, high) {
127 var text = ph_text(sel);
128 var match = text.match('([0-9.]+) / ([0-9]+)');
129 if (!match)
130 return false;
131 var ratio = parseFloat(match[1]) / parseFloat(match[2]);
132 return low <= ratio && ratio <= high;
133 })""", sel, low, high)
134
135 b.go("#/")
136 b.wait_visible(self.card_row("Storage", location=mount_point_bar))
137 bar_selector = self.card_row("Storage", location=mount_point_bar) + " td:nth-child(5)"
138 wait_ratio_in_range(bar_selector, 0.0, 0.1)
139 dd_count = disk_size // 2 + 10
140 m.execute(f"dd if=/dev/zero of={mount_point_bar}/zero bs=1M count={dd_count} status=none")
141 wait_ratio_in_range(bar_selector, 0.5, 1.0)
142 m.execute(f"rm {mount_point_bar}/zero")
143 wait_ratio_in_range(bar_selector, 0.0, 0.1)
144
145 self.click_card_row("Storage", location=mount_point_bar)
146 # On rhel-9 we don't use the 'vpd_use_hostno=0' option so S/N is different
147 serial_num = "8000" if b.machine.image.startswith("rhel-9") else "2000"
148 b.wait_in_text(self.card_desc("Solid State Drive", "Serial number"), serial_num) # scsi_debug serial
149
150 # Remove fstab entry
151
152 b.click(self.card_desc(filesystem, "Mount point") + " button")
153 self.dialog(expect={"mount_point": mount_point_bar},
154 values={"mount_point": ""})
155 self.assertEqual(self.configuration_field("/dev/sda", "fstab", "dir"), "")
156 b.wait_in_text(self.card_desc(filesystem, "Mount point"), "The filesystem has no permanent mount point.")
157
158 @testlib.skipImage('no btrfs support', 'rhel-*', 'centos-*')
159 def testMountingHelpBtrfs(self):
160 self._testMountingHelp("btrfs", "btrfs subvolume")
161
162 def testMountingHelp(self):
163 self._testMountingHelp()
164
165 def _testMountingHelp(self, fstype="ext4", filesystem="ext4 filesystem"):
166 m = self.machine
167 b = self.browser
168
169 self.login_and_go("/storage")
170
171 # Add a disk
172 disk = self.add_ram_disk(size=128)
173 self.click_card_row("Storage", name=disk)
174
175 # Format it
176
177 self.click_card_dropdown("Unformatted data", "Format")
178 self.dialog_wait_open()
179 self.dialog_set_val("type", fstype)
180 self.dialog_set_val("name", "FILESYSTEM")
181 self.dialog_set_val("mount_point", f"{self.mnt_dir}/foo")
182 self.dialog_apply()
183 self.dialog_wait_close()
184 if fstype == "btrfs":
185 self._navigate_root_subvolume()
186 b.wait_in_text(self.card_desc("btrfs subvolume", "Mount point"), f"{self.mnt_dir}/foo")
187 self.addCleanupMount(f"{self.mnt_dir}/foo")
188 else:
189 b.wait_text(self.card_desc(filesystem, "Name"), "FILESYSTEM")
190 b.wait_in_text(self.card_desc(filesystem, "Mount point"), f"{self.mnt_dir}/foo")
191
192 # Unmount externally, remount with Cockpit
193
194 m.execute(f"while mountpoint -q {self.mnt_dir}/foo && ! umount {self.mnt_dir}/foo; do sleep 0.2; done;")
195 b.click(self.card_button(filesystem, "Mount now"))
196 b.wait_not_present(self.card_button(filesystem, "Mount now"))
197 b.wait_not_in_text(self.card_desc(filesystem, "Mount point"), "The filesystem is not mounted")
198
199 # Unmount externally, adjust fstab with Cockpit
200
201 m.execute(f"while mountpoint -q {self.mnt_dir}/foo && ! umount {self.mnt_dir}/foo; do sleep 0.2; done;")
202 b.click(self.card_button(filesystem, "Do not mount automatically on boot"))
203 b.wait_not_present(self.card_button(filesystem, "Do not mount automatically on boot"))
204
205 # Mount somewhere else externally while "noauto", unmount with Cockpit
206
207 m.execute(f"mkdir -p {self.mnt_dir}/bar; mount {disk} {self.mnt_dir}/bar")
208 b.click(self.card_button(filesystem, "Unmount now"))
209 b.wait_not_present(self.card_button(filesystem, "Unmount now"))
210
211 # Mount externally, unmount with Cockpit
212
213 m.execute(f"mount {self.mnt_dir}/foo")
214 b.click(self.card_button(filesystem, "Unmount now"))
215 b.wait_not_present(self.card_button(filesystem, "Unmount now"))
216
217 # Mount externally, adjust fstab with Cockpit
218
219 m.execute(f"mount {self.mnt_dir}/foo")
220 b.click(self.card_button(filesystem, "Mount also automatically on boot"))
221 b.wait_not_present(self.card_button(filesystem, "Mount also automatically on boot"))
222
223 # Move mount point externally, move back with Cockpit
224
225 m.execute(f"while mountpoint -q {self.mnt_dir}/foo && ! umount {self.mnt_dir}/foo; do sleep 0.2; done;")
226 m.execute(f"mkdir -p {self.mnt_dir}/bar; mount {disk} {self.mnt_dir}/bar")
227 b.click(self.card_button(filesystem, f"Mount on {self.mnt_dir}/foo now"))
228 b.wait_not_present(self.card_button(filesystem, f"Mount on {self.mnt_dir}/foo now"))
229
230 # Move mount point externally, adjust fstab with Cockpit
231
232 m.execute(f"while mountpoint -q {self.mnt_dir}/foo && ! umount {self.mnt_dir}/foo; do sleep 0.2; done;")
233 m.execute(f"mkdir -p {self.mnt_dir}/bar; mount {disk} {self.mnt_dir}/bar")
234 b.click(self.card_button(filesystem, f"Mount automatically on {self.mnt_dir}/bar on boot"))
235 b.wait_not_present(self.card_button(filesystem, f"Mount automatically on {self.mnt_dir}/bar on boot"))
236
237 # Using noauto,x-systemd.automount should not show a warning
238 m.execute("sed -i -e 's/auto nofail/auto nofail,noauto/' /etc/fstab")
239 b.wait_visible(self.card_button(filesystem, "Mount also automatically on boot"))
240 m.execute("sed -i -e 's/noauto/noauto,x-systemd.automount/' /etc/fstab")
241 b.wait_not_present(self.card_button(filesystem, "Mount also automatically on boot"))
242
243 # Without fstab entry, mount and try to unmount
244 m.execute(f"sed -i '{self.mnt_dir.replace('/', '\\/')}\\/bar/d' /etc/fstab")
245 b.wait_visible(self.card_button(filesystem, f"Mount automatically on {self.mnt_dir}/bar on boot"))
246 b.click(self.card_button(filesystem, "Unmount now"))
247 b.wait_not_present(self.card_button(filesystem, f"Mount automatically on {self.mnt_dir}/bar on boot"))
248
249 def testFstabOptions(self):
250 self._testFstabOptions()
251
252 @testlib.skipImage('no btrfs support', 'rhel-*', 'centos-*')
253 def testFsabOptionsBtrfs(self):
254 self._testFstabOptions("btrfs", "btrfs subvolume")
255
256 def _testFstabOptions(self, filesystem="ext4", desc="ext4 filesystem"):
257 m = self.machine
258 b = self.browser
259
260 self.login_and_go("/storage")
261
262 disk = self.add_ram_disk(size=128)
263 self.click_card_row("Storage", name=disk)
264
265 m.execute(f"mkfs.{filesystem} -L testfs {disk}")
266 if filesystem == "btrfs":
267 self._navigate_root_subvolume()
268 else:
269 b.wait_visible(self.card(desc))
270
271 m.execute("! grep /run/data /etc/fstab")
272 b.click(self.card_button(desc, "Mount"))
273 self.dialog({"mount_point": "/run/data",
274 "mount_options.extra": "x-foo"})
275 m.execute("grep /run/data /etc/fstab")
276 m.execute("grep 'x-foo' /etc/fstab")
277
278 b.wait_in_text(self.card_desc(desc, "Mount point"), "/run/data (ignore failure, x-foo)")
279
280 # absent mntopts and fsck columns implies "defaults"
281 if filesystem == "btrfs":
282 m.execute(r"sed -i '/run\/data/ s/auto.*$/auto subvol=\//' /etc/fstab")
283 else:
284 m.execute(r"sed -i '/run\/data/ s/auto.*$/auto/' /etc/fstab")
285 b.wait_in_text(self.card_desc(desc, "Mount point"), "/run/data (stop boot on failure)")
286
287 @testlib.skipImage("FIXME: ought to work, investigate", "rhel-8-10")
288 def testBadOption(self):
289 m = self.machine
290 b = self.browser
291
292 self.login_and_go("/storage")
293
294 disk = self.add_ram_disk()
295 self.click_card_row("Storage", name=disk)
296
297 self.click_card_dropdown("Unformatted data", "Format")
298 self.dialog({"type": "ext4",
299 "mount_point": f"{self.mnt_dir}/foo"},
300 secondary=True)
301 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "The filesystem is not mounted")
302 self.assertIn("noauto", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
303
304 b.click(self.card_button("ext4 filesystem", "Mount"))
305 self.dialog_wait_open()
306 self.dialog_set_val("mount_options.extra", "hurr")
307 self.dialog_apply()
308 self.dialog_wait_alert("Unknown parameter 'hurr'", "bad option")
309 self.dialog_cancel()
310 self.dialog_wait_close()
311
312 # No changes should have been done to fstab, and the
313 # filesystem should not be mounted.
314 self.assertIn("noauto", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
315 self.assertNotIn("hurr", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
316 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "The filesystem is not mounted")
317
318 # Mount
319 b.click(self.card_button("ext4 filesystem", "Mount"))
320 self.dialog({})
321
322 # Apply the dialog without changes and verify that the
323 # filesystem is still mounted afterwards. Cockpit used to
324 # have a bug where this would accidentally unmount the
325 # filesystem.
326
327 b.click(self.card_desc("ext4 filesystem", "Mount point") + " button")
328 self.dialog({})
329 b.wait_not_in_text(self.card_desc("ext4 filesystem", "Mount point"), "The filesystem is not mounted")
330
331 # Try to set a bad option while the filesystem is mounted.
332 b.click(self.card_desc("ext4 filesystem", "Mount point") + " button")
333 self.dialog_wait_open()
334 self.dialog_set_val("mount_options.extra", "hurr")
335 self.dialog_apply()
336 self.dialog_wait_alert("Unknown parameter 'hurr'", "bad option")
337 self.dialog_cancel()
338 self.dialog_wait_close()
339
340 self.assertNotIn("hurr", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
341 b.wait_not_in_text(self.card_desc("ext4 filesystem", "Mount point"), "The filesystem is not mounted")
342
343 def testAtBoot(self):
344 m = self.machine
345 b = self.browser
346
347 self.login_and_go("/storage")
348
349 disk = self.add_ram_disk()
350 self.click_card_row("Storage", name=disk)
351
352 self.click_card_dropdown("Unformatted data", "Format")
353 self.dialog({"type": "ext4",
354 "mount_point": f"{self.mnt_dir}/foo",
355 "at_boot": "local",
356 "crypto": "luks1",
357 "passphrase": "foobarfoo",
358 "passphrase2": "foobarfoo"},
359 secondary=True)
360 b.wait_in_text(self.card_desc("Filesystem", "Mount point"), "The filesystem is not mounted")
361 self.assertIn("noauto", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
362 self.assert_in_configuration(disk, "crypttab", "options", "noauto")
363
364 def mount(expected_at_boot, at_boot):
365 b.click(self.card_button("Filesystem", "Mount"))
366 self.dialog_wait_open()
367 self.dialog_wait_val("at_boot", expected_at_boot)
368 self.dialog_set_val("at_boot", at_boot)
369 self.dialog_set_val("passphrase", "foobarfoo")
370 self.dialog_apply()
371 self.dialog_wait_close()
372
373 def unmount():
374 b.click(self.card_button("ext4 filesystem", "Unmount"))
375 self.dialog_wait_open()
376 self.dialog_apply()
377 self.dialog_wait_close()
378 b.wait_in_text(self.card_desc("Filesystem", "Mount point"), "The filesystem is not mounted")
379
380 mount("local", "nofail")
381 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "ignore failure")
382 self.assertIn("nofail", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
383 self.assert_in_configuration(disk, "crypttab", "options", "nofail")
384 unmount()
385
386 mount("nofail", "netdev")
387 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "after network")
388 self.assertIn("_netdev", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
389 self.assert_in_configuration(disk, "crypttab", "options", "_netdev")
390 unmount()
391
392 mount("netdev", "never")
393 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "never mount")
394 self.assertIn("x-cockpit-never-auto", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
395 self.assert_in_configuration(disk, "crypttab", "options", "noauto")
396 unmount()
397
398
399 @testlib.nondestructive
400 @testlib.skipImage("cryptsetup uses too much memory, OOM on our test VMs", "rhel-8-*")
401 class TestStorageMountingLUKS(storagelib.StorageCase):
402 def testEncryptedMountingHelp(self):
403 m = self.machine
404 b = self.browser
405
406 self.login_and_go("/storage")
407
408 # Add a disk
409 disk = self.add_ram_disk()
410 self.click_card_row("Storage", name=disk)
411
412 # Format it with encryption
413
414 self.click_card_dropdown("Unformatted data", "Format")
415 self.dialog_wait_open()
416 self.dialog_set_val("type", "ext4")
417 self.dialog_set_val("name", "FILESYSTEM")
418 self.dialog_set_val("crypto", self.default_crypto_type)
419 self.dialog_set_val("crypto_options", "xxx")
420 self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja")
421 self.dialog_set_val("passphrase2", "vainu-reku-toma-rolle-kaja")
422 self.dialog_set_val("mount_point", f"{self.mnt_dir}/foo")
423 self.dialog_set_val("at_boot", "netdev")
424 self.dialog_apply()
425 self.dialog_wait_close()
426 b.wait_text(self.card_desc("ext4 filesystem", "Name"), "FILESYSTEM")
427 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), f"{self.mnt_dir}/foo")
428
429 # Unmount and lock externally, unlock and remount with Cockpit
430
431 m.execute(f"while mountpoint -q {self.mnt_dir}/foo && ! umount {self.mnt_dir}/foo; do sleep 0.2; done;")
432 m.execute(f"udisksctl lock -b {disk}")
433 # wait until the UI updated to the locking
434 b.wait_text(self.card_desc("Encryption", "Cleartext device"), "-")
435 b.click(self.card_button("Filesystem", "Mount now"))
436 self.dialog({"passphrase": "vainu-reku-toma-rolle-kaja"})
437 b.wait_not_in_text(self.card_desc("ext4 filesystem", "Mount point"),
438 "The filesystem is not mounted")
439 b.wait_not_present(self.card_button("ext4 filesystem", "Mount now"))
440
441 # Unmount and lock externally, adjust fstab with Cockpit
442
443 m.execute(f"while mountpoint -q {self.mnt_dir}/foo && ! umount {self.mnt_dir}/foo; do sleep 0.2; done;")
444 m.execute(f"udisksctl lock -b {disk}")
445 # wait until the UI updated to the locking
446 b.wait_text(self.card_desc("Encryption", "Cleartext device"), "-")
447 b.click(self.card_button("Filesystem", "Do not mount automatically on boot"))
448 b.wait_not_present(self.card_button("Filesystem", "Do not mount automatically on boot"))
449
450 # Unlock and mount externally, unmount and lock with Cockpit
451
452 m.execute(f"echo -n vainu-reku-toma-rolle-kaja | udisksctl unlock --key-file /dev/stdin -b {disk}")
453 m.execute(f"mount {self.mnt_dir}/foo")
454 b.click(self.card_button("ext4 filesystem", "Unmount now"))
455 b.wait_visible(self.card("Filesystem"))
456 b.wait_not_present(self.card_button("Filesystem", "Unmount now"))
457
458 # Unlock and mount externally, adjust fstab with Cockpit
459
460 m.execute(f"echo -n vainu-reku-toma-rolle-kaja | udisksctl unlock --key-file /dev/stdin -b {disk}")
461 m.execute(f"mount {self.mnt_dir}/foo")
462 b.click(self.card_button("ext4 filesystem", "Mount also automatically on boot"))
463 b.wait_not_present(self.card_button("ext4 filesystem", "Mount also automatically on boot"))
464 b.wait_visible(self.card("ext4 filesystem"))
465
466 # Add noauto to crypttab (but not fstab), remove with Cockpit
467
468 m.execute("sed -i -e 's/xxx/xxx,noauto/' /etc/crypttab")
469 b.click(self.card_button("ext4 filesystem", "Unlock automatically on boot"))
470 b.wait_not_present(self.card_button("ext4 filesystem", "Unlock automatically on boot"))
471 b.wait_visible(self.card("ext4 filesystem"))
472
473 # Add noauto to crypttab (but not fstab), add also to fstab with Cockpit
474
475 m.execute("sed -i -e 's/xxx/xxx,noauto/' /etc/crypttab")
476 b.click(self.card_button("ext4 filesystem", "Do not mount automatically on boot"))
477 b.wait_not_present(self.card_button("ext4 filesystem", "Do not mount automatically on boot"))
478 b.wait_visible(self.card("ext4 filesystem"))
479
480 def testDuplicateMountPoints(self):
481 m = self.machine
482 b = self.browser
483
484 self.login_and_go("/storage")
485
486 self.addCleanupVG("test")
487 self.addCleanup(m.execute, "cryptsetup close $(lsblk -lno NAME /dev/test/one | tail -1) || true")
488 self.addCleanupMount("/run/data")
489
490 # Quickly make two logical volumes
491 disk = self.add_ram_disk()
492 b.wait_visible(self.card_row("Storage", name=disk))
493 m.execute(f"vgcreate test {disk}; lvcreate test -n one -L 20M; lvcreate test -n two -L 20M")
494 self.click_card_row("Storage", name="test")
495 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "one")
496 b.wait_text(self.card_row_col("LVM2 logical volumes", 2, 1), "two")
497
498 # Encrypt and format the first and give it /run/data as the mount point
499 self.click_card_row("LVM2 logical volumes", 1)
500 self.click_card_dropdown("Unformatted data", "Format")
501 self.dialog({"type": "ext4",
502 "crypto": self.default_crypto_type,
503 "passphrase": "vainu-reku-toma-rolle-kaja",
504 "passphrase2": "vainu-reku-toma-rolle-kaja",
505 "mount_point": "/run/data"})
506 b.click(self.card_parent_link())
507 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), "ext4 filesystem (encrypted)")
508 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 3), "/run/data")
509
510 # Format the second and also try to use /run/data as the mount point
511 self.click_card_row("LVM2 logical volumes", 2)
512 self.click_card_dropdown("Unformatted data", "Format")
513 self.dialog_wait_open()
514 self.dialog_set_val("type", "ext4")
515 self.dialog_set_val("mount_point", "/run/data")
516 self.dialog_apply()
517 self.dialog_wait_error("mount_point", "Mount point is already used for /dev/test/one")
518 self.dialog_set_val("mount_point", "/run/data") # to clear the error
519 self.dialog_apply_secondary()
520 self.dialog_wait_error("mount_point", "Mount point is already used for /dev/test/one")
521 self.dialog_cancel()
522 self.dialog_wait_close()
523 b.click(self.card_parent_link())
524
525 # Format the first and re-use /run/data as the mount point.
526 # This should be allowed.
527 self.click_card_row("LVM2 logical volumes", 1)
528 self.click_card_dropdown("ext4 filesystem", "Format")
529 self.dialog({"type": "ext4",
530 "mount_point": "/run/data"})
531 b.click(self.card_parent_link())
532 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), "ext4 filesystem (encrypted)")
533 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 3), "/run/data")
534
535 def testNeverAuto(self):
536 m = self.machine
537 b = self.browser
538
539 self.login_and_go("/storage")
540
541 # Add a disk and format it with luks and a filesystem, but with "Never unlock at boot"
542 disk = self.add_ram_disk()
543 self.click_card_row("Storage", name=disk)
544
545 self.click_card_dropdown("Unformatted data", "Format")
546 self.dialog({"type": "ext4",
547 "crypto": self.default_crypto_type,
548 "passphrase": "vainu-reku-toma-rolle-kaja",
549 "passphrase2": "vainu-reku-toma-rolle-kaja",
550 "at_boot": "never",
551 "mount_point": f"{self.mnt_dir}/foo"})
552 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "never mount at boot")
553
554 # The filesystem should be mounted but have the "noauto"
555 # option in both fstab and crypttab
556 self.wait_mounted("ext4 filesystem")
557 self.assertIn("noauto", m.execute(f"grep {self.mnt_dir}/foo /etc/fstab || true"))
558 self.assertNotEqual(m.execute("grep noauto /etc/crypttab"), "")
559
560 # Unmounting should keep the noauto option, as always
561 b.click(self.card_button("ext4 filesystem", "Unmount"))
562 self.confirm()
563 self.wait_not_mounted("Filesystem")
564 self.assertIn("noauto", m.execute(f"grep {self.mnt_dir}/foo /etc/fstab || true"))
565 self.assertNotEqual(m.execute("grep noauto /etc/crypttab"), "")
566
567 # Mounting should also keep the "noauto", but it should not show up in the extra options
568 b.click(self.card_button("Filesystem", "Mount"))
569 self.dialog_check({"mount_options.extra": False})
570 self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja")
571 self.dialog_apply()
572 self.dialog_wait_close()
573 self.wait_mounted("ext4 filesystem")
574 self.assertIn("noauto", m.execute(f"grep {self.mnt_dir}/foo /etc/fstab || true"))
575 self.assertNotEqual(m.execute("grep noauto /etc/crypttab"), "")
576
577 # As should updating the mount information
578 b.click(self.card_desc("ext4 filesystem", "Mount point") + " button")
579 self.dialog_check({"mount_options.extra": False})
580 self.dialog_apply()
581 self.dialog_wait_close()
582 self.assertIn("noauto", m.execute(f"grep {self.mnt_dir}/foo /etc/fstab || true"))
583 self.assertNotEqual(m.execute("grep noauto /etc/crypttab"), "")
584
585 # Removing "noauto" from fstab but not from crypttab externally should show a warning
586 m.execute("sed -i -e 's/noauto//' /etc/fstab")
587 b.wait_in_text(self.card("ext4 filesystem"),
588 "The filesystem is configured to be automatically mounted on boot but its encryption container will not be unlocked at that time.")
589 b.click(self.card_button("ext4 filesystem", "Do not mount automatically"))
590 b.wait_not_present(self.card_button("ext4 filesystem", "Do not mount automatically"))
591
592 def testOverMounting(self):
593 m = self.machine
594 b = self.browser
595
596 # Disable pre-loading packagekit, otherwise udisks oom's.
597 self.disable_preload("packagekit")
598
599 self.login_and_go("/storage")
600
601 # Add a disk and make two partitions on it, one on self.mnt_dir/foo
602 # and one on self.mnt_dir/foo/bar
603
604 disk = self.add_ram_disk(100)
605 self.click_card_row("Storage", name=disk)
606
607 self.click_card_dropdown("Solid State Drive", "Create partition table")
608 self.dialog({"type": "gpt"})
609 b.wait_text(self.card_row_col("GPT partitions", 1, 1), "Free space")
610
611 self.click_dropdown(self.card_row("GPT partitions", 1), "Create partition")
612 self.dialog({"type": "ext4",
613 "size": 50,
614 "crypto": self.default_crypto_type,
615 "passphrase": "vainu-reku-toma-rolle-kaja",
616 "passphrase2": "vainu-reku-toma-rolle-kaja",
617 "mount_point": f"{self.mnt_dir}/foo"},
618 secondary=True)
619 b.wait_text(self.card_row_col("GPT partitions", 1, 3), f"{self.mnt_dir}/foo (not mounted)")
620
621 self.click_dropdown(self.card_row("GPT partitions", 2), "Create partition")
622 self.dialog({"type": "ext4",
623 "crypto": self.default_crypto_type,
624 "passphrase": "vainu-reku-toma-rolle-kaja",
625 "passphrase2": "vainu-reku-toma-rolle-kaja",
626 "mount_point": f"{self.mnt_dir}/foo/bar"},
627 secondary=True)
628 b.wait_text(self.card_row_col("GPT partitions", 2, 3), f"{self.mnt_dir}/foo/bar (not mounted)")
629
630 # Mount self.mnt_dir/foo/bar first and check that mounting self.mnt_dir/foo is
631 # rejected
632
633 self.click_dropdown(self.card_row("GPT partitions", 2), "Mount")
634 self.dialog({"passphrase": "vainu-reku-toma-rolle-kaja"})
635 b.wait_text(self.card_row_col("GPT partitions", 2, 3), f"{self.mnt_dir}/foo/bar")
636
637 self.click_dropdown(self.card_row("GPT partitions", 1), "Mount")
638 self.dialog_wait_open()
639 self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja")
640 self.dialog_apply()
641 self.dialog_wait_error("mount_point", "Filesystems are already mounted below this mountpoint.")
642 b.assert_pixels("#dialog", "overmounting-rejection")
643 self.dialog_cancel()
644 self.dialog_wait_close()
645
646 # Unmount self.mnt_dir/foo/bar, mount self.mnt_dir/foo, mount self.mnt_dir/foo/bar
647 # again and then check that unmounting self.mnt_dir/foo will also
648 # unmount self.mnt_dir/foo/bar.
649
650 self.click_dropdown(self.card_row("GPT partitions", 2), "Unmount")
651 self.confirm()
652
653 self.click_dropdown(self.card_row("GPT partitions", 1), "Mount")
654 self.dialog({"passphrase": "vainu-reku-toma-rolle-kaja"})
655 b.wait_text(self.card_row_col("GPT partitions", 1, 3), f"{self.mnt_dir}/foo")
656
657 self.click_dropdown(self.card_row("GPT partitions", 2), "Mount")
658 self.dialog({"passphrase": "vainu-reku-toma-rolle-kaja"})
659 b.wait_text(self.card_row_col("GPT partitions", 2, 3), f"{self.mnt_dir}/foo/bar")
660
661 self.click_dropdown(self.card_row("GPT partitions", 1), "Unmount")
662 self.dialog_wait_open()
663 b.wait_in_text(f"#dialog tr:contains('{self.mnt_dir}/foo/bar')", "unmount")
664 self.dialog_apply()
665 self.dialog_wait_close()
666
667 # Now self.mnt_dir/foo/bar should be noauto.
668 self.assert_in_configuration(disk + "2", "crypttab", "options", "noauto")
669 self.assertIn("noauto", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo/bar"))
670
671 # Mount them again and check that initializing the disk will
672 # unmount self.mnt_dir/foo/bar first.
673
674 self.click_dropdown(self.card_row("GPT partitions", 1), "Mount")
675 self.dialog({"passphrase": "vainu-reku-toma-rolle-kaja"})
676 b.wait_text(self.card_row_col("GPT partitions", 1, 3), f"{self.mnt_dir}/foo")
677
678 self.click_dropdown(self.card_row("GPT partitions", 2), "Mount")
679 self.dialog({"passphrase": "vainu-reku-toma-rolle-kaja"})
680 b.wait_text(self.card_row_col("GPT partitions", 2, 3), f"{self.mnt_dir}/foo/bar")
681
682 # Sometimes a block device is still held open by
683 # something immediately after locking it. This
684 # prevents the kernel from reading the new partition
685 # table. Let's just retry in that case.
686
687 def first_setup():
688 b.wait_text("#dialog tbody:nth-of-type(1) td[data-label=Location]", f"{self.mnt_dir}/foo/bar")
689 b.wait_text("#dialog tbody:nth-of-type(2) td[data-label=Location]", f"{self.mnt_dir}/foo")
690
691 self.dialog_with_error_retry(trigger=lambda: self.click_card_dropdown("Solid State Drive",
692 "Create partition table"),
693 first_setup=first_setup,
694 errors=["Timed out waiting for object"])
695
696 b.wait_text(self.card_row_col("GPT partitions", 1, 1), "Free space")
697
698
699 if __name__ == '__main__':
700 testlib.test_main()