Debian Codegraph @

test/verify/check-storage-hidden

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 TestStorageHiddenLuks(storagelib.StorageCase):
14 def test(self):
15 m = self.machine
16 b = self.browser
17
18 mount_point_1 = f"{self.mnt_dir}/mount1"
19
20 self.login_and_go("/storage")
21
22 disk = self.add_ram_disk()
23 b.wait_visible(self.card_row("Storage", name=disk))
24
25 # Create a volume group with a logical volume with a encrypted
26 # filesystem.
27
28 self.click_dropdown(self.card_header("Storage"), "Create LVM2 volume group")
29 self.dialog_wait_open()
30 self.dialog_set_val('name', "TEST")
31 self.dialog_set_val('disks', {disk: True})
32 self.dialog_apply()
33 self.dialog_wait_close()
34
35 self.click_card_row("Storage", name="TEST")
36 b.click(self.card_button("LVM2 logical volumes", "Create new logical volume"))
37 self.dialog({'purpose': "block",
38 'name': "lvol",
39 'size': 48})
40 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "lvol")
41
42 self.click_card_row("LVM2 logical volumes", 1)
43 self.click_card_dropdown("Unformatted data", "Format")
44 self.dialog({"type": "ext4",
45 "crypto": self.default_crypto_type,
46 "name": "FS",
47 "passphrase": "einszweidrei",
48 "passphrase2": "einszweidrei",
49 "mount_point": mount_point_1,
50 "crypto_options": "my-crypto-tag"},
51 secondary=True)
52 self.assert_in_configuration("/dev/TEST/lvol", "crypttab", "options", "my-crypto-tag")
53 self.assert_in_child_configuration("/dev/TEST/lvol", "fstab", "dir", mount_point_1)
54 self.assert_in_lvol_child_configuration("lvol", "crypttab", "options", "my-crypto-tag")
55 self.assert_in_lvol_child_configuration("lvol", "fstab", "dir", mount_point_1)
56 b.click(self.card_parent_link())
57 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), "Filesystem (encrypted)")
58
59 # Now the filesystem is hidden because the LUKS device is
60 # locked. Doubly hide it by deactivating /dev/TEST/lvol
61 self.click_dropdown(self.card_row("LVM2 logical volumes", 1), "Deactivate")
62 self.confirm()
63 b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), "Inactive logical volume")
64
65 # Deleting the volume group should still remove the fstab entry
66 self.click_card_dropdown("LVM2 volume group", "Delete")
67 self.confirm()
68 b.wait_visible(self.card("Storage"))
69 self.assertEqual(m.execute(f"grep {mount_point_1} /etc/fstab || true"), "")
70 self.assertEqual(m.execute(f"grep {'my-crypto-tag'} /etc/crypttab || true"), "")
71
72
73 @testlib.nondestructive
74 class TestStorageHidden(storagelib.StorageCase):
75
76 def testHiddenRaid(self):
77 m = self.machine
78 b = self.browser
79
80 mount_point_2 = f"{self.mnt_dir}/mount2"
81
82 self.login_and_go("/storage")
83
84 disk1 = self.add_loopback_disk()
85 disk2 = self.add_loopback_disk()
86 b.wait_visible(self.card_row("Storage", name=disk1))
87 b.wait_visible(self.card_row("Storage", name=disk2))
88
89 self.dialog_with_retry(trigger=lambda: self.click_dropdown(self.card_header("Storage"),
90 "Create MDRAID device"),
91 expect=lambda: (self.dialog_is_present('disks', disk1) and
92 self.dialog_is_present('disks', disk2)),
93 values={"name": "ARR",
94 "disks": {disk1: True,
95 disk2: True}})
96
97 self.click_card_row("Storage", name="/dev/md/ARR")
98 b.wait_visible(self.card("MDRAID device"))
99 self.click_card_dropdown("Unformatted data", "Format")
100 self.dialog({"type": "ext4",
101 "name": "FS2",
102 "mount_point": mount_point_2})
103 self.assert_in_configuration("/dev/md127", "fstab", "dir", mount_point_2)
104 b.wait_visible(self.card("ext4 filesystem"))
105
106 # we need to wait for mdadm --monitor to stop using the device before delete
107 m.execute("while fuser -s /dev/md127; do sleep 0.2; done", timeout=20)
108
109 self.click_card_dropdown("MDRAID device", "Delete")
110 self.confirm()
111 b.wait_visible(self.card("Storage"))
112 self.assertEqual(m.execute(f"grep {mount_point_2} /etc/fstab || true"), "")
113
114 @testlib.onlyImage("Only test snaps on Ubuntu", "ubuntu*")
115 def testHiddenSnap(self):
116 m = self.machine
117 b = self.browser
118
119 self.login_and_go("/storage")
120
121 # We expect there to be at least one loop back device mounted
122 # somewhere below /snap.
123 snap_loops = []
124 devices = storagelib.json.loads(m.execute("lsblk --json --list --output NAME,TYPE,MOUNTPOINT"))
125 for d in devices["blockdevices"]:
126 if d["type"] == "loop" and d["mountpoint"].startswith("/snap/"):
127 snap_loops.append(d["name"])
128 self.assertGreater(len(snap_loops), 0)
129
130 # Make one more loopback device that we expect to see in the UI.
131 dev = self.add_loopback_disk()
132
133 # Now we wait until the regular loopback device is shown. The
134 # snaps should not be shown.
135 b.wait_visible(self.card_row("Storage", name=dev))
136 for sl in snap_loops:
137 b.wait_not_present(self.card_row("Storage", name=sl))
138
139
140 if __name__ == '__main__':
141 testlib.test_main()