| 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 TestStorageUnused(storagelib.StorageCase): |
| 14 |
|
| 15 |
def testUnused(self): |
| 16 |
m = self.machine |
| 17 |
b = self.browser |
| 18 |
|
| 19 |
# The following block devices should not be offered for creating a |
| 20 |
# raid |
| 21 |
# |
| 22 |
# - filesystems |
| 23 |
# - extended partition containers |
| 24 |
# - partition tables |
| 25 |
# |
| 26 |
# So we partition a disk with two logical partitions, one of which |
| 27 |
# has a filesystem on it. |
| 28 |
|
| 29 |
disk1 = self.add_ram_disk() |
| 30 |
disk2 = self.add_loopback_disk() |
| 31 |
|
| 32 |
self.login_and_go("/storage") |
| 33 |
|
| 34 |
b.wait_visible(self.card_row("Storage", name=disk1)) |
| 35 |
b.wait_visible(self.card_row("Storage", name=disk2)) |
| 36 |
script = """mktable msdos \ |
| 37 |
mkpart extended 1 50 \ |
| 38 |
mkpart logical ext2 2 24 \ |
| 39 |
mkpart logical ext2 24 48""" |
| 40 |
m.execute(f"parted -s {disk1} {script}") |
| 41 |
m.execute("udevadm trigger; udevadm settle") |
| 42 |
m.execute(f"until udevadm info --query=all {disk1}5 | grep -q ID_PART_TABLE_TYPE=dos; do sleep 0.1; done") |
| 43 |
m.execute(f"mke2fs -q -L TEST {disk1}5") |
| 44 |
|
| 45 |
b.eval_js(""" |
| 46 |
ph_texts = function (sel) { |
| 47 |
return ph_select(sel).map(function(e) { return e.textContent }); |
| 48 |
}""") |
| 49 |
|
| 50 |
def check_free_block_devices(): |
| 51 |
blocks = b.eval_js("ph_texts('#dialog [data-field=\"disks\"] .select-space-details')") |
| 52 |
print("blocks", blocks) |
| 53 |
# On Ubuntu we see /dev/ram devices as well |
| 54 |
# On Fedora also /dev/zram0 - see https://github.com/cockpit-project/cockpit/issues/14516 |
| 55 |
allowed = ["/dev/sda", "/dev/loop", "/dev/vda", "/dev/ram", "/dev/zram"] |
| 56 |
for block in blocks: |
| 57 |
for allow in allowed: |
| 58 |
if allow in block: |
| 59 |
break |
| 60 |
else: |
| 61 |
return False |
| 62 |
|
| 63 |
# Require these two to be present |
| 64 |
return f"{disk1}6" in blocks and disk2 in blocks |
| 65 |
|
| 66 |
self.dialog_with_retry(trigger=lambda: self.click_dropdown(self.card_header("Storage"), |
| 67 |
"Create MDRAID device"), |
| 68 |
expect=check_free_block_devices, |
| 69 |
values=None) |
| 70 |
|
| 71 |
|
| 72 |
if __name__ == '__main__': |
| 73 |
testlib.test_main() |