| 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.skipImage("UDisks doesn't have support for iSCSI", "debian-*", "ubuntu-*", "arch") |
| 13 |
@testlib.skipImage("udisks2-iscsi not on image", "*-bootc") |
| 14 |
@testlib.nondestructive |
| 15 |
class TestStorageISCSI(storagelib.StorageCase): |
| 16 |
|
| 17 |
def testISCSI(self): |
| 18 |
m = self.machine |
| 19 |
b = self.browser |
| 20 |
|
| 21 |
self.restore_dir("/etc/iscsi") |
| 22 |
self.restore_dir("/var/lib/iscsi") |
| 23 |
|
| 24 |
# ensure that we generate a /etc/iscsi/initiatorname.iscsi |
| 25 |
m.execute("systemctl start iscsid; systemctl stop iscsid") |
| 26 |
|
| 27 |
target_iqn = "iqn.2015-09.cockpit.lan" |
| 28 |
initiator_iqn = "iqn.2015-10.cockpit.lan" |
| 29 |
|
| 30 |
# Increase the iSCSI timeouts for heavy load during our testing |
| 31 |
self.sed_file(r"s|^\(node\..*log.*_timeout = \).*|\1 60|", "/etc/iscsi/iscsid.conf") |
| 32 |
|
| 33 |
# Setup a iSCSI target with authentication for discovery and join |
| 34 |
# |
| 35 |
# HACK - some versions of targetcli crash when TERM is not set |
| 36 |
# and stdout is not a tty. |
| 37 |
# |
| 38 |
# https://bugzilla.redhat.com/show_bug.cgi?id=1441121 |
| 39 |
|
| 40 |
m.execute(f""" |
| 41 |
export TERM=dumb |
| 42 |
targetcli /backstores/ramdisk create test 50M |
| 43 |
targetcli /iscsi set discovery_auth enable=1 userid=admin password=foobar |
| 44 |
targetcli /iscsi create {target_iqn} |
| 45 |
targetcli /iscsi/{target_iqn}/tpg1/luns create /backstores/ramdisk/test |
| 46 |
targetcli /iscsi/{target_iqn}/tpg1 set attribute authentication=1 |
| 47 |
targetcli /iscsi/{target_iqn}/tpg1/acls create {initiator_iqn} |
| 48 |
targetcli /iscsi/{target_iqn}/tpg1/acls/{initiator_iqn} set auth userid=admin password=barfoo |
| 49 |
""") |
| 50 |
self.addCleanup(m.execute, f""" |
| 51 |
targetcli /iscsi delete {target_iqn} |
| 52 |
iscsiadm -m node -o delete || true |
| 53 |
targetcli /backstores/ramdisk delete test""") |
| 54 |
# m.execute("targetcli ls") |
| 55 |
|
| 56 |
self.login_and_go("/storage") |
| 57 |
|
| 58 |
# Set initiator IQN |
| 59 |
orig_iqn = m.execute("sed </etc/iscsi/initiatorname.iscsi -e '/^#/d' -e 's/^.*=//'").rstrip() |
| 60 |
self.click_dropdown(self.card_header("Storage"), "Change iSCSI initiator name") |
| 61 |
self.dialog(expect={"name": orig_iqn}, |
| 62 |
values={"name": initiator_iqn}) |
| 63 |
new_iqn = m.execute("sed </etc/iscsi/initiatorname.iscsi -e '/^#/d' -e 's/^.*=//'").rstrip() |
| 64 |
self.assertEqual(new_iqn, initiator_iqn) |
| 65 |
|
| 66 |
# Access the target |
| 67 |
|
| 68 |
self.click_dropdown(self.card_header("Storage"), "Add iSCSI portal") |
| 69 |
|
| 70 |
self.dialog_wait_open() |
| 71 |
self.dialog_set_val("address", "127.0.0.1") |
| 72 |
self.dialog_set_val("username", "admin") |
| 73 |
self.dialog_set_val("password", "foobar") |
| 74 |
self.dialog_apply() |
| 75 |
# The dialog closes and a new dialog opens but we can't get |
| 76 |
# between that, so we just wait for the new fields to |
| 77 |
# appear. |
| 78 |
b.wait_visible(self.dialog_field("target")) |
| 79 |
b.wait_in_text(self.dialog_field("target"), target_iqn) |
| 80 |
self.dialog_apply() |
| 81 |
# Login will fail and a new dialog opens |
| 82 |
b.wait_visible(self.dialog_field("username")) |
| 83 |
self.dialog_wait_val("username", "admin") |
| 84 |
self.dialog_wait_val("password", "foobar") |
| 85 |
self.dialog_set_val("password", "barfoo") |
| 86 |
self.dialog_apply() |
| 87 |
self.dialog_wait_close() |
| 88 |
|
| 89 |
self.click_card_row("Storage", name=target_iqn) |
| 90 |
b.wait_text(self.card_desc("iSCSI portal", "Address"), "127.0.0.1") |
| 91 |
b.wait_text(self.card_desc("iSCSI portal", "Target"), target_iqn) |
| 92 |
b.wait_in_text(self.card_row_col("iSCSI drives", 1, 1), "LIO-ORG test") |
| 93 |
|
| 94 |
# Make a filesystem on it to prove that the disk really works. |
| 95 |
|
| 96 |
self.click_card_row("iSCSI drives", 1) |
| 97 |
self.click_card_dropdown("Unformatted data", "Format") |
| 98 |
self.dialog({"type": "ext4", |
| 99 |
"name": "FILESYSTEM", |
| 100 |
"mount_point": "/data"}) |
| 101 |
# _netdev should have been prefilled |
| 102 |
b.wait_in_text(self.card_desc("ext4 filesystem", "Mount point"), "after network") |
| 103 |
b.click(self.card_parent_link()) |
| 104 |
b.wait_in_text(self.card_row_col("iSCSI drives", 1, 2), "ext4 filesystem") |
| 105 |
|
| 106 |
self.click_card_dropdown("iSCSI portal", "Disconnect") |
| 107 |
with b.wait_timeout(120): |
| 108 |
b.wait_visible(self.card("Storage")) |
| 109 |
b.wait_not_present(self.card_row("Storage", name=target_iqn)) |
| 110 |
|
| 111 |
b.wait_not_in_text(self.card("Storage"), "LIO-ORG test") |
| 112 |
|
| 113 |
|
| 114 |
if __name__ == '__main__': |
| 115 |
testlib.test_main() |