diff options
| author | Craig Jennings <c@cjennings.net> | 2026-01-27 17:22:55 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-01-27 17:22:55 -0600 |
| commit | 70bb2d5ab1bf6787bc613e33f5398be2eca1f5fd (patch) | |
| tree | 0d8cd5057dd32f5f312a7f3534d590b99c2f0f91 /scripts/testing/debug-vm.sh | |
| parent | 0c6175bfc98f2c5ff2debc665fd8bf91f9171f4e (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/debug-vm.sh')
| -rwxr-xr-x | scripts/testing/debug-vm.sh | 122 |
1 files changed, 49 insertions, 73 deletions
diff --git a/scripts/testing/debug-vm.sh b/scripts/testing/debug-vm.sh index a442850..5b2b197 100755 --- a/scripts/testing/debug-vm.sh +++ b/scripts/testing/debug-vm.sh @@ -2,6 +2,9 @@ # Launch VM for interactive debugging # Author: Craig Jennings <craigmartinjennings@gmail.com> # License: GNU GPLv3 +# +# Launches a QEMU VM with a graphical display for interactive debugging. +# Uses a copy-on-write overlay when using --base to protect the base image. set -e @@ -27,21 +30,23 @@ else echo "Usage: $0 [disk-image.qcow2 | --base]" echo "" echo "Options:" - echo " --base Use base VM (read-only, safe for testing)" - echo " disk-image.qcow2 Use existing test disk image" - echo " (no args) Clone base VM for debugging" + echo " --base Use base VM via copy-on-write overlay (safe)" + echo " disk-image.qcow2 Use existing test disk image directly" + echo " (no args) Same as --base" exit 1 fi # Configuration TIMESTAMP=$(date +'%Y%m%d-%H%M%S') -DEBUG_VM_NAME="archsetup-debug-$TIMESTAMP" -BASE_DISK="$PROJECT_ROOT/vm-images/archsetup-base.qcow2" +VM_IMAGES_DIR="$PROJECT_ROOT/vm-images" +BASE_DISK="$VM_IMAGES_DIR/archsetup-base.qcow2" ROOT_PASSWORD="archsetup" +OVERLAY_DISK="" -# Initialize logging +# Initialize logging and VM paths LOGFILE="/tmp/debug-vm-$TIMESTAMP.log" init_logging "$LOGFILE" +init_vm_paths "$VM_IMAGES_DIR" section "Launching Debug VM" @@ -50,84 +55,55 @@ if $USE_BASE; then if [ ! -f "$BASE_DISK" ]; then fatal "Base disk not found: $BASE_DISK" fi - VM_DISK="$BASE_DISK" - info "Using base VM (read-only snapshot mode)" -else - if [ -z "$VM_DISK" ]; then - # Clone base VM - VM_DISK="$PROJECT_ROOT/vm-images/$DEBUG_VM_NAME.qcow2" - step "Cloning base VM for debugging" - clone_disk "$BASE_DISK" "$VM_DISK" || fatal "Failed to clone base VM" - success "Debug disk created: $VM_DISK" + + # Create a copy-on-write overlay (instant, protects base image) + OVERLAY_DISK="$VM_IMAGES_DIR/debug-overlay-$TIMESTAMP.qcow2" + step "Creating copy-on-write overlay" + if qemu-img create -f qcow2 -b "$BASE_DISK" -F qcow2 "$OVERLAY_DISK" >> "$LOGFILE" 2>&1; then + success "Overlay created: $(basename "$OVERLAY_DISK")" else - info "Using existing disk: $VM_DISK" + fatal "Failed to create overlay disk" fi + VM_DISK="$OVERLAY_DISK" +else + info "Using existing disk: $VM_DISK" fi -# Create debug VM -step "Creating debug VM: $DEBUG_VM_NAME" -virt-install \ - --connect qemu:///system \ - --name "$DEBUG_VM_NAME" \ - --memory 4096 \ - --vcpus 2 \ - --disk path="$VM_DISK",format=qcow2,bus=virtio \ - --os-variant archlinux \ - --network network=default,model=virtio \ - --graphics vnc,listen=127.0.0.1 \ - --console pty,target.type=serial \ - --boot uefi \ - --import \ - --noautoconsole \ - >> "$LOGFILE" 2>&1 - -success "Debug VM created" - -# Wait for boot -step "Waiting for VM to boot..." -sleep 20 - -# Get VM IP -VM_IP=$(get_vm_ip "$DEBUG_VM_NAME" 2>/dev/null || true) +# If snapshot exists, restore it first (only for non-overlay disks) +if [ -z "$OVERLAY_DISK" ] && snapshot_exists "$VM_DISK" "clean-install"; then + step "Restoring clean-install snapshot" + restore_snapshot "$VM_DISK" "clean-install" +fi + +# Launch QEMU with graphical display +step "Starting QEMU with graphical display" +start_qemu "$VM_DISK" "disk" "" "gtk" || fatal "Failed to start QEMU" # Display connection information section "Debug VM Ready" info "" -info "VM Name: $DEBUG_VM_NAME" -if [ -n "$VM_IP" ]; then - info "IP Address: $VM_IP" -fi -info "Disk: $VM_DISK" +info " Disk: $(basename "$VM_DISK")" +info " SSH: sshpass -p '$ROOT_PASSWORD' ssh -p $SSH_PORT root@localhost" +info " Root password: $ROOT_PASSWORD" info "" -info "Connect via:" -info " Console: virsh console $DEBUG_VM_NAME" -if [ -n "$VM_IP" ]; then - info " SSH: ssh root@$VM_IP" -fi -info " VNC: virt-viewer $DEBUG_VM_NAME" -info "" -info "Root password: $ROOT_PASSWORD" -info "" -info "When done debugging:" -info " virsh destroy $DEBUG_VM_NAME" -info " virsh undefine $DEBUG_VM_NAME" -if [ ! "$VM_DISK" = "$BASE_DISK" ] && [ -z "$1" ]; then - info " rm $VM_DISK" -fi -info "" -info "Log file: $LOGFILE" +info " The GTK window should be open. Close it to stop the VM." +info " Log file: $LOGFILE" info "" -# Offer to connect to console -read -p "Connect to console now? [Y/n] " -n 1 -r -echo "" -if [[ $REPLY =~ ^[Nn]$ ]]; then - info "VM is running in background" - info "Connect later with: virsh console $DEBUG_VM_NAME" -else - info "Connecting to console..." - info "Press Ctrl+] to disconnect from console" +# Wait for QEMU to exit (user closes GTK window) +step "Waiting for VM to exit..." +while vm_is_running; do sleep 2 - virsh console "$DEBUG_VM_NAME" +done +success "VM has stopped" + +# Clean up overlay disk +if [ -n "$OVERLAY_DISK" ] && [ -f "$OVERLAY_DISK" ]; then + step "Removing overlay disk" + rm -f "$OVERLAY_DISK" + success "Overlay cleaned up" fi + +_cleanup_qemu_files +info "Debug session complete" |
