From 82ad3a1b6d5b092dfc691f5122c38bf2298c0c1e Mon Sep 17 00:00:00 2001 From: reachableceo Date: Thu, 30 Jul 2026 13:03:15 -0500 Subject: [PATCH] feat: add QEMU software emulation fallback for VM testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VM creation failed with "Emulator does not support virt type 'kvm'" in environments without /dev/kvm (nested VMs, CI, containers). This makes ISO boot testing work everywhere by detecting KVM at runtime. Changes: - vm/template.xml: replace hardcoded type='kvm' and cpu mode='host-passthrough' with @DOMAIN_TYPE@ and @CPU_MODE@ placeholders - run.sh vm_create(): detect /dev/kvm at runtime, use KVM + host-passthrough when available, fall back to QEMU + qemu64 software emulation when not - tests: 6 new tests covering placeholder existence, KVM detection, and substitution logic This enables the ISO to be booted and serial output captured for verification even without hardware virtualization support. 💘 Generated with Crush Assisted-by: GLM-4.7 via Crush --- run.sh | 14 ++++++++++++++ tests/unit/secureboot_test.bats | 28 ++++++++++++++++++++++++++++ vm/template.xml | 4 ++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/run.sh b/run.sh index f17cc45..3a16ed8 100755 --- a/run.sh +++ b/run.sh @@ -199,12 +199,26 @@ vm_create() { log_warn "This is OK for live ISO testing but not for installation" fi + # Detect KVM acceleration; fall back to QEMU software emulation + local domain_type="qemu" + local cpu_mode="qemu64" + if [[ -e /dev/kvm ]]; then + domain_type="kvm" + cpu_mode="host-passthrough" + log_info "KVM acceleration enabled" + else + log_warn "KVM not available (/dev/kvm missing) - using QEMU software emulation" + log_warn "VM will be slower but functional for boot testing" + fi + # Create VM XML from template local vm_xml="/tmp/${VM_NAME}.xml" sed -e "s|@VM_NAME@|${VM_NAME}|g" \ -e "s|@VM_UUID@|${vm_uuid}|g" \ -e "s|@VM_RAM@|${VM_RAM}|g" \ -e "s|@VM_CPUS@|${VM_CPUS}|g" \ + -e "s|@DOMAIN_TYPE@|${domain_type}|g" \ + -e "s|@CPU_MODE@|${cpu_mode}|g" \ -e "s|@SECURE_BOOT@|${secure_boot}|g" \ -e "s|@UEFI_CODE@|${uefi_code}|g" \ -e "s|@UEFI_VARS_TEMPLATE@|${uefi_vars}|g" \ diff --git a/tests/unit/secureboot_test.bats b/tests/unit/secureboot_test.bats index 5573866..e592f9b 100644 --- a/tests/unit/secureboot_test.bats +++ b/tests/unit/secureboot_test.bats @@ -275,6 +275,34 @@ grep -q "vm_setup_swtpm" /workspace/run.sh } +# ============================================================================= +# VM KVM/QEMU Acceleration Fallback +# ============================================================================= + +@test "VM template has domain type placeholder" { + grep -q '@DOMAIN_TYPE@' /workspace/vm/template.xml +} + +@test "VM template has CPU mode placeholder" { + grep -q '@CPU_MODE@' /workspace/vm/template.xml +} + +@test "run.sh detects KVM availability via /dev/kvm" { + grep -q '/dev/kvm' /workspace/run.sh +} + +@test "run.sh substitutes domain type in VM XML" { + grep -q '@DOMAIN_TYPE@' /workspace/run.sh +} + +@test "run.sh substitutes CPU mode in VM XML" { + grep -q '@CPU_MODE@' /workspace/run.sh +} + +@test "run.sh defaults to QEMU emulation when KVM unavailable" { + grep -q 'qemu64' /workspace/run.sh +} + # ============================================================================= # Output Verification # ============================================================================= diff --git a/vm/template.xml b/vm/template.xml index 5f49468..692dd02 100644 --- a/vm/template.xml +++ b/vm/template.xml @@ -1,4 +1,4 @@ - + @VM_NAME@ @VM_UUID@ @VM_RAM@ @@ -16,7 +16,7 @@ - +