Debian Codegraph @

test/verify/check-storage-format

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 TestStorageFormat(storagelib.StorageCase):
14
15 def testFormatTooSmall(self):
16 b = self.browser
17
18 self.login_and_go("/storage")
19
20 # Try to format a disk that is too small for XFS.
21
22 disk = self.add_ram_disk(size=5)
23 self.click_card_row("Storage", name=disk)
24
25 self.click_card_dropdown("Unformatted data", "Format")
26 self.dialog_wait_open()
27 self.dialog_set_val("type", "xfs")
28 self.dialog_set_val("mount_point", f"{self.mnt_dir}/foo")
29 self.dialog_apply_secondary()
30
31 b.wait_in_text("#dialog", "Error creating")
32 b.wait_in_text("#dialog", "too small")
33
34 def testFormatTypes(self):
35 m = self.machine
36 b = self.browser
37
38 self.login_and_go("/storage")
39
40 disk = self.add_loopback_disk(size=320) # xfs minimum size is ~300MB
41 self.click_card_row("Storage", name=disk)
42
43 def check_type(fstype, label_limit):
44 self.click_card_dropdown("Unformatted data", "Format")
45 self.dialog_wait_open()
46 self.dialog_set_val("type", fstype)
47 self.dialog_set_val("mount_point", f"{self.mnt_dir}/foo")
48 self.dialog_set_val("name", "X" * (label_limit + 1))
49 self.dialog_apply_secondary()
50 self.dialog_wait_error("name", "Name cannot be longer than %d characters" % label_limit)
51 self.dialog_set_val("name", "X" * label_limit)
52 self.dialog_apply_secondary()
53 self.dialog_wait_close()
54 b.wait_visible(self.card(fstype + " filesystem"))
55 self.click_card_dropdown(fstype + " filesystem", "Format")
56 self.dialog({"type": "empty"})
57 b.wait_visible(self.card("Unformatted data"))
58
59 def check_unsupported_type(fstype):
60 self.click_card_dropdown("Unformatted data", "Format")
61 self.dialog_wait_open()
62 b.wait_not_present(f'#dialog li[value={fstype}]')
63 self.dialog_cancel()
64 self.dialog_wait_close()
65
66 check_type("xfs", 12)
67 check_type("ext4", 16)
68 check_type("vfat", 11)
69
70 if m.image.startswith("rhel") or m.image.startswith("centos"):
71 check_unsupported_type("ntfs")
72 else:
73 check_type("ntfs", 128)
74
75 # Format without mount point
76 self.click_card_dropdown("Unformatted data", "Format")
77 self.dialog_wait_open()
78 self.dialog_set_val("type", "xfs")
79 self.dialog_apply_secondary()
80 self.dialog_wait_close()
81
82 # Verify button text is 'Format' when no filesystem is selected
83 self.click_card_dropdown("xfs filesystem", "Format")
84 self.dialog_wait_open()
85 self.dialog_set_val("type", "empty")
86 b.wait_text("#dialog .apply", "Format")
87
88 def testFormatCancel(self):
89 m = self.machine
90 b = self.browser
91
92 self.login_and_go("/storage")
93
94 # Make a super slow block device so that we have enough
95 # chances to cancel the operation
96
97 disk = self.add_ram_disk()
98 blocks = int(m.execute(f"blockdev --getsz {disk}"))
99
100 m.execute(f"echo '0 {blocks} delay {disk} 0 500' | dmsetup create superslow")
101 self.click_card_row("Storage", name="/dev/mapper/superslow")
102
103 # Put a signature near the end
104 sigoff = (blocks - 1) * 512
105 m.execute(f"echo hello | dd if=/dev/stdin of=/dev/mapper/superslow bs=1 count=5 seek={sigoff}")
106
107 self.click_card_dropdown("Unformatted data", "Format")
108 self.dialog_wait_open()
109 self.dialog_set_val("erase.on", val=True)
110 self.dialog_set_val("mount_point", f"{self.mnt_dir}/foo")
111 self.dialog_apply()
112 with b.wait_timeout(60):
113 b.wait_in_text("footer", "Erasing /dev/mapper/superslow")
114 self.dialog_cancel()
115 self.dialog_wait_close()
116
117 # The signature should still be there
118 sig = m.execute(f"dd if=/dev/mapper/superslow of=/dev/stdout bs=1 count=5 skip={sigoff}")
119 self.assertEqual(sig, 'hello')
120
121 def testAtBoot(self):
122 m = self.machine
123 b = self.browser
124
125 self.login_and_go("/storage")
126
127 disk = self.add_ram_disk()
128 self.click_card_row("Storage", name=disk)
129
130 def format_partition(expected_at_boot, at_boot, keep, first=False):
131 self.click_card_dropdown("Unformatted data" if first else "ext4 filesystem", "Format")
132 self.dialog_wait_open()
133 self.dialog_wait_val("at_boot", expected_at_boot)
134 self.dialog_set_val("type", "ext4")
135 self.dialog_set_val("mount_point", f"{self.mnt_dir}/foo")
136 self.dialog_set_val("at_boot", at_boot)
137 if keep:
138 self.dialog_set_val("crypto", " keep")
139 else:
140 self.dialog_set_val("crypto", "luks1")
141 self.dialog_set_val("passphrase", "foobarfoo")
142 self.dialog_set_val("passphrase2", "foobarfoo")
143 self.dialog_apply()
144 self.dialog_wait_close()
145
146 format_partition("nofail", "local", keep=False, first=True)
147 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "stop boot on failure")
148 self.assertNotIn("noauto", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
149
150 format_partition("local", "nofail", keep=True)
151 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "ignore failure")
152 self.assertIn("nofail", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
153 self.assert_in_configuration(disk, "crypttab", "options", "nofail")
154
155 format_partition("nofail", "netdev", keep=True)
156 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "after network")
157 self.assertIn("_netdev", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
158 self.assert_in_configuration(disk, "crypttab", "options", "_netdev")
159
160 format_partition("netdev", "never", keep=True)
161 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "never mount")
162 self.assertIn("x-cockpit-never-auto", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
163 self.assert_in_configuration(disk, "crypttab", "options", "noauto")
164
165 format_partition("never", "nofail", keep=False)
166 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "ignore failure")
167 self.assertIn("nofail", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
168 self.assert_in_configuration(disk, "crypttab", "options", "nofail")
169
170 format_partition("nofail", "netdev", keep=False)
171 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "after network")
172 self.assertIn("_netdev", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
173 self.assert_in_configuration(disk, "crypttab", "options", "_netdev")
174
175 format_partition("netdev", "never", keep=False)
176 b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "never mount")
177 self.assertIn("x-cockpit-never-auto", m.execute(f"findmnt --fstab -n -o OPTIONS {self.mnt_dir}/foo"))
178 self.assert_in_configuration(disk, "crypttab", "options", "noauto")
179
180
181 if __name__ == '__main__':
182 testlib.test_main()