summaryrefslogtreecommitdiff
path: root/tests/pve/create-vm.sh
diff options
context:
space:
mode:
authorRoberto Bertó <463349+robertoberto@users.noreply.github.com>2026-05-19 06:05:43 +0000
committerRoberto Bertó <463349+robertoberto@users.noreply.github.com>2026-05-19 06:05:43 +0000
commitbfcaffe9c55b687038eab337a718ea0a43f5e668 (patch)
tree10bf25a4d67a3809a185a7a0aef99fbd3da3e535 /tests/pve/create-vm.sh
parentc5a2ae114835791de16c5b982632569377c39bfa (diff)
downloadpyvyos-bfcaffe9c55b687038eab337a718ea0a43f5e668.tar.gz
pyvyos-bfcaffe9c55b687038eab337a718ea0a43f5e668.zip
tests: add live VyOS e2e harness on Proxmox
Adds an opt-in end-to-end harness that runs pyvyos against a real VyOS HTTPS API on a Proxmox VE host. tests/pve/ shell-based VM lifecycle on a remote PVE host: preflight, ensure-template (state-machine over the VMID with manual-install phase 1 and cloud-init phase 2), create/start/stop/destroy, run-e2e. Cloud-init seed ISO is generated on the PVE host itself; nothing local-side beyond ssh is required. .env is gitignored; .env.example documents the full set of variables. tests/e2e/ pytest suite that exercises the public methods most likely to regress on a payload change: show, retrieve_show_config, configure_set / retrieve_return_values / configure_delete round trip, and configure_multiple_op batch. Auto-skipped unless PYVYOS_E2E=1. The cloud-init template now sets 'service https api rest' before the API key. Without that flag VyOS only exposes /info; the other HTTPS routes return 404. README and tests/pve/README document the requirement, both for cloud-init and for the manual-fallback path. Also fixes a pre-existing footgun in pyproject.toml: the pytest-env defaults overwrote VYDEVICE_HOSTNAME from the shell, which made the e2e tests silently aim at the stale 192.168.56.100 fixture host. The entries now use the 'D:' (default) prefix so live runs can override from the environment as expected. Validated against VyOS rolling 2026.05.18-0045: 4 e2e + 57 unit tests pass. This commit does not change pyvyos HTTP payloads, request handling, or response parsing.
Diffstat (limited to 'tests/pve/create-vm.sh')
-rwxr-xr-xtests/pve/create-vm.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/pve/create-vm.sh b/tests/pve/create-vm.sh
new file mode 100755
index 0000000..af34a66
--- /dev/null
+++ b/tests/pve/create-vm.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+# tests/pve/create-vm.sh — clone the template into a fresh e2e VM.
+#
+# Refuses to overwrite an existing VMID. Use destroy-vm.sh first if
+# the e2e VMID is already taken.
+
+set -euo pipefail
+
+HERE="$(cd "$(dirname "$0")" && pwd)"
+# shellcheck source=_lib.sh
+source "$HERE/_lib.sh"
+
+pve_load_env
+pve_require_reachable
+
+hdr "Check e2e VMID $VYOS_E2E_VMID is free"
+if pve_qm status "$VYOS_E2E_VMID" >/dev/null 2>&1; then
+ echo "ERR: VMID $VYOS_E2E_VMID already exists." >&2
+ echo " run tests/pve/destroy-vm.sh first, or pick a different VYOS_E2E_VMID." >&2
+ exit 1
+fi
+
+hdr "Check template $VYOS_TEMPLATE_VMID exists"
+if ! pve_qm config "$VYOS_TEMPLATE_VMID" | grep -q '^template: 1'; then
+ echo "ERR: template VMID $VYOS_TEMPLATE_VMID not found." >&2
+ echo " run tests/pve/ensure-template.sh first." >&2
+ exit 1
+fi
+
+hdr "qm clone $VYOS_TEMPLATE_VMID -> $VYOS_E2E_VMID"
+pve_qm clone "$VYOS_TEMPLATE_VMID" "$VYOS_E2E_VMID" \
+ --name "$VYOS_E2E_VM_NAME" --full true
+
+hdr "qm set memory/cores/static-ip"
+# The template already carries the HTTPS API key (baked by cloud-init
+# at template-build time), so this clone does not need another seed.
+# We only override the static IP via PVE's ipconfig drive.
+pve_qm set "$VYOS_E2E_VMID" \
+ --memory "$VYOS_E2E_MEMORY" --cores "$VYOS_E2E_CORES" \
+ --ipconfig0 "ip=$VYOS_E2E_IP/$VYOS_E2E_CIDR,gw=$VYOS_E2E_GATEWAY"
+
+echo "ok: VM $VYOS_E2E_VMID created (not started). Next: tests/pve/start-vm.sh" >&2