From 2846a74f6b53d9a70d233dbea2cd9e34f4ca88b5 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 5 Sep 2024 13:51:35 +0200 Subject: [PATCH 1/3] other-dockerfiles: Add a Dockerfile for targetcli-fb These dockerfiles will be consumed by the github action, that will build docker images and upload to our ghcr.io registry. The new image will be used later by the open-iscsi test. --- other-dockerfiles/targetcli-fb/Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 other-dockerfiles/targetcli-fb/Dockerfile diff --git a/other-dockerfiles/targetcli-fb/Dockerfile b/other-dockerfiles/targetcli-fb/Dockerfile new file mode 100644 index 000000000..26238730f --- /dev/null +++ b/other-dockerfiles/targetcli-fb/Dockerfile @@ -0,0 +1,5 @@ +# For this image to work /sys, /etc, /run/dbus and /usr/lib/modules +# need to be forwarded, also needs --privileged and --network host. + +FROM docker.io/library/debian:bookworm-slim +RUN apt-get update && apt-get upgrade --assume-yes && apt-get install --assume-yes --no-install-recommends kmod targetcli-fb From c3fadfe694ca49db6bf4d756339ab215de21b9e5 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 5 Sep 2024 13:53:15 +0200 Subject: [PATCH 2/3] .github: Add an action for building docker images on-demand There isn't a clear way to tell when the image should be rebuilt automatically. In theory it should be when the relevant debian package gets an update or when a new Debian version is released. In practice, these are annoying to track, so the action is to be invoked on demand. --- .../workflows/build-other-docker-image.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/build-other-docker-image.yaml diff --git a/.github/workflows/build-other-docker-image.yaml b/.github/workflows/build-other-docker-image.yaml new file mode 100644 index 000000000..844cc9002 --- /dev/null +++ b/.github/workflows/build-other-docker-image.yaml @@ -0,0 +1,52 @@ +name: Build other docker image +on: + workflow_dispatch: + inputs: + image_name: + description: "Name of the image from the other-dockerfiles directory." + required: true + type: choice + options: + - targetcli-fb + +env: + REGISTRY: ghcr.io + ORG: flatcar + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: linux/amd64,linux/arm64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: other-dockerfiles/${{ inputs.image_name }} + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ inputs.image_name }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max From e20bf97bf445f14f35727ad912a57b0e60dc2e28 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 5 Sep 2024 13:55:16 +0200 Subject: [PATCH 3/3] kola/tests: Add an open-iscsi test --- kola/tests/packages/openiscsi.go | 157 +++++++++++++++++++++++++++++++ kola/tests/packages/packages.go | 3 +- 2 files changed, 159 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..ede61a098 --- /dev/null +++ b/kola/tests/packages/openiscsi.go @@ -0,0 +1,157 @@ +package packages + +import ( + "fmt" + "strings" + + "github.com/flatcar/mantle/kola/cluster" + "github.com/flatcar/mantle/kola/tests/util" + "github.com/flatcar/mantle/platform" +) + +var ( + getInitiatorClientScript = 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 + echo "${name}" + exit 0 +done +echo "no initiator name config found" +exit 1 +`) + + setupServerScript = util.TrimLeftSpace(` +#!/bin/bash + +set -euo pipefail + +initiator=${1} + +mkdir -p /shared + +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=/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 +`) + + checkClientScript = util.TrimLeftSpace(` +#!/bin/bash + +set -euo pipefail + +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": getInitiatorClientScript, + "/discover": discoverClientScript, + "/check": checkClientScript, + } { + 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(setupServerScript), server, "/setup"); err != nil { + c.Fatalf("failed to upload script /setup to server: %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) }