summaryrefslogtreecommitdiff
path: root/scripts/testing/cleanup-tests.sh
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-01-27 17:22:55 -0600
committerCraig Jennings <c@cjennings.net>2026-01-27 17:22:55 -0600
commit70bb2d5ab1bf6787bc613e33f5398be2eca1f5fd (patch)
tree0d8cd5057dd32f5f312a7f3534d590b99c2f0f91 /scripts/testing/cleanup-tests.sh
parent0c6175bfc98f2c5ff2debc665fd8bf91f9171f4e (diff)
feat(testing): rewrite test infrastructure from libvirt to direct QEMU
Replace the never-fully-operational libvirt-based VM test infrastructure with direct QEMU management and archangel ISO for fully automated, unattended base VM creation. Key changes: - vm-utils.sh: complete rewrite — QEMU process mgmt via PID file, monitor socket for graceful shutdown, qemu-img snapshots, SSH port forwarding (localhost:2222) - create-base-vm.sh: boots archangel ISO, SSHs in, runs unattended install via config file, verifies, creates clean-install snapshot - run-test.sh: snapshot revert, git bundle transfer, detached archsetup execution with setsid, polling, validation, and report generation - debug-vm.sh: CoW overlay disk, GTK display, auto-cleanup on close - setup-testing-env.sh: reduced deps to qemu-full/sshpass/edk2-ovmf/socat - cleanup-tests.sh: PID-based process management, orphan detection - validation.sh: port-based SSH (backward compatible), fuzzel/foot for Hyprland, corrected package list paths - network-diagnostics.sh: getent/curl instead of nslookup/ping (SLIRP) New files: - archsetup-test.conf: archangel config for base VM (btrfs, no encrypt) - archsetup-vm.conf: archsetup config for unattended test execution - assets/archangel.conf.example: reference archangel config Deleted: - finalize-base-vm.sh: merged into create-base-vm.sh - archinstall-config.json: replaced by archangel .conf format Tested: full end-to-end run — 51 validations passed, 0 failures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'scripts/testing/cleanup-tests.sh')
-rwxr-xr-xscripts/testing/cleanup-tests.sh125
1 files changed, 63 insertions, 62 deletions
diff --git a/scripts/testing/cleanup-tests.sh b/scripts/testing/cleanup-tests.sh
index e4289a7..fd2f8de 100755
--- a/scripts/testing/cleanup-tests.sh
+++ b/scripts/testing/cleanup-tests.sh
@@ -36,85 +36,86 @@ while [[ $# -gt 0 ]]; do
esac
done
-# Initialize logging
+# Initialize logging and VM paths
LOGFILE="/tmp/cleanup-tests-$(date +'%Y%m%d-%H%M%S').log"
init_logging "$LOGFILE"
+init_vm_paths "$PROJECT_ROOT/vm-images"
section "Cleaning Up Test Artifacts"
-# Find all test VMs
-step "Finding test VMs"
-TEST_VMS=$(virsh --connect qemu:///system list --all | grep "archsetup-test-" | awk '{print $2}' || true)
+# Find and stop running QEMU processes
+step "Checking for running QEMU processes"
-if [ -z "$TEST_VMS" ]; then
- info "No test VMs found"
-else
- VM_COUNT=$(echo "$TEST_VMS" | wc -l)
- info "Found $VM_COUNT test VM(s)"
-
- if ! $FORCE; then
- echo ""
- echo "$TEST_VMS"
- echo ""
- read -p "Destroy these VMs? [y/N] " -n 1 -r
+if vm_is_running; then
+ info "Found running QEMU test VM (PID: $(cat "$PID_FILE"))"
+ if $FORCE; then
+ stop_qemu
+ else
+ read -p "Stop running VM? [y/N] " -n 1 -r
echo ""
- if [[ ! $REPLY =~ ^[Yy]$ ]]; then
- info "Skipping VM cleanup"
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
+ stop_qemu
else
- for vm in $TEST_VMS; do
- step "Destroying VM: $vm"
- if vm_is_running "$vm"; then
- virsh --connect qemu:///system destroy "$vm" >> "$LOGFILE" 2>&1
- fi
- virsh --connect qemu:///system undefine "$vm" --nvram >> "$LOGFILE" 2>&1 || true
- success "VM destroyed: $vm"
- done
+ info "Skipping VM shutdown"
fi
+ fi
+else
+ info "No running VM found"
+fi
+
+# Check for orphaned QEMU processes
+QEMU_PIDS=$(pgrep -f "qemu-system.*archsetup-test" 2>/dev/null || true)
+if [ -n "$QEMU_PIDS" ]; then
+ info "Found orphaned QEMU processes: $QEMU_PIDS"
+ if $FORCE; then
+ echo "$QEMU_PIDS" | xargs kill -9 2>/dev/null || true
+ success "Orphaned processes killed"
else
- for vm in $TEST_VMS; do
- step "Destroying VM: $vm"
- if vm_is_running "$vm"; then
- virsh --connect qemu:///system destroy "$vm" >> "$LOGFILE" 2>&1
- fi
- virsh --connect qemu:///system undefine "$vm" --nvram >> "$LOGFILE" 2>&1 || true
- success "VM destroyed: $vm"
- done
+ read -p "Kill orphaned QEMU processes? [y/N] " -n 1 -r
+ echo ""
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
+ echo "$QEMU_PIDS" | xargs kill -9 2>/dev/null || true
+ success "Orphaned processes killed"
+ fi
fi
fi
-# Clean up test disk images
+# Clean up QEMU runtime files
+rm -f "$PID_FILE" "$MONITOR_SOCK"
+
+# Clean up debug overlay and test disk images
section "Cleaning Up Disk Images"
-step "Finding test disk images"
+step "Finding temporary disk images"
if [ -d "$PROJECT_ROOT/vm-images" ]; then
- TEST_DISKS=$(find "$PROJECT_ROOT/vm-images" -name "archsetup-test-*.qcow2" 2>/dev/null || true)
+ TEMP_DISKS=$(find "$PROJECT_ROOT/vm-images" -name "debug-overlay-*.qcow2" -o -name "archsetup-test-*.qcow2" 2>/dev/null || true)
- if [ -z "$TEST_DISKS" ]; then
- info "No test disk images found"
+ if [ -z "$TEMP_DISKS" ]; then
+ info "No temporary disk images found"
else
- DISK_COUNT=$(echo "$TEST_DISKS" | wc -l)
- DISK_SIZE=$(du -ch $TEST_DISKS | tail -1 | awk '{print $1}')
- info "Found $DISK_COUNT test disk image(s) totaling $DISK_SIZE"
+ DISK_COUNT=$(echo "$TEMP_DISKS" | wc -l)
+ DISK_SIZE=$(du -ch $TEMP_DISKS 2>/dev/null | tail -1 | awk '{print $1}')
+ info "Found $DISK_COUNT temporary disk image(s) totaling $DISK_SIZE"
- if ! $FORCE; then
+ if $FORCE; then
+ echo "$TEMP_DISKS" | while read disk; do
+ rm -f "$disk"
+ done
+ success "Temporary disk images deleted"
+ else
echo ""
- echo "$TEST_DISKS"
+ echo "$TEMP_DISKS"
echo ""
read -p "Delete these disk images? [y/N] " -n 1 -r
echo ""
- if [[ ! $REPLY =~ ^[Yy]$ ]]; then
- info "Skipping disk cleanup"
- else
- echo "$TEST_DISKS" | while read disk; do
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
+ echo "$TEMP_DISKS" | while read disk; do
rm -f "$disk"
done
- success "Test disk images deleted"
+ success "Temporary disk images deleted"
+ else
+ info "Skipping disk cleanup"
fi
- else
- echo "$TEST_DISKS" | while read disk; do
- rm -f "$disk"
- done
- success "Test disk images deleted"
fi
fi
fi
@@ -141,26 +142,26 @@ else
DELETE_COUNT=$(echo "$TO_DELETE" | wc -l)
info "Keeping last $KEEP_LAST, deleting $DELETE_COUNT old result(s)"
- if ! $FORCE; then
+ if $FORCE; then
+ echo "$TO_DELETE" | while read dir; do
+ rm -rf "$dir"
+ done
+ success "Old test results deleted"
+ else
echo ""
echo "Will delete:"
echo "$TO_DELETE"
echo ""
read -p "Delete these test results? [y/N] " -n 1 -r
echo ""
- if [[ ! $REPLY =~ ^[Yy]$ ]]; then
- info "Skipping results cleanup"
- else
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "$TO_DELETE" | while read dir; do
rm -rf "$dir"
done
success "Old test results deleted"
+ else
+ info "Skipping results cleanup"
fi
- else
- echo "$TO_DELETE" | while read dir; do
- rm -rf "$dir"
- done
- success "Old test results deleted"
fi
fi
fi