| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2022 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 |
@testlib.nondestructive |
| 15 |
class TestStorageswap(storagelib.StorageCase): |
| 16 |
|
| 17 |
def checkSwapUsed(self): |
| 18 |
# this relies on PCP, which is missing on some images |
| 19 |
if self.machine.image in ["rhel-8-10"]: |
| 20 |
return |
| 21 |
|
| 22 |
self.browser.wait_text(self.card_desc("Swap", "Used"), "0 B") |
| 23 |
|
| 24 |
def testBasic(self): |
| 25 |
b = self.browser |
| 26 |
m = self.machine |
| 27 |
|
| 28 |
disk = self.add_ram_disk() |
| 29 |
self.addCleanup(m.execute, f"swapoff {disk} || true; swapoff {disk}1 || true") |
| 30 |
|
| 31 |
self.login_and_go("/storage") |
| 32 |
|
| 33 |
# Create a swap partition on GPT |
| 34 |
self.click_card_row("Storage", name=disk) |
| 35 |
self.click_card_dropdown("Solid State Drive", "Create partition table") |
| 36 |
self.confirm() |
| 37 |
b.wait_text(self.card_row_col("GPT partitions", 1, 1), "Free space") |
| 38 |
self.click_dropdown(self.card_row("GPT partitions", 1), "Create partition") |
| 39 |
self.dialog({"type": "swap"}) |
| 40 |
b.wait_text(self.card_row_col("GPT partitions", 1, 2), "Swap") |
| 41 |
|
| 42 |
# It should have been started and have a fstab entry |
| 43 |
self.click_card_row("GPT partitions", 1) |
| 44 |
self.checkSwapUsed() |
| 45 |
testlib.wait(lambda: "defaults" in m.execute(f"findmnt --fstab -n -o OPTIONS {disk}1")) |
| 46 |
|
| 47 |
# Stopping should set it to noauto |
| 48 |
b.click(self.card_button("Swap", "Stop")) |
| 49 |
b.wait_text(self.card_desc("Swap", "Used"), "-") |
| 50 |
testlib.wait(lambda: "noauto" in m.execute(f"findmnt --fstab -n -o OPTIONS {disk}1")) |
| 51 |
|
| 52 |
# Start it again to test teardown below |
| 53 |
b.click(self.card_button("Swap", "Start")) |
| 54 |
self.checkSwapUsed() |
| 55 |
testlib.wait(lambda: "defaults" in m.execute(f"findmnt --fstab -n -o OPTIONS {disk}1")) |
| 56 |
|
| 57 |
# It should have the right partition type |
| 58 |
b.wait_visible(self.card("Swap")) |
| 59 |
b.wait_text(self.card_desc("Partition", "Type"), "Linux swap space") |
| 60 |
|
| 61 |
# Set it to something else |
| 62 |
b.click(self.card_desc_action("Partition", "Type")) |
| 63 |
self.dialog({"type": "0fc63daf-8483-4772-8e79-3d69d8477de4"}) |
| 64 |
b.wait_text(self.card_desc("Partition", "Type"), "Linux filesystem data") |
| 65 |
|
| 66 |
# Correct it by reformatting |
| 67 |
self.click_card_dropdown("Swap", "Format") |
| 68 |
self.dialog_wait_open() |
| 69 |
self.dialog_set_val("type", "swap") |
| 70 |
b.wait_in_text("#dialog .modal-footer-teardown", f"{os.path.basename(disk)}1") |
| 71 |
b.wait_in_text("#dialog .modal-footer-teardown", "stop, format") |
| 72 |
self.dialog_apply_secondary() |
| 73 |
self.dialog_wait_close() |
| 74 |
b.wait_text(self.card_desc("Partition", "Type"), "Linux swap space") |
| 75 |
|
| 76 |
# Delete the partition, the fstab entry should disappear |
| 77 |
self.click_card_dropdown("Partition", "Delete") |
| 78 |
self.confirm() |
| 79 |
b.wait_visible(self.card("Solid State Drive")) |
| 80 |
m.execute(f"! findmnt --fstab -n -o OPTIONS {disk}1") |
| 81 |
|
| 82 |
# Format as swap on the command line, starting it should add |
| 83 |
# fstab entry |
| 84 |
m.execute(f"mkswap -f {disk}") |
| 85 |
b.click(self.card_button("Swap", "Start")) |
| 86 |
self.checkSwapUsed() |
| 87 |
testlib.wait(lambda: "defaults" in m.execute(f"findmnt --fstab -n -o OPTIONS {disk}")) |
| 88 |
|
| 89 |
@testlib.skipImage("cryptsetup uses too much memory, OOM on our test VMs", "rhel-8-*") |
| 90 |
def testEncrypted(self): |
| 91 |
b = self.browser |
| 92 |
m = self.machine |
| 93 |
|
| 94 |
disk = self.add_ram_disk() |
| 95 |
self.addCleanup(m.execute, f"swapoff $(lsblk -plno NAME {disk} | tail -1) || true") |
| 96 |
|
| 97 |
self.login_and_go("/storage") |
| 98 |
|
| 99 |
# Create a encrypted swap partition directly on a disk |
| 100 |
self.click_dropdown(self.card_row("Storage", name=disk), "Format") |
| 101 |
with b.wait_timeout(60): |
| 102 |
self.dialog({ |
| 103 |
"type": "swap", |
| 104 |
"crypto": "luks2", |
| 105 |
"passphrase": "foobar", |
| 106 |
"passphrase2": "foobar", |
| 107 |
}) |
| 108 |
b.wait_in_text(self.card_row("Storage", name=disk), "Swap (encrypted)") |
| 109 |
|
| 110 |
# It should have been started and have a fstab entry |
| 111 |
self.click_card_row("Storage", name=disk) |
| 112 |
self.checkSwapUsed() |
| 113 |
dev = b.text(self.card_desc("Encryption", "Cleartext device")) |
| 114 |
testlib.wait(lambda: "defaults" in m.execute(f"findmnt --fstab -n -o OPTIONS {dev}")) |
| 115 |
|
| 116 |
|
| 117 |
if __name__ == '__main__': |
| 118 |
testlib.test_main() |