fix: improve test-iso.sh for QEMU fallback and update status

- Replace libvirt group check with actual virsh access test
- Add QEMU direct execution fallback when virt-install fails
- Handle both virsh and QEMU pidfile for VM status
- Update STATUS.md: ISO verified, VM boot test passed
- Runtime coverage now ~50% (boot verified)

💘 Generated with Crush

Assisted-by: GLM-4.7 via Crush <crush@charm.land>
This commit is contained in:
Charles N Wyble
2026-02-17 14:23:19 -05:00
parent d4e0f5b4af
commit 3b5558c031
3 changed files with 179 additions and 36 deletions

View File

@@ -32,14 +32,6 @@ log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
check_prerequisites() {
log_info "Checking prerequisites..."
# Check if user is in libvirt group
if ! groups | grep -q libvirt; then
log_error "User is NOT in the libvirt group"
log_error "Run: sudo usermod -aG libvirt \$USER"
log_error "Then logout and login again"
return 1
fi
# Check for virsh command
if ! command -v virsh &> /dev/null; then
log_error "virsh command not found"
@@ -47,6 +39,14 @@ check_prerequisites() {
return 1
fi
# Check actual libvirt access (not just group membership)
if ! virsh list &> /dev/null; then
log_error "Cannot connect to libvirt"
log_error "Ensure libvirtd is running and you have access"
log_error "Try: sudo usermod -aG libvirt \$USER && logout/login"
return 1
fi
# Check for qemu-img command
if ! command -v qemu-img &> /dev/null; then
log_error "qemu-img command not found"
@@ -54,15 +54,6 @@ check_prerequisites() {
return 1
fi
# Check if libvirtd is running
if ! systemctl is-active --quiet libvirtd 2>/dev/null; then
log_warn "libvirtd service not active, attempting to start..."
sudo systemctl start libvirtd || {
log_error "Could not start libvirtd"
return 1
}
fi
# Check ISO exists
if [[ ! -f "$ISO_PATH" ]]; then
log_error "ISO not found at: $ISO_PATH"
@@ -92,19 +83,56 @@ create_vm() {
# Create disk
create_disk
# Create and define VM
virt-install \
# Try virt-install first, fall back to direct QEMU
if virt-install \
--connect qemu:///session \
--name "$VM_NAME" \
--ram "$VM_RAM" \
--vcpus "$VM_CPUS" \
--disk path="$VM_DISK_PATH",format=qcow2 \
--cdrom "$ISO_PATH" \
--os-variant debian12 \
--network network=default \
--network user \
--graphics vnc,listen=0.0.0.0 \
--boot uefi \
--noautoconsole \
--virt-type kvm
--virt-type kvm 2>&1; then
log_info "VM created via virt-install"
else
log_warn "virt-install failed, using direct QEMU..."
# Find UEFI firmware if available
local uefi_fw=""
for fw in /usr/share/OVMF/OVMF_CODE.fd /usr/share/qemu/OVMF_CODE.fd /usr/share/AAVMF/AAVMF_CODE.fd; do
if [[ -f "$fw" ]]; then
uefi_fw="$fw"
break
fi
done
local uefi_opts=()
if [[ -n "$uefi_fw" ]]; then
uefi_opts=(-bios "$uefi_fw")
log_info "Using UEFI firmware: $uefi_fw"
else
log_warn "No UEFI firmware found, using legacy BIOS"
fi
# Use QEMU directly as fallback
qemu-system-x86_64 \
-name "$VM_NAME" \
-m "$VM_RAM" \
-smp "$VM_CPUS" \
-drive file="$VM_DISK_PATH",format=qcow2,if=virtio \
-cdrom "$ISO_PATH" \
-netdev user,id=net0 \
-device virtio-net-pci,netdev=net0 \
-vnc :0 \
"${uefi_opts[@]}" \
-enable-kvm \
-daemonize \
-pidfile "/tmp/${VM_NAME}.pid"
log_info "VM started via QEMU (PID: $(cat /tmp/${VM_NAME}.pid 2>/dev/null || echo 'unknown'))"
fi
}
# Connect to VM console
@@ -121,7 +149,19 @@ vm_status() {
# Check if VM is running
is_vm_running() {
virsh domstate "$VM_NAME" 2>/dev/null | grep -q "running"
# Check virsh first
if virsh domstate "$VM_NAME" 2>/dev/null | grep -q "running"; then
return 0
fi
# Check QEMU pidfile
if [[ -f "/tmp/${VM_NAME}.pid" ]]; then
local pid
pid=$(cat "/tmp/${VM_NAME}.pid")
if kill -0 "$pid" 2>/dev/null; then
return 0
fi
fi
return 1
}
# Wait for boot and capture screenshot
@@ -138,8 +178,16 @@ capture_boot_screen() {
# Destroy VM and cleanup
destroy_vm() {
log_info "Destroying VM: $VM_NAME"
# Try virsh first
virsh destroy "$VM_NAME" 2>/dev/null || true
virsh undefine "$VM_NAME" 2>/dev/null || true
# Kill QEMU process if running
if [[ -f "/tmp/${VM_NAME}.pid" ]]; then
local pid
pid=$(cat "/tmp/${VM_NAME}.pid")
kill "$pid" 2>/dev/null || true
rm -f "/tmp/${VM_NAME}.pid"
fi
rm -f "$VM_DISK_PATH"
log_info "Cleanup complete"
}