| 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 os |
| 9 |
|
| 10 |
import storagelib |
| 11 |
import testlib |
| 12 |
|
| 13 |
|
| 14 |
class TestStorageResize(storagelib.StorageCase): |
| 15 |
|
| 16 |
# on RHEL 8, provide enough RAM for cryptsetup's PBKDF (https://issues.redhat.com/browse/RHEL-8258) |
| 17 |
# On any newer OS, cryptsetup gets along with less RAM |
| 18 |
provision = { |
| 19 |
"0": {"memory_mb": 1400 if os.environ.get("TEST_OS", "").startswith("rhel-8-") else None} |
| 20 |
} |
| 21 |
|
| 22 |
def checkResize(self, fsys, crypto, can_shrink, can_grow, shrink_needs_unmount=None, grow_needs_unmount=None): |
| 23 |
m = self.machine |
| 24 |
b = self.browser |
| 25 |
|
| 26 |
need_passphrase = crypto and self.default_crypto_type == "luks2" |
| 27 |
filesystem_desc = f"{fsys} filesystem" |
| 28 |
filesystem_desc_enc = filesystem_desc |
| 29 |
if crypto: |
| 30 |
filesystem_desc_enc = filesystem_desc + " (encrypted)" |
| 31 |
|
| 32 |
self.login_and_go("/storage") |
| 33 |
disk = m.add_disk("500M", serial="DISK1") |
| 34 |
b.wait_visible(self.card_row("Storage", name=f"/dev/{disk['dev']}")) |
| 35 |
|
| 36 |
m.execute("vgcreate TEST /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_DISK1; udevadm trigger") |
| 37 |
b.wait_visible(self.card_row("Storage", name="TEST")) |
| 38 |
|
| 39 |
m.execute("lvcreate TEST -n vol -L 320m") # minimum xfs size is ~300MB |
| 40 |
b.wait_visible(self.card_row("Storage", name="vol")) |
| 41 |
|
| 42 |
self.click_card_row("Storage", name="TEST") |
| 43 |
b.wait_visible(self.card("LVM2 volume group")) |
| 44 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "vol") |
| 45 |
|
| 46 |
self.click_dropdown(self.card_row("LVM2 logical volumes", 1), "Format") |
| 47 |
self.dialog_wait_open() |
| 48 |
self.dialog_wait_apply_enabled() |
| 49 |
self.dialog_set_val("name", "FSYS") |
| 50 |
self.dialog_set_val("type", fsys) |
| 51 |
self.dialog_set_val("mount_point", f"{self.mnt_dir}/foo") |
| 52 |
if crypto: |
| 53 |
self.dialog_set_val("crypto", self.default_crypto_type) |
| 54 |
self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja") |
| 55 |
self.dialog_set_val("passphrase2", "vainu-reku-toma-rolle-kaja") |
| 56 |
self.dialog_apply() |
| 57 |
with b.wait_timeout(60): |
| 58 |
self.dialog_wait_close() |
| 59 |
|
| 60 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), filesystem_desc_enc) |
| 61 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 3), f"{self.mnt_dir}/foo") |
| 62 |
|
| 63 |
if can_grow: |
| 64 |
self.click_card_row("LVM2 logical volumes", 1) |
| 65 |
b.click(self.card_button("LVM2 logical volume", "Grow")) |
| 66 |
self.dialog_wait_open() |
| 67 |
self.dialog_wait_apply_enabled() |
| 68 |
if grow_needs_unmount: |
| 69 |
b.wait_in_text("#dialog", "unmount, grow") |
| 70 |
self.dialog_set_val("size", 400) |
| 71 |
if need_passphrase: |
| 72 |
self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja") |
| 73 |
self.dialog_apply() |
| 74 |
self.dialog_wait_close() |
| 75 |
b.wait_in_text(self.card_desc("LVM2 logical volume", "Size"), "398 MB") |
| 76 |
with b.wait_timeout(30): |
| 77 |
self.wait_mounted(filesystem_desc) |
| 78 |
size = int(m.execute(f"df -k --output=size {self.mnt_dir}/foo | tail -1").strip()) |
| 79 |
self.assertGreater(size, 300000) |
| 80 |
else: |
| 81 |
self.wait_card_button_disabled("LVM2 logical volume", "Grow") |
| 82 |
|
| 83 |
if can_shrink: |
| 84 |
b.click(self.card_button("LVM2 logical volume", "Shrink")) |
| 85 |
self.dialog_wait_open() |
| 86 |
self.dialog_wait_apply_enabled() |
| 87 |
if shrink_needs_unmount: |
| 88 |
b.wait_in_text("#dialog", "unmount, shrink") |
| 89 |
self.dialog_set_val("size", 200) |
| 90 |
if need_passphrase: |
| 91 |
self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja") |
| 92 |
self.dialog_apply() |
| 93 |
self.dialog_wait_close() |
| 94 |
b.wait_in_text(self.card_desc("LVM2 logical volume", "Size"), "201 MB") |
| 95 |
self.wait_mounted(filesystem_desc) |
| 96 |
size = int(m.execute(f"df -k --output=size {self.mnt_dir}/foo | tail -1").strip()) |
| 97 |
self.assertLess(size, 300000) |
| 98 |
else: |
| 99 |
self.wait_card_button_disabled("LVM2 logical volume", "Shrink") |
| 100 |
|
| 101 |
def testResizeExt4(self): |
| 102 |
self.checkResize("ext4", crypto=False, |
| 103 |
can_shrink=True, shrink_needs_unmount=True, |
| 104 |
can_grow=True, grow_needs_unmount=False) |
| 105 |
|
| 106 |
def testResizeXfs(self): |
| 107 |
self.checkResize("xfs", crypto=False, |
| 108 |
can_shrink=False, |
| 109 |
can_grow=True, grow_needs_unmount=False) |
| 110 |
|
| 111 |
@testlib.skipImage("NTFS not supported on RHEL", "rhel-*", "centos-*") |
| 112 |
def testResizeNtfs(self): |
| 113 |
self.checkResize("ntfs", crypto=False, |
| 114 |
can_shrink=True, shrink_needs_unmount=True, |
| 115 |
can_grow=True, grow_needs_unmount=True) |
| 116 |
|
| 117 |
@testlib.skipImage("TODO: arch does not mount the LUKS partition after growing", "arch") |
| 118 |
def testResizeLuks(self): |
| 119 |
self.checkResize("ext4", crypto=True, |
| 120 |
can_shrink=True, shrink_needs_unmount=True, |
| 121 |
can_grow=True, grow_needs_unmount=False) |
| 122 |
|
| 123 |
def shrink_extfs(self, fs_dev, size): |
| 124 |
# fsadm can automatically unmount and check the fs when doing |
| 125 |
# a resize, but in that case it will try to remount it |
| 126 |
# afterwards. This remounting will mostly fail because |
| 127 |
# UDisks2 has removed the mount point directory in the mean |
| 128 |
# time. But sometimes it will succeed. So we take control |
| 129 |
# and unmount the fs explicitly. But then we also need to |
| 130 |
# check it explicitly. |
| 131 |
# |
| 132 |
self.machine.execute(f"(! findmnt -S '{fs_dev}' || umount '{fs_dev}'); fsadm -y check '{fs_dev}'; fsadm -y resize '{fs_dev}' '{size}'; udevadm trigger") |
| 133 |
|
| 134 |
def testGrowShrinkHelp(self): |
| 135 |
m = self.machine |
| 136 |
b = self.browser |
| 137 |
|
| 138 |
self.login_and_go("/storage") |
| 139 |
disk = m.add_disk("500M", serial="DISK1") |
| 140 |
b.wait_visible(self.card_row("Storage", name=f"/dev/{disk['dev']}")) |
| 141 |
|
| 142 |
m.execute("vgcreate TEST /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_DISK1") |
| 143 |
b.wait_visible(self.card_row("Storage", name="TEST")) |
| 144 |
|
| 145 |
m.execute("lvcreate TEST -n vol -L 200m") |
| 146 |
b.wait_visible(self.card_row("Storage", name="vol")) |
| 147 |
|
| 148 |
self.click_card_row("Storage", name="TEST") |
| 149 |
b.wait_visible(self.card("LVM2 volume group")) |
| 150 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "vol") |
| 151 |
|
| 152 |
mountpoint = f"{self.mnt_dir}/foo" |
| 153 |
self.click_dropdown(self.card_row("LVM2 logical volumes", 1), "Format") |
| 154 |
self.dialog_wait_open() |
| 155 |
self.dialog_set_val("name", "FSYS") |
| 156 |
self.dialog_set_val("type", "ext4") |
| 157 |
self.dialog_set_val("mount_point", mountpoint) |
| 158 |
self.dialog_apply() |
| 159 |
self.dialog_wait_close() |
| 160 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), "ext4 filesystem") |
| 161 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 3), mountpoint) |
| 162 |
|
| 163 |
# Click on the card to check the label |
| 164 |
self.click_card_row("LVM2 logical volumes", 1) |
| 165 |
b.wait_text(self.card_desc("ext4 filesystem", "Name"), "FSYS") |
| 166 |
|
| 167 |
# Grow the logical volume and let Cockpit grow the filesystem |
| 168 |
m.execute("lvresize TEST/vol -L+100M") |
| 169 |
b.click(self.card_button("LVM2 logical volume", "Grow content")) |
| 170 |
b.wait_not_present(self.card_button("LVM2 logical volume", "Grow content")) |
| 171 |
size = int(m.execute(f"df -k --output=size {mountpoint} | tail -1").strip()) |
| 172 |
self.assertGreater(size, 250000) |
| 173 |
|
| 174 |
# Shrink the filesystem and let Cockpit shrink the logical volume |
| 175 |
|
| 176 |
fs_dev = m.execute("lsblk -pnl /dev/TEST/vol -o NAME | tail -1").strip() |
| 177 |
self.shrink_extfs(fs_dev, "200M") |
| 178 |
|
| 179 |
b.click(self.card_button("ext4 filesystem", "Mount now")) |
| 180 |
self.wait_mounted("ext4 filesystem") |
| 181 |
b.click(self.card_button("LVM2 logical volume", "Shrink volume")) |
| 182 |
b.wait_not_present(self.card_button("LVM2 logical volume", "Shrink volume")) |
| 183 |
size = int(m.execute("lvs TEST/vol -o lv_size --noheading --units b --nosuffix")) |
| 184 |
self.assertLess(size, 250000000) |
| 185 |
|
| 186 |
@testlib.skipImage("cryptsetup uses too much memory, OOM on our test VMs", "rhel-8-*") |
| 187 |
def testGrowShrinkEncryptedHelp(self): |
| 188 |
m = self.machine |
| 189 |
b = self.browser |
| 190 |
|
| 191 |
self.login_and_go("/storage") |
| 192 |
disk = m.add_disk("500M", serial="DISK1") |
| 193 |
b.wait_visible(self.card_row("Storage", name=f"/dev/{disk['dev']}")) |
| 194 |
|
| 195 |
m.execute("vgcreate TEST /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_DISK1") |
| 196 |
b.wait_visible(self.card_row("Storage", name="TEST")) |
| 197 |
|
| 198 |
m.execute("lvcreate TEST -n vol -L 200m") |
| 199 |
b.wait_visible(self.card_row("Storage", name="vol")) |
| 200 |
|
| 201 |
self.click_card_row("Storage", name="TEST") |
| 202 |
b.wait_visible(self.card("LVM2 volume group")) |
| 203 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "vol") |
| 204 |
|
| 205 |
mountpoint = f"{self.mnt_dir}/foo" |
| 206 |
self.click_dropdown(self.card_row("LVM2 logical volumes", 1), "Format") |
| 207 |
self.dialog_wait_open() |
| 208 |
self.dialog_set_val("name", "FSYS") |
| 209 |
self.dialog_set_val("type", "ext4") |
| 210 |
self.dialog_set_val("crypto", self.default_crypto_type) |
| 211 |
self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja") |
| 212 |
self.dialog_set_val("passphrase2", "vainu-reku-toma-rolle-kaja") |
| 213 |
self.dialog_set_val("mount_point", mountpoint) |
| 214 |
self.dialog_apply() |
| 215 |
self.dialog_wait_close() |
| 216 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), "ext4 filesystem (encrypted)") |
| 217 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 3), mountpoint) |
| 218 |
|
| 219 |
# Grow the logical volume and let Cockpit grow the LUKS container and the filesystem |
| 220 |
m.execute("lvresize TEST/vol -L+100M") |
| 221 |
|
| 222 |
def confirm_with_passphrase(): |
| 223 |
if self.default_crypto_type == "luks1": |
| 224 |
return |
| 225 |
self.dialog_wait_open() |
| 226 |
self.dialog_wait_apply_enabled() |
| 227 |
self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja") |
| 228 |
self.dialog_apply() |
| 229 |
self.dialog_wait_close() |
| 230 |
|
| 231 |
self.click_card_row("LVM2 logical volumes", 1) |
| 232 |
b.click(self.card_button("LVM2 logical volume", "Grow content")) |
| 233 |
confirm_with_passphrase() |
| 234 |
b.wait_not_present(self.card_button("LVM2 logical volume", "Grow content")) |
| 235 |
size = int(m.execute(f"df -k --output=size {mountpoint} | tail -1").strip()) |
| 236 |
self.assertGreater(size, 250000) |
| 237 |
|
| 238 |
# Shrink the filesystem and let Cockpit shrink the LUKS container and logical volume |
| 239 |
|
| 240 |
fs_dev = m.execute("lsblk -pnl /dev/TEST/vol -o NAME | tail -1").strip() |
| 241 |
self.shrink_extfs(fs_dev, "200M") |
| 242 |
b.click(self.card_button("ext4 filesystem", "Mount now")) |
| 243 |
self.wait_mounted("ext4 filesystem") |
| 244 |
|
| 245 |
b.click(self.card_button("LVM2 logical volume", "Shrink volume")) |
| 246 |
confirm_with_passphrase() |
| 247 |
b.wait_not_present(self.card_button("LVM2 logical volume", "Shrink volume")) |
| 248 |
size = int(m.execute("lvs TEST/vol -o lv_size --noheading --units b --nosuffix")) |
| 249 |
self.assertLess(size, 250000000) |
| 250 |
|
| 251 |
# Grow the logical volume and the LUKS container and let Cockpit grow the filesystem |
| 252 |
|
| 253 |
m.execute("lvresize TEST/vol -L+100M") |
| 254 |
m.execute(f"echo vainu-reku-toma-rolle-kaja | cryptsetup resize {fs_dev}") |
| 255 |
|
| 256 |
b.click(self.card_button("LVM2 logical volume", "Grow content")) |
| 257 |
confirm_with_passphrase() |
| 258 |
b.wait_not_present(self.card_button("LVM2 logical volume", "Grow volume")) |
| 259 |
size = int(m.execute(f"df -k --output=size {mountpoint} | tail -1").strip()) |
| 260 |
self.assertGreater(size, 250000) |
| 261 |
|
| 262 |
# Shrink the filesystem and the LUKS container and let Cockpit shrink the logical volume |
| 263 |
self.shrink_extfs(fs_dev, "198M") |
| 264 |
m.execute(f"echo vainu-reku-toma-rolle-kaja | cryptsetup resize '{fs_dev}' 200M") |
| 265 |
b.click(self.card_button("ext4 filesystem", "Mount now")) |
| 266 |
self.wait_mounted("ext4 filesystem") |
| 267 |
b.click(self.card_button("LVM2 logical volume", "Shrink volume")) |
| 268 |
confirm_with_passphrase() |
| 269 |
b.wait_not_present(self.card_button("LVM2 logical volume", "Shrink volume")) |
| 270 |
size = int(m.execute("lvs TEST/vol -o lv_size --noheading --units b --nosuffix")) |
| 271 |
self.assertLess(size, 250000000) |
| 272 |
|
| 273 |
def testUnsupported(self): |
| 274 |
m = self.machine |
| 275 |
b = self.browser |
| 276 |
|
| 277 |
self.login_and_go("/storage") |
| 278 |
b.wait_visible(self.card("Storage")) |
| 279 |
disk = m.add_disk("500M", serial="DISK1") |
| 280 |
b.wait_visible(self.card_row("Storage", name=f"/dev/{disk['dev']}")) |
| 281 |
|
| 282 |
m.execute("vgcreate TEST /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_DISK1; udevadm trigger") |
| 283 |
b.wait_visible(self.card_row("Storage", name="TEST")) |
| 284 |
|
| 285 |
m.execute("lvcreate TEST -n vol -L 320m") |
| 286 |
b.wait_visible(self.card_row("Storage", name="vol")) |
| 287 |
|
| 288 |
self.click_card_row("Storage", name="TEST") |
| 289 |
b.wait_visible(self.card("LVM2 volume group")) |
| 290 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 1), "vol") |
| 291 |
|
| 292 |
m.execute("mkfs.ext4 -L FSYS /dev/TEST/vol") |
| 293 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), "ext4 filesystem") |
| 294 |
|
| 295 |
def fake_fstype(fstype): |
| 296 |
# Change fstype via a udev rule |
| 297 |
m.write("/run/udev/rules.d/99-fake-fstype.rules", |
| 298 |
f'SUBSYSTEM=="block", ENV{{ID_FS_LABEL}}=="FSYS", ENV{{ID_FS_TYPE}}="{fstype}"\n') |
| 299 |
m.execute("udevadm control --reload; udevadm trigger") |
| 300 |
|
| 301 |
self.addCleanup(m.execute, |
| 302 |
"rm /run/udev/rules.d/99-fake-fstype.rules; udevadm control --reload; udevadm trigger") |
| 303 |
|
| 304 |
def check_btn(title, excuse): |
| 305 |
btn = self.card_button("LVM2 logical volume", title) |
| 306 |
b.wait_visible(btn) |
| 307 |
b.mouse(btn, "mouseenter", 0, 0, 0) |
| 308 |
b.wait_in_text("#tip-storage", excuse) |
| 309 |
b.mouse(btn, "mouseleave", 0, 0, 0) |
| 310 |
b.wait_not_present("#tip-storage") |
| 311 |
|
| 312 |
fake_fstype("udf") # UDF is a real filesystem type that UDisks knows about. It can definitely not be resized. |
| 313 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), "udf filesystem") |
| 314 |
self.click_card_row("LVM2 logical volumes", 1) |
| 315 |
check_btn("Shrink", "udf can not be resized") |
| 316 |
check_btn("Grow", "udf can not be resized") |
| 317 |
b.click(".pf-v6-c-breadcrumb__link:contains('TEST')") |
| 318 |
|
| 319 |
fake_fstype("fake") # This is not a real filesystem and UDisks2 knows nothing about it. |
| 320 |
b.wait_text(self.card_row_col("LVM2 logical volumes", 1, 2), "fake filesystem") |
| 321 |
self.click_card_row("LVM2 logical volumes", 1) |
| 322 |
check_btn("Shrink", "fake can not be resized here") |
| 323 |
check_btn("Grow", "fake can not be resized here") |
| 324 |
b.click(".pf-v6-c-breadcrumb__link:contains('TEST')") |
| 325 |
|
| 326 |
|
| 327 |
if __name__ == '__main__': |
| 328 |
testlib.test_main() |