| 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 json |
| 9 |
import os |
| 10 |
|
| 11 |
import storagelib |
| 12 |
import testlib |
| 13 |
|
| 14 |
|
| 15 |
@testlib.nondestructive |
| 16 |
@testlib.skipOstree("No /sysroot and directory cannot be created on read-only filesystem") |
| 17 |
@testlib.skipImage("Not relevant for Anaconda", "debian-*", "ubuntu-*", "arch", "rhel-8", "rhel-9") |
| 18 |
class TestStorageAnaconda(storagelib.StorageCase): |
| 19 |
|
| 20 |
def enterAnacondaMode(self, config): |
| 21 |
b = self.browser |
| 22 |
b.call_js_func("window.sessionStorage.setItem", "cockpit_anaconda", json.dumps(config)) |
| 23 |
b.reload() |
| 24 |
b.enter_page("/storage") |
| 25 |
|
| 26 |
def expectExportedDevice(self, device, value): |
| 27 |
mpm = json.loads(self.browser.call_js_func("window.sessionStorage.getItem", "cockpit_mount_points")) |
| 28 |
self.assertIn(device, mpm) |
| 29 |
self.assertEqual(mpm[device], value) |
| 30 |
|
| 31 |
def expectExportedDevicePassphrase(self, device, value): |
| 32 |
pp = json.loads(self.browser.call_js_func("window.sessionStorage.getItem", "cockpit_passphrases")) |
| 33 |
self.assertIn(device, pp) |
| 34 |
self.assertEqual(pp[device], value) |
| 35 |
|
| 36 |
def testBasic(self): |
| 37 |
m = self.machine |
| 38 |
b = self.browser |
| 39 |
|
| 40 |
disk = self.add_ram_disk() |
| 41 |
|
| 42 |
anaconda_config = { |
| 43 |
"mount_point_prefix": "/sysroot", |
| 44 |
"available_devices": [disk], |
| 45 |
} |
| 46 |
|
| 47 |
self.login_and_go("/storage") |
| 48 |
self.enterAnacondaMode(anaconda_config) |
| 49 |
|
| 50 |
# There should be only one row, for our disk |
| 51 |
b.wait_count(self.card("Storage") + " tbody tr", 1) |
| 52 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Unformatted data") |
| 53 |
b.wait_not_present(self.card_row("Storage", location="/")) |
| 54 |
|
| 55 |
# Create a volume group with a logical volume |
| 56 |
self.click_devices_dropdown("Create LVM2 volume group") |
| 57 |
self.dialog_wait_open() |
| 58 |
b.wait_count("#dialog .select-space-name", 1) |
| 59 |
self.dialog_set_val("disks", {disk: True}) |
| 60 |
self.dialog_apply() |
| 61 |
self.dialog_wait_close() |
| 62 |
self.click_dropdown(self.card_row("Storage", name="vgroup0"), "Create new logical volume") |
| 63 |
self.dialog({}) |
| 64 |
|
| 65 |
# Create an encrypted filesystem |
| 66 |
self.click_dropdown(self.card_row("Storage", name="lvol0"), "Format") |
| 67 |
self.dialog_wait_open() |
| 68 |
b.wait_not_present(self.dialog_field("at_boot")) |
| 69 |
b.wait_not_present(self.dialog_field("mount_options")) |
| 70 |
self.dialog_set_val("type", "ext4") |
| 71 |
self.dialog_set_val("mount_point", "/") |
| 72 |
self.dialog_set_val("crypto", self.default_crypto_type) |
| 73 |
self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja") |
| 74 |
self.dialog_set_val("passphrase2", "vainu-reku-toma-rolle-kaja") |
| 75 |
self.dialog_apply() |
| 76 |
self.dialog_wait_close() |
| 77 |
|
| 78 |
self.assertIn("noauto", m.execute("findmnt --fstab -n -o OPTIONS /sysroot")) |
| 79 |
self.assertNotIn("nofail", m.execute("findmnt --fstab -n -o OPTIONS /sysroot")) |
| 80 |
|
| 81 |
self.click_card_row("Storage", name="lvol0") |
| 82 |
b.click(self.card_parent_link()) |
| 83 |
b.click(self.card_parent_link()) |
| 84 |
b.wait_visible(self.card("Storage")) |
| 85 |
|
| 86 |
b.assert_pixels("body", "page") |
| 87 |
|
| 88 |
# Edit mount point |
| 89 |
self.click_dropdown(self.card_row("Storage", name="lvol0"), "Edit mount point") |
| 90 |
self.dialog_wait_open() |
| 91 |
self.dialog_wait_val("mount_point", "/") |
| 92 |
self.dialog_set_val("mount_point", "/var") |
| 93 |
self.dialog_apply() |
| 94 |
self.dialog_wait_close() |
| 95 |
self.assertIn("noauto", m.execute("findmnt --fstab -n -o OPTIONS /sysroot/var")) |
| 96 |
|
| 97 |
# Mount/Unmount the filesystem |
| 98 |
self.click_card_row("Storage", location="/var") |
| 99 |
b.wait_visible(self.card("Encryption")) |
| 100 |
# LUKS should be open |
| 101 |
b.wait_in_text(self.card_desc("Encryption", "Cleartext device"), "/dev/mapper") |
| 102 |
b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "/var") |
| 103 |
|
| 104 |
# Cockpit hides its "Mount" action in Anaconda mode... |
| 105 |
b.wait_not_present(self.card_button("ext4 filesystem", "Mount")) |
| 106 |
m.execute("mkdir -p /sysroot/var; mount /sysroot/var") |
| 107 |
|
| 108 |
# ...but unmounting is still there. |
| 109 |
b.click(self.card_button("ext4 filesystem", "Unmount")) |
| 110 |
self.dialog_wait_open() |
| 111 |
b.wait_text("#dialog .pf-v6-c-modal-box__title-text", "Unmount filesystem /var") |
| 112 |
self.dialog_apply() |
| 113 |
self.dialog_wait_close() |
| 114 |
self.assertIn("noauto", m.execute("findmnt --fstab -n -o OPTIONS /sysroot/var")) |
| 115 |
|
| 116 |
# LUKS should still be open, close it so that we can deactivate the LV |
| 117 |
cleartext = b.text(self.card_desc("Encryption", "Cleartext device")) |
| 118 |
m.execute(f"cryptsetup close {cleartext}") |
| 119 |
b.wait_text(self.card_desc("Encryption", "Cleartext device"), "-") |
| 120 |
|
| 121 |
# Deactivate |
| 122 |
b.click(self.card_button("LVM2 logical volume", "Deactivate")) |
| 123 |
self.confirm() |
| 124 |
testlib.wait(lambda: m.execute("if ! test -e /dev/vgroup0/lvol0; then echo gone; fi").strip() == "gone") |
| 125 |
|
| 126 |
# Check exported information. |
| 127 |
self.expectExportedDevicePassphrase("/dev/vgroup0/lvol0", "vainu-reku-toma-rolle-kaja") |
| 128 |
self.expectExportedDevice("/dev/vgroup0/lvol0", |
| 129 |
{ |
| 130 |
"type": "crypto", |
| 131 |
"content": { |
| 132 |
"type": "filesystem", |
| 133 |
"dir": "/var" |
| 134 |
} |
| 135 |
}) |
| 136 |
|
| 137 |
# Activate |
| 138 |
b.click(self.card_button("Inactive logical volume", "Activate")) |
| 139 |
|
| 140 |
# Crypto is locked. Unlock and mount via the "Reuse existing |
| 141 |
# encryption" mode of the Format dialog |
| 142 |
self.click_card_dropdown("Filesystem", "Format") |
| 143 |
self.dialog_wait_open() |
| 144 |
self.dialog_wait_val("crypto", " keep") |
| 145 |
self.dialog_set_val("old_passphrase", "vainu-reku-toma-rolle-kaja") |
| 146 |
b.set_checked("#dialog-confirm", val=True) |
| 147 |
self.dialog_apply() |
| 148 |
self.dialog_wait_close() |
| 149 |
|
| 150 |
# Passphrase should still be remembered |
| 151 |
self.expectExportedDevicePassphrase("/dev/vgroup0/lvol0", "vainu-reku-toma-rolle-kaja") |
| 152 |
|
| 153 |
# Check and delete volume group |
| 154 |
b.click(self.card_parent_link()) |
| 155 |
b.wait_visible(self.card_row("LVM2 volume group", name=disk)) |
| 156 |
self.click_card_dropdown("LVM2 volume group", "Delete group") |
| 157 |
self.confirm() |
| 158 |
m.execute("! findmnt --fstab -n /sysroot/var") |
| 159 |
|
| 160 |
# Back to the beginning |
| 161 |
b.wait_visible(self.card("Storage")) |
| 162 |
b.wait_count(self.card("Storage") + " tbody tr", 1) |
| 163 |
b.wait_not_present(self.card_row("Storage", location="/var")) |
| 164 |
|
| 165 |
@testlib.skipImage("No Stratis", "debian-*", "ubuntu-*", "arch") |
| 166 |
@testlib.skipImage("commit 817c957899a4 removed Statis 2 support", "rhel-8-*") |
| 167 |
@testlib.skipImage("Stratis v1 pools are unsupported", "rhel-9-*") |
| 168 |
def testStratis(self): |
| 169 |
m = self.machine |
| 170 |
b = self.browser |
| 171 |
|
| 172 |
m.execute("systemctl start stratisd") |
| 173 |
self.addCleanup(m.execute, "systemctl stop stratisd") |
| 174 |
|
| 175 |
# Forcefully remove all Stratis pools. This also gets rid of partially constructed pools. |
| 176 |
self.addCleanup(m.execute, |
| 177 |
"dmsetup ls | cut -f1 | grep ^stratis | xargs -n1 --no-run-if-empty dmsetup remove --force") |
| 178 |
|
| 179 |
PV_SIZE = 4000 # 4 GB in MB |
| 180 |
|
| 181 |
disk = self.add_loopback_disk(PV_SIZE, name="loop10") |
| 182 |
|
| 183 |
anaconda_config = { |
| 184 |
"mount_point_prefix": "/sysroot", |
| 185 |
"available_devices": [disk], |
| 186 |
} |
| 187 |
|
| 188 |
self.login_and_go("/storage") |
| 189 |
self.enterAnacondaMode(anaconda_config) |
| 190 |
|
| 191 |
# Create an encrypted Stratis pool |
| 192 |
self.click_devices_dropdown("Create Stratis pool") |
| 193 |
self.dialog_wait_open() |
| 194 |
b.wait_count("#dialog .select-space-name", 1) |
| 195 |
self.dialog_set_val("disks", {disk: True}) |
| 196 |
self.dialog_set_val("encrypt_pass.on", val=True) |
| 197 |
self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja") |
| 198 |
self.dialog_set_val("passphrase2", "vainu-reku-toma-rolle-kaja") |
| 199 |
self.dialog_apply() |
| 200 |
self.dialog_wait_close() |
| 201 |
|
| 202 |
self.click_dropdown(self.card_row("Storage", name="pool0"), "Create new filesystem") |
| 203 |
self.dialog_wait_open() |
| 204 |
b.wait_not_present(self.dialog_field("at_boot")) |
| 205 |
b.wait_not_present(self.dialog_field("mount_options")) |
| 206 |
self.dialog_set_val("name", "root") |
| 207 |
self.dialog_set_val("mount_point", "/") |
| 208 |
self.dialog_apply() |
| 209 |
self.dialog_wait_close() |
| 210 |
|
| 211 |
self.assertIn("noauto", m.execute("findmnt --fstab -n -o OPTIONS /sysroot")) |
| 212 |
self.assertNotIn("nofail", m.execute("findmnt --fstab -n -o OPTIONS /sysroot")) |
| 213 |
|
| 214 |
b.wait_visible(self.card_row_col("Storage", 3, 5) + " .usage-bar[role=progressbar]") |
| 215 |
|
| 216 |
# Edit mount point |
| 217 |
self.click_dropdown(self.card_row("Storage", name="root"), "Edit mount point") |
| 218 |
self.dialog_wait_open() |
| 219 |
self.dialog_wait_val("mount_point", "/") |
| 220 |
self.dialog_set_val("mount_point", "/var") |
| 221 |
self.dialog_apply() |
| 222 |
self.dialog_wait_close() |
| 223 |
self.assertIn("noauto", m.execute("findmnt --fstab -n -o OPTIONS /sysroot/var")) |
| 224 |
|
| 225 |
# Mount/Unmount the filesystem |
| 226 |
self.click_card_row("Storage", location="/var") |
| 227 |
b.wait_in_text(self.card_desc("Stratis filesystem", "Mount point"), "/var") |
| 228 |
# Cockpit hides its "Mount" action in Anaconda mode... |
| 229 |
b.wait_not_present(self.card_button("Stratis filesystem", "Mount")) |
| 230 |
m.execute("mkdir -p /sysroot/var; mount /sysroot/var") |
| 231 |
|
| 232 |
b.click(self.card_button("Stratis filesystem", "Unmount")) |
| 233 |
self.dialog_wait_open() |
| 234 |
b.wait_text("#dialog .pf-v6-c-modal-box__title-text", "Unmount filesystem /var") |
| 235 |
self.dialog_apply() |
| 236 |
self.dialog_wait_close() |
| 237 |
self.assertIn("noauto", m.execute("findmnt --fstab -n -o OPTIONS /sysroot/var")) |
| 238 |
|
| 239 |
# Check exported mount point and passphrase information. |
| 240 |
self.expectExportedDevicePassphrase(disk, "vainu-reku-toma-rolle-kaja") |
| 241 |
|
| 242 |
self.expectExportedDevice("/dev/stratis/pool0/root", |
| 243 |
{ |
| 244 |
"type": "filesystem", |
| 245 |
"dir": "/var" |
| 246 |
}) |
| 247 |
|
| 248 |
# Mount again, to check location in tear down information |
| 249 |
m.execute("mount /sysroot/var") |
| 250 |
|
| 251 |
# Check and delete pool |
| 252 |
b.click(self.card_parent_link()) |
| 253 |
b.wait_visible(self.card_row("Encrypted Stratis pool", name=disk)) |
| 254 |
self.click_card_dropdown("Encrypted Stratis pool", "Delete") |
| 255 |
self.confirm() |
| 256 |
m.execute("! findmnt --fstab -n /sysroot/var") |
| 257 |
|
| 258 |
@testlib.skipImage('no btrfs support', 'rhel-*', 'centos-*') |
| 259 |
def testBtrfs(self): |
| 260 |
b = self.browser |
| 261 |
|
| 262 |
disk = self.add_ram_disk(128) |
| 263 |
|
| 264 |
anaconda_config = { |
| 265 |
"mount_point_prefix": "/sysroot", |
| 266 |
"available_devices": [disk], |
| 267 |
} |
| 268 |
|
| 269 |
self.login_and_go("/storage") |
| 270 |
self.enterAnacondaMode(anaconda_config) |
| 271 |
|
| 272 |
# Create a encrypted Btrfs filesystem |
| 273 |
|
| 274 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Unformatted data") |
| 275 |
self.click_dropdown(self.card_row("Storage", 1), "Format") |
| 276 |
self.dialog_wait_open() |
| 277 |
b.wait_not_present(self.dialog_field("at_boot")) |
| 278 |
b.wait_not_present(self.dialog_field("mount_options")) |
| 279 |
self.dialog_set_val("name", "butter") |
| 280 |
self.dialog_set_val("type", "btrfs") |
| 281 |
self.dialog_set_val("mount_point", f"{self.mnt_dir}/butter") |
| 282 |
self.dialog_set_val("crypto", self.default_crypto_type) |
| 283 |
self.dialog_set_val("passphrase", "vainu-reku-toma-rolle-kaja") |
| 284 |
self.dialog_set_val("passphrase2", "vainu-reku-toma-rolle-kaja") |
| 285 |
self.dialog_apply() |
| 286 |
self.dialog_wait_close() |
| 287 |
|
| 288 |
# Create two subvolumes |
| 289 |
self.click_dropdown(self.card_row("Storage", location=f"{self.mnt_dir}/butter"), "Create subvolume") |
| 290 |
self.dialog_wait_open() |
| 291 |
b.wait_not_present(self.dialog_field("at_boot")) |
| 292 |
b.wait_not_present(self.dialog_field("mount_options")) |
| 293 |
self.dialog_set_val("name", "root") |
| 294 |
self.dialog_set_val("mount_point", "/") |
| 295 |
b.wait_count("#dialog button.apply", 1) |
| 296 |
self.dialog_apply() |
| 297 |
self.dialog_wait_close() |
| 298 |
|
| 299 |
self.click_dropdown(self.card_row("Storage", location=f"{self.mnt_dir}/butter"), "Create subvolume") |
| 300 |
self.dialog_wait_open() |
| 301 |
self.dialog_set_val("name", "home") |
| 302 |
self.dialog_set_val("mount_point", "/home") |
| 303 |
self.dialog_apply() |
| 304 |
self.dialog_wait_close() |
| 305 |
|
| 306 |
# Popular subvolume names starting with @ are allowed. |
| 307 |
self.click_dropdown(self.card_row("Storage", location=f"{self.mnt_dir}/butter"), "Create subvolume") |
| 308 |
self.dialog_wait_open() |
| 309 |
self.dialog_set_val("name", "@data") |
| 310 |
self.dialog_set_val("mount_point", "/data") |
| 311 |
self.dialog_apply() |
| 312 |
self.dialog_wait_close() |
| 313 |
|
| 314 |
# Lock, mount point exporting should still work |
| 315 |
|
| 316 |
self.click_dropdown(self.card_row("Storage", name=disk), "Lock") |
| 317 |
self.confirm() |
| 318 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Locked data (encrypted)") |
| 319 |
|
| 320 |
self.expectExportedDevice(disk, |
| 321 |
{ |
| 322 |
"type": "crypto", |
| 323 |
"content": { |
| 324 |
"type": "filesystem", |
| 325 |
"subvolumes": { |
| 326 |
"/": { |
| 327 |
"dir": f"{self.mnt_dir}/butter" |
| 328 |
}, |
| 329 |
"root": { |
| 330 |
"dir": "/" |
| 331 |
}, |
| 332 |
"home": { |
| 333 |
"dir": "/home" |
| 334 |
}, |
| 335 |
"@data": { |
| 336 |
"dir": "/data" |
| 337 |
}, |
| 338 |
} |
| 339 |
} |
| 340 |
}) |
| 341 |
|
| 342 |
@testlib.skipImage('no btrfs support', 'rhel-*', 'centos-*') |
| 343 |
def testDegradedBtrfs(self): |
| 344 |
b = self.browser |
| 345 |
m = self.machine |
| 346 |
|
| 347 |
disk1 = self.add_ram_disk(size=140) |
| 348 |
disk2 = self.add_loopback_disk(size=140) |
| 349 |
|
| 350 |
anaconda_config = { |
| 351 |
"mount_point_prefix": "/sysroot", |
| 352 |
"available_devices": [disk1, disk2], |
| 353 |
} |
| 354 |
|
| 355 |
# Create a two-device btrfs and then degrade it by wiping the second device. |
| 356 |
# Cockpit used to crash when such a filesystem is present in Anaconda mode. |
| 357 |
|
| 358 |
m.execute(f"mkfs.btrfs -L butter {disk1} {disk2}") |
| 359 |
m.execute(f"wipefs -a {disk2}") |
| 360 |
|
| 361 |
self.login_and_go("/storage") |
| 362 |
self.enterAnacondaMode(anaconda_config) |
| 363 |
|
| 364 |
b.wait_visible(self.card_row("Storage", name="butter")) |
| 365 |
|
| 366 |
def testBiosboot(self): |
| 367 |
b = self.browser |
| 368 |
|
| 369 |
disk = self.add_ram_disk() |
| 370 |
|
| 371 |
anaconda_config = { |
| 372 |
"mount_point_prefix": "/sysroot", |
| 373 |
"available_devices": [disk], |
| 374 |
"efi": False, |
| 375 |
} |
| 376 |
|
| 377 |
self.login_and_go("/storage") |
| 378 |
self.enterAnacondaMode(anaconda_config) |
| 379 |
|
| 380 |
# Create a biosboot partition on GPT |
| 381 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Unformatted data") |
| 382 |
self.click_dropdown(self.card_row("Storage", 1), "Create partition table") |
| 383 |
self.confirm() |
| 384 |
b.wait_text(self.card_row_col("Storage", 2, 2), "Free space") |
| 385 |
self.click_dropdown(self.card_row("Storage", 2), "Create partition") |
| 386 |
self.dialog({"type": "biosboot"}) |
| 387 |
|
| 388 |
# Check the type and set it to something else |
| 389 |
b.wait_text(self.card_row_col("Storage", 2, 3), "Unformatted data (BIOS boot partition)") |
| 390 |
self.click_card_row("Storage", 2) |
| 391 |
b.wait_text(self.card_desc("Partition", "Type"), "BIOS boot partition") |
| 392 |
b.click(self.card_desc_action("Partition", "Type")) |
| 393 |
self.dialog({"type": "0fc63daf-8483-4772-8e79-3d69d8477de4"}) |
| 394 |
b.wait_text(self.card_desc("Partition", "Type"), "Linux filesystem data") |
| 395 |
|
| 396 |
# Correct it by reformatting as "biosboot" |
| 397 |
self.click_card_dropdown("Unformatted data", "Format") |
| 398 |
self.dialog({"type": "biosboot"}) |
| 399 |
b.wait_text(self.card_desc("Partition", "Type"), "BIOS boot partition") |
| 400 |
|
| 401 |
def testEfiSystemPartition(self): |
| 402 |
b = self.browser |
| 403 |
|
| 404 |
disk = self.add_ram_disk() |
| 405 |
|
| 406 |
anaconda_config = { |
| 407 |
"mount_point_prefix": "/sysroot", |
| 408 |
"available_devices": [disk], |
| 409 |
"efi": True, |
| 410 |
} |
| 411 |
|
| 412 |
self.login_and_go("/storage") |
| 413 |
self.enterAnacondaMode(anaconda_config) |
| 414 |
|
| 415 |
# Create a EFI system partition on GPT |
| 416 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Unformatted data") |
| 417 |
self.click_dropdown(self.card_row("Storage", 1), "Create partition table") |
| 418 |
self.confirm() |
| 419 |
b.wait_text(self.card_row_col("Storage", 2, 2), "Free space") |
| 420 |
self.click_dropdown(self.card_row("Storage", 2), "Create partition") |
| 421 |
self.dialog({"type": "efi"}) |
| 422 |
|
| 423 |
# Check the type and set it to something else |
| 424 |
b.wait_text(self.card_row_col("Storage", 2, 3), "vfat filesystem (EFI system partition)") |
| 425 |
b.wait_text(self.card_row_col("Storage", 2, 4), "/boot/efi") |
| 426 |
self.click_card_row("Storage", 2) |
| 427 |
b.wait_visible(self.card("vfat filesystem")) |
| 428 |
b.wait_text(self.card_desc("Partition", "Type"), "EFI system partition") |
| 429 |
b.click(self.card_desc_action("Partition", "Type")) |
| 430 |
self.dialog({"type": "0fc63daf-8483-4772-8e79-3d69d8477de4"}) |
| 431 |
b.wait_text(self.card_desc("Partition", "Type"), "Linux filesystem data") |
| 432 |
|
| 433 |
# Correct it by reformatting as "efi" |
| 434 |
self.click_card_dropdown("vfat filesystem", "Format") |
| 435 |
self.dialog({"type": "efi"}) |
| 436 |
b.wait_text(self.card_desc("Partition", "Type"), "EFI system partition") |
| 437 |
|
| 438 |
def testFormat(self): |
| 439 |
m = self.machine |
| 440 |
b = self.browser |
| 441 |
|
| 442 |
disk = self.add_ram_disk() |
| 443 |
|
| 444 |
anaconda_config = { |
| 445 |
"mount_point_prefix": "/sysroot", |
| 446 |
"available_devices": [disk], |
| 447 |
"default_fsys_type": "vfat", |
| 448 |
} |
| 449 |
|
| 450 |
self.login_and_go("/storage") |
| 451 |
self.enterAnacondaMode(anaconda_config) |
| 452 |
|
| 453 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Unformatted data") |
| 454 |
self.click_dropdown(self.card_row("Storage", 1), "Create partition table") |
| 455 |
self.confirm() |
| 456 |
b.wait_text(self.card_row_col("Storage", 2, 2), "Free space") |
| 457 |
|
| 458 |
# Only one apply button in the Create Partition dialog, |
| 459 |
# default filesystem type should be "vfat". |
| 460 |
self.click_dropdown(self.card_row("Storage", 2), "Create partition") |
| 461 |
self.dialog_wait_open() |
| 462 |
self.dialog_wait_val("type", "vfat") |
| 463 |
self.dialog_set_val("type", "ext4") |
| 464 |
self.dialog_set_val("size", "30") |
| 465 |
b.wait_count("#dialog button.apply", 1) |
| 466 |
b.wait_text("#dialog button.apply", "Create") |
| 467 |
self.dialog_apply() |
| 468 |
self.dialog_wait_close() |
| 469 |
|
| 470 |
# Page talks about assigned mount points instead of "not mounted". |
| 471 |
b.wait_text(self.card_row_col("Storage", 2, 4), "(no assigned mount point)") |
| 472 |
|
| 473 |
# Format it again and make it the root filesystem. It should |
| 474 |
# keep ext4 as the type. |
| 475 |
self.click_dropdown(self.card_row("Storage", 2), "Format") |
| 476 |
self.dialog_wait_open() |
| 477 |
self.dialog_set_val("mount_point", "/") |
| 478 |
self.dialog_wait_val("type", "ext4") |
| 479 |
b.wait_count("#dialog button.apply", 1) |
| 480 |
b.wait_text("#dialog button.apply", "Format") |
| 481 |
self.dialog_apply() |
| 482 |
self.dialog_wait_close() |
| 483 |
|
| 484 |
# Filesystem is not mounted but page doesn't mention "not mounted". |
| 485 |
m.execute(f"! findmnt {disk}") |
| 486 |
b.wait_text(self.card_row_col("Storage", 2, 4), "/") |
| 487 |
|
| 488 |
# Create another partition, it should inherit ext4 |
| 489 |
# from the root |
| 490 |
b.wait_text(self.card_row_col("Storage", 3, 2), "Free space") |
| 491 |
self.click_dropdown(self.card_row("Storage", 3), "Create partition") |
| 492 |
self.dialog_wait_open() |
| 493 |
self.dialog_wait_val("type", "ext4") |
| 494 |
self.dialog_apply() |
| 495 |
self.dialog_wait_close() |
| 496 |
|
| 497 |
def testSwap(self): |
| 498 |
b = self.browser |
| 499 |
|
| 500 |
disk = self.add_ram_disk() |
| 501 |
|
| 502 |
anaconda_config = { |
| 503 |
"mount_point_prefix": "/sysroot", |
| 504 |
"available_devices": [disk], |
| 505 |
} |
| 506 |
|
| 507 |
self.login_and_go("/storage") |
| 508 |
self.enterAnacondaMode(anaconda_config) |
| 509 |
|
| 510 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Unformatted data") |
| 511 |
self.click_dropdown(self.card_row("Storage", 1), "Format") |
| 512 |
self.dialog({"type": "swap"}) |
| 513 |
|
| 514 |
self.expectExportedDevice(disk, {"type": "swap"}) |
| 515 |
|
| 516 |
def testMDRaid(self): |
| 517 |
b = self.browser |
| 518 |
|
| 519 |
disk1 = self.add_loopback_disk(name="loop10") |
| 520 |
disk2 = self.add_loopback_disk(name="loop11") |
| 521 |
|
| 522 |
anaconda_config = { |
| 523 |
"mount_point_prefix": "/sysroot", |
| 524 |
"available_devices": [disk1, disk2], |
| 525 |
} |
| 526 |
|
| 527 |
self.login_and_go("/storage") |
| 528 |
self.enterAnacondaMode(anaconda_config) |
| 529 |
|
| 530 |
# Create a mirrored MDRAID |
| 531 |
self.click_devices_dropdown("Create MDRAID device") |
| 532 |
self.dialog_wait_open() |
| 533 |
b.wait_count("#dialog .select-space-name", 2) |
| 534 |
self.dialog_wait_val("name", "raid0") |
| 535 |
self.dialog_set_val("level", "raid1") |
| 536 |
self.dialog_set_val("disks", {disk1: True, disk2: True}) |
| 537 |
self.dialog_apply() |
| 538 |
self.dialog_wait_close() |
| 539 |
# Stop the raid array in case the test fails otherwise losetup can't release the devices |
| 540 |
self.addCleanup(self.machine.execute, "if [ -b /dev/md/raid0 ]; then mdadm --stop /dev/md/raid0; fi;") |
| 541 |
|
| 542 |
# Create a partition with a filesystem on it |
| 543 |
self.click_dropdown(self.card_row("Storage", name="md/raid0"), "Create partition table") |
| 544 |
self.confirm() |
| 545 |
b.wait_text(self.card_row_col("Storage", 4, 2), "Free space") |
| 546 |
self.click_dropdown(self.card_row("Storage", 4), "Create partition") |
| 547 |
self.dialog({}) |
| 548 |
|
| 549 |
# Stop the MDRAID, it should still be shown |
| 550 |
self.click_card_row("Storage", name="md/raid0") |
| 551 |
b.wait_visible(self.card("GPT partitions")) |
| 552 |
b.click(self.card_button("MDRAID device", "Stop")) |
| 553 |
self.confirm() |
| 554 |
b.wait_not_present(self.card("GPT partitions")) |
| 555 |
b.wait_visible(self.card("MDRAID device")) |
| 556 |
|
| 557 |
b.click(self.card_parent_link()) |
| 558 |
b.wait_visible(self.card_row("Storage", name="raid0")) |
| 559 |
|
| 560 |
# Now remove disk2 from "available_devices". This should hide the mdraid. |
| 561 |
|
| 562 |
anaconda_config = { |
| 563 |
"mount_point_prefix": "/sysroot", |
| 564 |
"available_devices": [disk1], |
| 565 |
} |
| 566 |
|
| 567 |
self.enterAnacondaMode(anaconda_config) |
| 568 |
|
| 569 |
b.wait_visible(self.card("Storage")) |
| 570 |
b.wait_not_present(self.card_row("Storage", name="raid0")) |
| 571 |
b.wait_not_present(self.card_row("Storage", name="md/raid0")) |
| 572 |
|
| 573 |
# But it is still reachable via disk1. This leads to a "Not |
| 574 |
# found" page. |
| 575 |
|
| 576 |
self.click_card_row("Storage", name=disk1) |
| 577 |
b.click(self.card_desc("MDRAID disk", "MDRAID device") + " button") |
| 578 |
b.wait_in_text("body", "Not found") |
| 579 |
|
| 580 |
def testNonEmpty(self): |
| 581 |
b = self.browser |
| 582 |
m = self.machine |
| 583 |
|
| 584 |
disk = self.add_loopback_disk(name="loop10") |
| 585 |
|
| 586 |
anaconda_config = { |
| 587 |
"mount_point_prefix": "/sysroot", |
| 588 |
"available_devices": [disk], |
| 589 |
} |
| 590 |
|
| 591 |
# Create some content on the disk |
| 592 |
m.execute(f"echo einszweidrei | cryptsetup luksFormat --pbkdf-memory 32768 {disk}") |
| 593 |
m.execute(f"echo einszweidrei | cryptsetup luksOpen {disk} dm-test") |
| 594 |
m.execute(f"mkfs.ext4 /dev/mapper/dm-test; mount /dev/mapper/dm-test {self.mnt_dir}; echo Hi >{self.mnt_dir}/hello; umount {self.mnt_dir}") |
| 595 |
m.execute("cryptsetup close dm-test") |
| 596 |
|
| 597 |
self.login_and_go("/storage") |
| 598 |
self.enterAnacondaMode(anaconda_config) |
| 599 |
|
| 600 |
# Attempt to wipe it. This requires a extra confirmation |
| 601 |
# because it is locked. |
| 602 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Locked data (encrypted)") |
| 603 |
self.click_dropdown(self.card_row("Storage", 1), "Create partition table") |
| 604 |
self.dialog_wait_open() |
| 605 |
self.dialog_set_val("type", "empty") |
| 606 |
b.wait_in_text("#dialog", "Locked encrypted device might contain data") |
| 607 |
self.dialog_wait_apply_disabled() |
| 608 |
b.assert_pixels('#dialog', "wipe") |
| 609 |
b.set_checked("#dialog-confirm", val=True) |
| 610 |
self.dialog_wait_apply_enabled() |
| 611 |
self.dialog_cancel() |
| 612 |
self.dialog_wait_close() |
| 613 |
|
| 614 |
# Unlock and confirm the extra warning, and actually wipe it |
| 615 |
self.click_dropdown(self.card_row("Storage", 1), "Unlock") |
| 616 |
self.dialog({"passphrase": "einszweidrei"}) |
| 617 |
b.wait_text(self.card_row_col("Storage", 1, 3), "ext4 filesystem (encrypted)") |
| 618 |
self.click_dropdown(self.card_row("Storage", 1), "Create partition table") |
| 619 |
self.dialog_wait_open() |
| 620 |
self.dialog_set_val("type", "empty") |
| 621 |
b.wait_in_text("#dialog", "Important data might be deleted") |
| 622 |
b.wait_in_text("#dialog", os.path.basename(disk)) |
| 623 |
b.wait_in_text("#dialog", "kB used") |
| 624 |
b.wait_in_text("#dialog", "MB total") |
| 625 |
b.set_checked("#dialog-confirm", val=True) |
| 626 |
self.dialog_wait_apply_enabled() |
| 627 |
self.dialog_apply() |
| 628 |
self.dialog_wait_close() |
| 629 |
|
| 630 |
# Put some unrecognized data on it |
| 631 |
|
| 632 |
# This is the superblock of a legacy VDO device. Cockpit does |
| 633 |
# not recognize it. |
| 634 |
|
| 635 |
data = """ |
| 636 |
ZG12ZG8wMDEFAAAABAAAAAAAAABdAAAAAAAAAJQJAgCGsH0mrQgGAC4WnB4G50Fzu20jY6J1rfwA |
| 637 |
AAAAAQAAAAAAAAABAAAA2FwKAAAAAAAA////AAAAAAA7tw9zAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
| 638 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
| 639 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
| 640 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
| 641 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
| 642 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
| 643 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
| 644 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= |
| 645 |
""" |
| 646 |
m.execute(f"base64 -d >{disk}", input=data) |
| 647 |
# Wait for udev to settle and re-trigger, udisks sometimes misses udev events on ubuntu 2204. |
| 648 |
m.execute(f"udevadm settle; udevadm trigger {disk}") |
| 649 |
|
| 650 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Unrecognized data") |
| 651 |
self.click_dropdown(self.card_row("Storage", 1), "Create partition table") |
| 652 |
self.dialog_wait_open() |
| 653 |
self.dialog_set_val("type", "empty") |
| 654 |
b.wait_in_text("#dialog", "Device contains unrecognized data") |
| 655 |
b.set_checked("#dialog-confirm", val=True) |
| 656 |
self.dialog_wait_apply_enabled() |
| 657 |
self.dialog_apply() |
| 658 |
self.dialog_wait_close() |
| 659 |
|
| 660 |
# A filesystem with just directories should not show the |
| 661 |
# warning. |
| 662 |
|
| 663 |
m.execute(f"mkfs.ext4 {disk}; mount {disk} {self.mnt_dir}; mkdir -p {self.mnt_dir}/dir/ect/ory") |
| 664 |
m.execute(f"while mountpoint -q {self.mnt_dir} && ! umount {self.mnt_dir}; do sleep 0.2; done;") |
| 665 |
b.wait_text(self.card_row_col("Storage", 1, 3), "ext4 filesystem") |
| 666 |
|
| 667 |
self.dialog_open_with_retry(lambda: self.click_dropdown(self.card_row("Storage", 1), "Create partition table"), |
| 668 |
lambda: "Initialize" in b.text("#dialog")) |
| 669 |
self.dialog_set_val("type", "empty") |
| 670 |
self.dialog_apply() |
| 671 |
self.dialog_wait_close() |
| 672 |
b.wait_text(self.card_row_col("Storage", 1, 3), "Unformatted data") |
| 673 |
|
| 674 |
@testlib.skipImage("No Stratis", "debian-*", "ubuntu-*") |
| 675 |
@testlib.skipImage("No Anaconda", "arch") |
| 676 |
@testlib.destructive |
| 677 |
def testNoOndemandPackages(self): |
| 678 |
b = self.browser |
| 679 |
m = self.machine |
| 680 |
|
| 681 |
disk = self.add_loopback_disk(name="loop10") |
| 682 |
|
| 683 |
m.execute("systemctl stop stratisd; dnf remove -y stratisd stratis") |
| 684 |
|
| 685 |
anaconda_config = { |
| 686 |
"mount_point_prefix": "/sysroot", |
| 687 |
"available_devices": [disk], |
| 688 |
} |
| 689 |
|
| 690 |
self.login_and_go("/storage") |
| 691 |
self.enterAnacondaMode(anaconda_config) |
| 692 |
|
| 693 |
dropdown_toggle = self.dropdown_toggle(self.card_header("Storage")) |
| 694 |
raid_action = self.dropdown_action("Create MDRAID device") |
| 695 |
stratis_action = self.dropdown_action("Create Stratis pool") |
| 696 |
b.click(dropdown_toggle) |
| 697 |
b.wait_visible(raid_action) |
| 698 |
b.wait_not_present(stratis_action) |
| 699 |
|
| 700 |
|
| 701 |
if __name__ == '__main__': |
| 702 |
testlib.test_main() |