From 8ada4a8624430562aa95ea72bc2eafec5fbe27e2 Mon Sep 17 00:00:00 2001 From: Johannes Leupolz Date: Tue, 3 Feb 2026 20:39:11 +0000 Subject: [PATCH] Prepare cloud-init iso file to be able to initialize VMs with various distributions for automated tests --- .../cloud-init/create-cloud-init-iso.sh | 60 +++++++++++++++++++ .../cloud-init/template/meta-data.tmpl | 2 + .../cloud-init/template/user-data.tmpl | 21 +++++++ 3 files changed, 83 insertions(+) create mode 100644 distro-tests/cloud-init/create-cloud-init-iso.sh create mode 100644 distro-tests/cloud-init/template/meta-data.tmpl create mode 100644 distro-tests/cloud-init/template/user-data.tmpl diff --git a/distro-tests/cloud-init/create-cloud-init-iso.sh b/distro-tests/cloud-init/create-cloud-init-iso.sh new file mode 100644 index 0000000..8696a70 --- /dev/null +++ b/distro-tests/cloud-init/create-cloud-init-iso.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +set -eu + +# How to do it is documented on https://cloudinit.readthedocs.io/en/latest/howto/launch_qemu.html + + +ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +PREPARED_DIR="${ROOT_DIR}/prepared" +IDENTITY_DIR="${PREPARED_DIR}/identity" +TMP_DIR="${ROOT_DIR}/tmp" + +KEY_PRIV="${IDENTITY_DIR}/ssh_ed25519" +KEY_PUB="${IDENTITY_DIR}/ssh_ed25519.pub" + +USER_DATA_SRC="${ROOT_DIR}/cloud-init/template/user-data.tmpl" +META_DATA_SRC="${ROOT_DIR}/cloud-init/template/meta-data.tmpl" + +mkdir -p ${TMP_DIR} + +# -------------------------------------------------------------------- +# SSH identity (per user, stable) +# -------------------------------------------------------------------- +if [ ! -f "${KEY_PRIV}" ]; then + echo "[*] Generating SSH keypair" + ssh-keygen -t ed25519 -N "" -f "${KEY_PRIV}" -C "distro-tests" +else + echo "[*] Reusing existing SSH key" +fi + +SSH_KEY="$(cat "${KEY_PUB}")" + +# -------------------------------------------------------------------- +# Build user-data with injected SSH key +# -------------------------------------------------------------------- +USER_DATA_TMP="${TMP_DIR}/user-data" +META_DATA_TMP="${TMP_DIR}/meta-data" + +awk -v key="${SSH_KEY}" ' + /^users:/ { print; users=1; next } + users && /ssh_authorized_keys:/ { + print + print " - " key + next + } + { print } +' "${USER_DATA_SRC}" > "${USER_DATA_TMP}" + +cp "${META_DATA_SRC}" "${META_DATA_TMP}" + +# -------------------------------------------------------------------- +# Create seed ISO +# -------------------------------------------------------------------- +echo "[*] Creating cloud-init seed.iso" +cloud-localds \ + "${PREPARED_DIR}/seed.iso" \ + "${USER_DATA_TMP}" \ + "${META_DATA_TMP}" + +echo "[✓] cloud-init ISO ready: ${PREPARED_DIR}/seed.iso" diff --git a/distro-tests/cloud-init/template/meta-data.tmpl b/distro-tests/cloud-init/template/meta-data.tmpl new file mode 100644 index 0000000..0769594 --- /dev/null +++ b/distro-tests/cloud-init/template/meta-data.tmpl @@ -0,0 +1,2 @@ +instance-id: vuinputd-distro-tests +local-hostname: vuinputd-distro-tests diff --git a/distro-tests/cloud-init/template/user-data.tmpl b/distro-tests/cloud-init/template/user-data.tmpl new file mode 100644 index 0000000..ed7c399 --- /dev/null +++ b/distro-tests/cloud-init/template/user-data.tmpl @@ -0,0 +1,21 @@ +#cloud-config +# +# Shared cloud-init configuration for distro-tests +# SSH keys are injected dynamically by create-cloud-init-iso.sh +# + +users: + - name: testuser + groups: users, adm + shell: /bin/bash + sudo: ALL=(ALL) NOPASSWD:ALL + ssh_authorized_keys: + +disable_root: true +ssh_pwauth: false + +package_update: false +package_upgrade: false + +runcmd: + - echo "cloud-init bootstrap complete" > /var/tmp/cloud-init-ok