From 778e91f0bcad999aa5a359ec9db5e2f4862e870c Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 5 Sep 2024 13:55:16 +0200 Subject: [PATCH] kola/tests: Add an open-iscsi test --- kola/tests/packages/openiscsi.go | 150 +++++++++++++++++++++++++++++++ kola/tests/packages/packages.go | 3 +- 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 kola/tests/packages/openiscsi.go diff --git a/kola/tests/packages/openiscsi.go b/kola/tests/packages/openiscsi.go new file mode 100644 index 000000000..eb6c1e73a --- /dev/null +++ b/kola/tests/packages/openiscsi.go @@ -0,0 +1,150 @@ +package packages + +import ( + "fmt" + "strings" + + "github.com/flatcar/mantle/kola/cluster" + "github.com/flatcar/mantle/kola/tests/util" + "github.com/flatcar/mantle/platform" +) + +var ( + clientScript1 = util.TrimLeftSpace(` +#!/bin/bash + +set -euo pipefail + +sudo systemctl start iscsid +for i in {0..9}; do + if [[ ! -e /etc/iscsi/initiatorname.iscsi ]]; then + sleep 1 + continue + fi + name=$(grep -F InitiatorName /etc/iscsi/initiatorname.iscsi | cut -d= -f2-) + if [[ -z ${name} ]]; then + echo "malformed initiator name config" + exit 1 + fi + exit 0 +done +echo "no initiator name config found" +exit 1 +`) + + serverScript = util.TrimLeftSpace(` +#!/bin/bash + +set -euo pipefail + +initiator=${1} + +mkdir -p /shared /etc/rtslib-fb-target + +cat </shared/init.script +cd / +backstores/fileio create test /shared/test.img 100m +iscsi/ create iqn.2006-04.com.example:test-target +cd iscsi/iqn.2006-04.com.example:test-target/tpg1/ +luns/ create /backstores/fileio/test +set attribute generate_node_acls=1 +acls/ create ${initiator} +EOF + +docker_args=( + --privileged + --network host + --mount type=bind,source=/sys,destination=/sys + --mount type=bind,source=/etc/rtslib-fb-target,destination=/etc/rtslib-fb-target + --mount type=bind,source=/shared,destination=/shared + --mount type=bind,source=/run/dbus,destination=/run/dbus,readonly + --mount type=bind,source=/usr/lib/modules,destination=/usr/lib/modules,readonly + --rm +) + +docker run "${docker_args[@]}" ghcr.io/flatcar/targetcli-fb bash -c 'targetcli /drive/test-file +umount /drive + +systemctl enable iscsi +`) + + clientScript3 = util.TrimLeftSpace(` +#!/bin/bash + +if [[ ! -e /dev/sda ]]; then + echo "no /dev/sda device after reboot" + exit 1 +fi + +mkdir -p /drive +mount -t ext2 /dev/sda /drive + +if [[ ! -e /drive/test-file ]]; then + echo 'expected file missing' + exit 1 +fi + +contents=$(cat /drive/test-file) +if [[ ${contents} != 'seems to be working' ]]; then + echo "unexpected file contents: ${contents@Q}" + exit 1 +fi +umount /drive +`) +) + +func openISCSI(c cluster.TestCluster) { + // machine 0 will have the remote disk mounted + // + // machine 1 will be a disk provider + client := c.Machines()[0] + server := c.Machines()[1] + + for name, script := range map[string]string{ + "/get_initiator": clientScript1, + "/discover": clientScript2, + "/check": clientScript3, + } { + if err := platform.InstallFile(strings.NewReader(script), client, name); err != nil { + c.Fatalf("failed to upload script %s to client: %v", name, err) + } + } + if err := platform.InstallFile(strings.NewReader(serverScript), server, "/setup"); err != nil { + c.Fatalf("failed to upload script /setup to client: %v", err) + } + + c.MustSSH(client, "sudo chmod a+x /get_initiator /discover /check") + c.MustSSH(server, "sudo chmod a+x /setup") + + initiatorName := c.MustSSH(client, `sudo /get_initiator`) + c.MustSSH(server, fmt.Sprintf("sudo /setup '%s'", initiatorName)) + c.MustSSH(client, fmt.Sprintf("sudo /discover %s", server.PrivateIP())) + if err := client.Reboot(); err != nil { + c.Fatalf("failed to reboot the client: %v", err) + } + c.MustSSH(client, "sudo /check") +} diff --git a/kola/tests/packages/packages.go b/kola/tests/packages/packages.go index 3a5b34598..43535be7a 100644 --- a/kola/tests/packages/packages.go +++ b/kola/tests/packages/packages.go @@ -22,7 +22,7 @@ import ( func init() { register.Register(®ister.Test{ Run: packageTests, - ClusterSize: 1, + ClusterSize: 2, Name: "packages", Distros: []string{"cl"}, // This test is normally not related to the cloud environment @@ -32,4 +32,5 @@ func init() { func packageTests(c cluster.TestCluster) { c.Run("sys-cluster/ipvsadm", ipvsadm) + c.Run("sys-block/open-iscsi", openISCSI) }