aboutsummaryrefslogtreecommitdiff
path: root/scripts/testing/lib/vm-utils.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/testing/lib/vm-utils.sh')
-rwxr-xr-xscripts/testing/lib/vm-utils.sh24
1 files changed, 21 insertions, 3 deletions
diff --git a/scripts/testing/lib/vm-utils.sh b/scripts/testing/lib/vm-utils.sh
index 47bd391..a8736a3 100755
--- a/scripts/testing/lib/vm-utils.sh
+++ b/scripts/testing/lib/vm-utils.sh
@@ -72,6 +72,11 @@ check_ovmf() {
info "Install with: sudo pacman -S edk2-ovmf"
return 1
fi
+ if [ ! -f "$OVMF_VARS_TEMPLATE" ]; then
+ error "OVMF vars template not found: $OVMF_VARS_TEMPLATE"
+ info "Install with: sudo pacman -S edk2-ovmf"
+ return 1
+ fi
return 0
}
@@ -132,6 +137,15 @@ start_qemu() {
local iso_path="${3:-}"
local display="${4:-none}"
+ if [ -z "$disk" ] || [ ! -f "$disk" ]; then
+ error "Disk image not found: ${disk:-<unset>}"
+ return 1
+ fi
+ if [ "$mode" = "iso" ] && { [ -z "$iso_path" ] || [ ! -f "$iso_path" ]; }; then
+ error "ISO not found: ${iso_path:-<unset>}"
+ return 1
+ fi
+
# Stop any existing instance
stop_qemu 2>/dev/null || true
@@ -223,7 +237,7 @@ stop_qemu() {
# Wait for graceful shutdown
local elapsed=0
- while [ $elapsed -lt $timeout ]; do
+ while [ "$elapsed" -lt "$timeout" ]; do
if ! vm_is_running; then
success "VM stopped gracefully"
_cleanup_qemu_files
@@ -319,7 +333,11 @@ list_snapshots() {
snapshot_exists() {
local disk="${1:-$DISK_PATH}"
local snapshot_name="${2:-clean-install}"
- qemu-img snapshot -l "$disk" 2>/dev/null | grep -q "$snapshot_name"
+ # Match on the TAG column (field 2) so a name appearing inside a timestamp
+ # or filename elsewhere in the output can't false-positive the check.
+ qemu-img snapshot -l "$disk" 2>/dev/null \
+ | awk 'NR > 2 { print $2 }' \
+ | grep -Fxq "$snapshot_name"
}
# ─── SSH Operations ───────────────────────────────────────────────────
@@ -331,7 +349,7 @@ wait_for_ssh() {
local elapsed=0
progress "Waiting for SSH on localhost:$SSH_PORT..."
- while [ $elapsed -lt $timeout ]; do
+ while [ "$elapsed" -lt "$timeout" ]; do
if sshpass -p "$password" ssh $SSH_OPTS -p "$SSH_PORT" root@localhost true 2>/dev/null; then
success "SSH is available"
return 0