all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Michael Köppl" <m.koeppl@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH test-tools 2/8] instance: ship generic hook scripts
Date: Tue,  1 Dec 2026 15:58:11 +0100	[thread overview]
Message-ID: <20261201145817.894414-3-m.koeppl@proxmox.com> (raw)
In-Reply-To: <20261201145817.894414-1-m.koeppl@proxmox.com>

Updating the packages of an instance, downloading images into a storage,
installing Ceph, or setting up a ZFS storage or FRR are not specific to
E2E tests. So far, plans could only use these scripts from
proxmox-e2e-tests under a path relative to wherever
proxmox-test-instance was run from.

Ship them with proxmox-test-instance (installed to
/usr/share/proxmox-test-instance/scripts), so that every plan can rely
on them being available at a fixed location. They are copied from
proxmox-e2e-tests.

Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
---
 Makefile                             |  2 +-
 debian/proxmox-test-instance.install |  1 +
 scripts/download-cloud-image.sh      | 21 +++++++++
 scripts/download-container-image.sh  | 22 +++++++++
 scripts/install-ceph.sh              | 13 ++++++
 scripts/setup-frr.sh                 | 18 ++++++++
 scripts/setup-zfs-storage.sh         | 64 ++++++++++++++++++++++++++
 scripts/update-packages.sh           | 69 ++++++++++++++++++++++++++++
 8 files changed, 209 insertions(+), 1 deletion(-)
 create mode 100755 scripts/download-cloud-image.sh
 create mode 100755 scripts/download-container-image.sh
 create mode 100755 scripts/install-ceph.sh
 create mode 100755 scripts/setup-frr.sh
 create mode 100755 scripts/setup-zfs-storage.sh
 create mode 100755 scripts/update-packages.sh

diff --git a/Makefile b/Makefile
index 789bb353..8bce483f 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,7 @@ cargo-build-scheduler:
 build: $(BUILDDIR)
 $(BUILDDIR): | submodule
 	rm -rf $@ $@.tmp; mkdir $@.tmp
-	cp -a proxmox-test-api-types proxmox-test-common proxmox-test-runner proxmox-test-instance proxmox-test-scheduler ui debian Cargo.toml LICENSE Makefile README.md defines.mk $@.tmp/
+	cp -a proxmox-test-api-types proxmox-test-common proxmox-test-runner proxmox-test-instance proxmox-test-scheduler scripts ui debian Cargo.toml LICENSE Makefile README.md defines.mk $@.tmp/
 	rm -rf $@.tmp/ui/target $@.tmp/ui/dist $@.tmp/ui/Cargo.lock
 	mv $@.tmp $@
 
diff --git a/debian/proxmox-test-instance.install b/debian/proxmox-test-instance.install
index a7d2ec88..681bd6e5 100644
--- a/debian/proxmox-test-instance.install
+++ b/debian/proxmox-test-instance.install
@@ -1 +1,2 @@
 target/x86_64-unknown-linux-gnu/release/proxmox-test-instance usr/bin/
+scripts/ usr/share/proxmox-test-instance/
diff --git a/scripts/download-cloud-image.sh b/scripts/download-cloud-image.sh
new file mode 100755
index 00000000..56c57fdf
--- /dev/null
+++ b/scripts/download-cloud-image.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+# Downloads a VM disk image to the import content of a storage, so that VMs can be created from it
+# with 'import-from'. The download is only kept if it matches the given SHA-512 checksum.
+SSH_KEY=$(jq -r '.ssh_private_keyfile' "$CONFIG_PATH")
+HOST=$(jq -r '.host' "$CONFIG_PATH")
+USER=$(jq -r '.ssh_user' "$CONFIG_PATH")
+
+STORAGE=$1
+URL=$2
+FILENAME=$3
+SHA512=$4
+
+ssh -i "$SSH_KEY" "$USER"@"$HOST" -o StrictHostKeyChecking=no <<EOF
+set -e
+
+pvesh create /nodes/localhost/storage/$STORAGE/download-url --content import \
+    --url '$URL' --filename '$FILENAME' --checksum $SHA512 --checksum-algorithm sha512
+# Check the file itself. pvesh exits with 0 even if the download failed, which leaves a file that
+# already exists in place, whatever its content.
+echo "$SHA512  \$(pvesm path $STORAGE:import/$FILENAME)" | sha512sum --check --quiet
+EOF
diff --git a/scripts/download-container-image.sh b/scripts/download-container-image.sh
new file mode 100755
index 00000000..a6539901
--- /dev/null
+++ b/scripts/download-container-image.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+SSH_KEY=$(jq -r '.ssh_private_keyfile' $CONFIG_PATH)
+HOST=$(jq -r '.host' $CONFIG_PATH)
+USER=$(jq -r '.ssh_user' $CONFIG_PATH)
+
+STORAGE=$1
+IMAGE=$2
+
+ssh -i $SSH_KEY $USER@$HOST -o StrictHostKeyChecking=no <<EOF
+set -e
+
+path=\$(pvesm path $STORAGE:vztmpl/$IMAGE)
+# Sometimes requests are rejected with 503, to try again after a while.
+for attempt in 1 2 3 4 5; do
+    pveam download $STORAGE $IMAGE || true
+    # Explicitly check for the path, since download will still return 0 if it fails.
+    [ -e "\$path" ] && exit 0
+    sleep \$((attempt * 10))
+done
+echo "downloading $IMAGE to $STORAGE failed" >&2
+exit 1
+EOF
diff --git a/scripts/install-ceph.sh b/scripts/install-ceph.sh
new file mode 100755
index 00000000..23dc3a06
--- /dev/null
+++ b/scripts/install-ceph.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+SSH_KEY=$(jq -r '.ssh_private_keyfile' $CONFIG_PATH)
+HOST=$(jq -r '.host' $CONFIG_PATH)
+USER=$(jq -r '.ssh_user' $CONFIG_PATH)
+
+VERSION=$1
+REPOSITORY=$2
+
+ssh -i $SSH_KEY $USER@$HOST -o StrictHostKeyChecking=no <<EOT
+set -e
+
+yes | pveceph install --version $VERSION --repository $REPOSITORY
+EOT
diff --git a/scripts/setup-frr.sh b/scripts/setup-frr.sh
new file mode 100755
index 00000000..5be2e1f7
--- /dev/null
+++ b/scripts/setup-frr.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+SSH_KEY=$(jq -r '.ssh_private_keyfile' $CONFIG_PATH)
+HOST=$(jq -r '.host' $CONFIG_PATH)
+USER=$(jq -r '.ssh_user' $CONFIG_PATH)
+
+ssh -i $SSH_KEY $USER@$HOST -o StrictHostKeyChecking=no <<'EOF'
+set -e
+
+echo -e "LANG=C\nLC_ALL=C" | tee /etc/default/locale /etc/environment
+export LANG=C LC_ALL=C
+
+export DEBIAN_FRONTEND=noninteractive
+apt-get -y update
+apt-get -y dist-upgrade
+apt-get -y install frr vlan
+
+systemctl enable --now frr
+EOF
diff --git a/scripts/setup-zfs-storage.sh b/scripts/setup-zfs-storage.sh
new file mode 100755
index 00000000..a00ac552
--- /dev/null
+++ b/scripts/setup-zfs-storage.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+# Create a ZFS pool on an additional disk of a PVE node and register it as a zfspool storage, so
+# tests that need ZFS-backed guest images (storage replication) find one.
+#
+# Usage: setup-zfs-storage.sh <disk-serial> <name>
+#
+# The node needs an extra disk with the given serial. The name is used both for the pool and for
+# the storage id. The disk is looked up by ID_SCSI_SERIAL.
+#
+# Enabling zfs-import@<pool> is what makes the pool come back after the node is powered down at
+# the end of the setup.
+
+set -euo pipefail
+
+SSH_KEY=$(jq -r '.ssh_private_keyfile' $CONFIG_PATH)
+HOST=$(jq -r '.host' $CONFIG_PATH)
+USER=$(jq -r '.ssh_user' $CONFIG_PATH)
+
+SERIAL=$1
+POOL=$2
+
+ssh -i $SSH_KEY $USER@$HOST -o StrictHostKeyChecking=no bash -s -- "$SERIAL" "$POOL" <<'EOF'
+set -e
+
+serial=$1
+pool=$2
+
+dev=""
+for disk in /dev/sd?; do
+    udevadm info --query=property --name="$disk" | grep -qx "ID_SCSI_SERIAL=$serial" || continue
+    dev="$disk"
+    break
+done
+
+if [ -z "$dev" ]; then
+    echo "no disk with SCSI serial '$serial' on $(hostname); disks on this node:" >&2
+    for disk in /dev/sd?; do
+        echo "  $disk $(udevadm info --query=property --name="$disk" \
+            | grep '^ID_SCSI_SERIAL=' || echo 'ID_SCSI_SERIAL=')" >&2
+    done
+    exit 1
+fi
+
+# Prefer the persistent link, as PVE's disk management does, and fall back to the device node
+# for a disk udev created no such link for.
+if link=$(udevadm info --query=symlink --name="$dev" | tr ' ' '\n' | grep -m1 '^disk/by-id/scsi-')
+then
+    dev="/dev/$link"
+fi
+
+if ! zpool list -H "$pool" >/dev/null 2>&1; then
+    zpool create -o ashift=12 "$pool" "$dev"
+    zfs set compression=on "$pool"
+fi
+
+if [ -e /lib/systemd/system/zfs-import@.service ]; then
+    systemctl enable "zfs-import@$pool.service"
+fi
+
+# The storage is what the tests look for, so it needs the content types for guest images.
+if ! pvesm status --storage "$pool" >/dev/null 2>&1; then
+    pvesm add zfspool "$pool" --pool "$pool" --content images,rootdir --sparse 1
+fi
+EOF
diff --git a/scripts/update-packages.sh b/scripts/update-packages.sh
new file mode 100755
index 00000000..b4648dcb
--- /dev/null
+++ b/scripts/update-packages.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+SSH_KEY=$(jq -r '.ssh_private_keyfile' $CONFIG_PATH)
+HOST=$(jq -r '.host' $CONFIG_PATH)
+USER=$(jq -r '.ssh_user' $CONFIG_PATH)
+
+product=$1
+repo=$2
+
+case $product in
+  "pve")
+    maj=9
+    ;;
+  "pmg")
+    maj=9
+    ;;
+  "pbs")
+    maj=4
+    ;;
+  "pdm")
+    maj=1
+    ;;
+  *)
+    echo "unknown product: $product"
+    exit 1
+    ;;
+esac
+
+case $repo in
+  "staging")
+    full_repo="Types: deb
+URIs: http://repo.intra.proxmox.com/staging/${product}
+Suites: trixie
+Components: ${product}-${maj}
+Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg"
+    ;;
+  "no-subscription")
+    full_repo="Types: deb
+URIs: http://download.proxmox.com/debian/${product}
+Suites: trixie
+Components: ${product}-no-subscription
+Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg"
+    ;;
+  "test")
+    full_repo="Types: deb
+URIs: http://download.proxmox.com/debian/${product}
+Suites: trixie
+Components: ${product}-test
+Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg"
+    ;;
+esac
+
+ssh -i $SSH_KEY $USER@$HOST -o StrictHostKeyChecking=no <<EOF
+set -e
+
+echo "Update packages hook running"
+
+tee > /etc/apt/sources.list.d/pve-$repo.sources <<EOT
+$full_repo
+EOT
+
+rm -f /etc/apt/sources.list.d/pve-enterprise.sources
+rm -f /etc/apt/sources.list.d/pbs-enterprise.sources
+rm -f /etc/apt/sources.list.d/pmg-enterprise.sources
+rm -f /etc/apt/sources.list.d/ceph.sources
+
+export DEBIAN_FRONTEND=noninteractive
+apt-get update -y
+apt-get dist-upgrade -y
+EOF
-- 
2.47.3





  parent reply	other threads:[~2026-12-01 14:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 14:58 [PATCH e2e-tests/test-tools 0/8] instance: rework hooks and set up Ceph as a cluster hook Michael Köppl
2026-12-01 14:58 ` [PATCH test-tools 1/8] readme: drop token fields from the hook config example Michael Köppl
2026-12-01 14:58 ` Michael Köppl [this message]
2026-12-01 14:58 ` [PATCH test-tools 3/8] instance: distinguish builtin hooks from hook files Michael Köppl
2026-12-01 14:58 ` [PATCH test-tools 4/8] instance: add hooks that run once a cluster is formed Michael Köppl
2026-12-01 14:58 ` [PATCH test-tools 5/8] instance: cli: run a script once for a whole cluster Michael Köppl
2026-12-01 14:58 ` [PATCH test-tools 6/8] instance: add a builtin hook to set up a Ceph cluster Michael Köppl
2026-12-01 14:58 ` [PATCH e2e-tests 7/8] plans: use the hook scripts shipped with proxmox-test-instance Michael Köppl
2026-12-01 14:58 ` [PATCH e2e-tests 8/8] scripts: drop the scripts now shipped by proxmox-test-instance Michael Köppl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201145817.894414-3-m.koeppl@proxmox.com \
    --to=m.koeppl@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal