From 2897feb43e62854e89cb9a3af3a2e1a92bb62c0d Mon Sep 17 00:00:00 2001 From: Clint Branham Date: Sun, 23 Aug 2026 09:27:27 -0500 Subject: [PATCH] ci: cleanup honours PVE_TARGET_NODE and the ISO storage var A pool-scoped token cannot list /nodes, so node discovery fell back to 'pve' and force-cleanup silently found no VMs to destroy. --- tests/infrastructure/scripts/preflight-cleanup.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/infrastructure/scripts/preflight-cleanup.sh b/tests/infrastructure/scripts/preflight-cleanup.sh index ef12e33..760a7b8 100755 --- a/tests/infrastructure/scripts/preflight-cleanup.sh +++ b/tests/infrastructure/scripts/preflight-cleanup.sh @@ -13,9 +13,13 @@ ISO_FILENAME="$4" TF_DIR="$5" API_BASE="${PVE_ENDPOINT}/api2/json" -# Discover node name -NODES_JSON=$(curl -sk -H "Authorization: PVEAPIToken=${API_TOKEN}" "${API_BASE}/nodes" 2>/dev/null) -NODE=$(echo "$NODES_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['data'][0]['node'])" 2>/dev/null || echo "pve") +# Node: PVE_TARGET_NODE when set (a pool-scoped token cannot list /nodes), else the first node. +NODE="${PVE_TARGET_NODE:-}" +if [ -z "$NODE" ]; then + NODES_JSON=$(curl -sk -H "Authorization: PVEAPIToken=${API_TOKEN}" "${API_BASE}/nodes" 2>/dev/null) + NODE=$(echo "$NODES_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['data'][0]['node'])" 2>/dev/null || echo "pve") +fi +ISO_STORAGE="${TF_VAR_iso_storage:-local}" echo "=== Pre-flight cleanup (node: ${NODE}, vmid: ${VM_ID}) ===" @@ -53,7 +57,7 @@ if [ -z "$ISO_FILENAME" ]; then echo "No ISO filename specified, skipping ISO cleanup" else ISO_EXISTS=$(curl -sk -H "Authorization: PVEAPIToken=${API_TOKEN}" \ - "${API_BASE}/nodes/${NODE}/storage/local/content" 2>/dev/null \ + "${API_BASE}/nodes/${NODE}/storage/${ISO_STORAGE}/content" 2>/dev/null \ | python3 -c " import json, sys data = json.load(sys.stdin).get('data', []) @@ -68,7 +72,7 @@ if [ -n "$ISO_EXISTS" ]; then echo " Deleting..." ENCODED=$(python3 -c "import urllib.parse; print(urllib.parse.quote('${ISO_EXISTS}', safe=''))") curl -sk -X DELETE -H "Authorization: PVEAPIToken=${API_TOKEN}" \ - "${API_BASE}/nodes/${NODE}/storage/local/content/${ENCODED}" >/dev/null 2>&1 + "${API_BASE}/nodes/${NODE}/storage/${ISO_STORAGE}/content/${ENCODED}" >/dev/null 2>&1 sleep 2 echo " ISO cleanup done" else