5546d34dddbb

make golden-image harness work end-to-end: env-var arg passing, sudo-i for nixos autologin, /dev/vda1 mount, marker-driven serial; golden builds and boots disposably

time
2026-05-29 14:49 UTC · 4 months ago
machine
koh2
parent
a7db23cbf680
3 files test/vm/boot-overlay.sh+13 −13test/vm/build-golden.sh+36 −25test/vm/install.sh+7 −1
test/vm/boot-overlay.sh+13 −13
@@ -25,12 +25,15 @@2525 qemu-img create -f qcow2 -b "$(cd "$(dirname "$GOLDEN")" && pwd)/$(basename "$GOLDEN")" -F qcow2 "$overlay" >/dev/null2626 echo "throwaway overlay: $overlay  (backing: $GOLDEN)"2727 28+export BO_OVERLAY="$overlay" BO_MEM="$MEM_MB" BO_SMP="$SMP" \29+       BO_TIMEOUT="$BOOT_TIMEOUT" BO_CMD="$CMD"30+2831 expect -c '29-  set timeout [lindex $argv 3]30-  set overlay [lindex $argv 0]31-  set mem     [lindex $argv 1]32-  set smp     [lindex $argv 2]33-  set cmd     [lindex $argv 4]32+  set timeout $env(BO_TIMEOUT)33+  set overlay $env(BO_OVERLAY)34+  set mem     $env(BO_MEM)35+  set smp     $env(BO_SMP)36+  set cmd     $env(BO_CMD)3437 3538   spawn qemu-system-x86_64 \3639     -machine q35 -accel tcg -cpu max -smp $smp -m $mem \@@ -39,15 +42,12 @@3942     -nographic4043 4144   expect {42-    timeout { puts "\n!! no login on serial"; exit 2 }43-    -re {\[root@test-primary[^\]]*\]#} {}44-    -re {login:} { send "root\r"; exp_continue }45+    timeout { puts "\n!! no autologin on serial"; exit 2 }46+    "automatic login" {}4547   }46-  send "\r"47-  expect -re {\[root@test-primary[^\]]*\]#}48-48+  sleep 64949   send "echo NINA_SMOKE_BEGIN\r"50-  expect "NINA_SMOKE_BEGIN"50+  expect { timeout { puts "\n!! shell not ready"; exit 3 } "NINA_SMOKE_BEGIN" {} }5151   send "$cmd\r"5252   send "echo NINA_SMOKE_END_RC=\$?\r"5353   expect {@@ -57,6 +57,6 @@5757   send "poweroff\r"5858   set timeout 1205959   expect eof60-' "$overlay" "$MEM_MB" "$SMP" "$BOOT_TIMEOUT" "$CMD"60+'6161 6262 echo "=== overlay discarded; golden image unchanged ==="

view file

test/vm/build-golden.sh+36 −25
@@ -32,54 +32,65 @@3232 3333 # Fresh blank disk for the install target.3434 qemu-img create -f qcow2 "$OUT" "${DISK_GB}G" >/dev/null35+36+# Direct kernel boot: the ISO's own cmdline omits console=ttyS0 (kernel + getty37+# land on VGA, invisible under -nographic). Extract the kernel/initrd and the38+# installer's APPEND line, then add a serial console so the install is drivable.39+bsdtar -xOf "$ISO" boot/bzImage > "$work/bzImage"40+bsdtar -xOf "$ISO" boot/initrd  > "$work/initrd"41+APPEND_BASE="$(bsdtar -xOf "$ISO" isolinux/isolinux.cfg 2>/dev/null \42+  | awk '/^[[:space:]]*APPEND/ {sub(/^[[:space:]]*APPEND[[:space:]]*/,""); print; exit}')"43+[ -n "$APPEND_BASE" ] || { echo "could not read installer APPEND line" >&2; exit 1; }44+APPEND="$APPEND_BASE console=ttyS0,115200"3545 echo "golden target: $OUT (${DISK_GB}G)  ·  seed: $SEED_ISO"46+echo "kernel append: $APPEND"3647 48+# Pass values to expect via the environment ($env(...)); `expect -c` does not49+# populate $argv from trailing args.50+export GI_ISO="$ISO" GI_SEED="$SEED_ISO" GI_OUT="$OUT" GI_MEM="$MEM_MB" \51+       GI_SMP="$SMP" GI_TIMEOUT="$INSTALL_TIMEOUT" \52+       GI_KERNEL="$work/bzImage" GI_INITRD="$work/initrd" GI_APPEND="$APPEND"53+3754 expect -c '3855   set timeout 60039-  set iso       [lindex $argv 0]40-  set seed_iso  [lindex $argv 1]41-  set out       [lindex $argv 2]42-  set mem       [lindex $argv 3]43-  set smp       [lindex $argv 4]44-  set install_timeout [lindex $argv 5]56+  set iso       $env(GI_ISO)57+  set seed_iso  $env(GI_SEED)58+  set out       $env(GI_OUT)59+  set mem       $env(GI_MEM)60+  set smp       $env(GI_SMP)61+  set install_timeout $env(GI_TIMEOUT)62+  set kernel    $env(GI_KERNEL)63+  set initrd    $env(GI_INITRD)64+  set append    $env(GI_APPEND)4565 4666   spawn qemu-system-x86_64 \4767     -machine q35 -accel tcg -cpu max -smp $smp -m $mem \68+    -kernel $kernel -initrd $initrd -append $append \4869     -drive file=$out,if=virtio,format=qcow2 \4970     -drive file=$iso,media=cdrom,readonly=on \5071     -drive file=$seed_iso,media=cdrom,readonly=on \51-    -boot d \5272     -netdev user,id=n0 -device virtio-net-pci,netdev=n0 \5373     -nographic5474 55-  # Reach an installer root shell (autologin on the ISO serial console).5675   expect {57-    timeout { puts "\n!! no shell prompt from installer"; exit 2 }58-    -re {\[root@nixos[^\]]*\]#} {}59-    -re {nixos@nixos} { send "sudo -i\r"; exp_continue }60-    -re {login:} { send "root\r"; exp_continue }76+    timeout { puts "\n!! installer never reached autologin"; exit 2 }77+    "automatic login" {}6178   }62-  send "\r"63-  expect -re {\[root@nixos[^\]]*\]#}79+  sleep 580+  send "sudo -i\r"81+  sleep 282+  send "mkdir -p /mnt-seed && mount /dev/sr1 /mnt-seed && bash /mnt-seed/install.sh\r"6483 65-  # Mount seed media and run the installer script.66-  send "mkdir -p /mnt-seed && mount /dev/sr1 /mnt-seed && echo NINA_SEED_OK\r"67-  expect {68-    timeout { puts "\n!! seed mount failed"; exit 3 }69-    "NINA_SEED_OK" {}70-  }71-  send "bash /mnt-seed/install.sh\r"72-7384   set timeout $install_timeout7485   expect {75-    timeout { puts "\n!! install timed out"; exit 4 }86+    timeout { puts "\n!! install never finished"; exit 4 }87+    "NINA_INSTALL_FAIL" { puts "\n!! install.sh reported failure"; exit 5 }7688     "NINA_INSTALL_DONE" {}7789     "NINA_INSTALL_START" { exp_continue }7890   }79-  # qemu exits when the guest powers off.8091   set timeout 1208192   expect eof82-' "$ISO" "$SEED_ISO" "$OUT" "$MEM_MB" "$SMP" "$INSTALL_TIMEOUT"93+'8394 8495 echo "=== golden image built: $OUT ==="8596 qemu-img info "$OUT" | sed 's/^/  /'

view file

test/vm/install.sh+7 −1
@@ -2,6 +2,8 @@22 # Runs INSIDE the NixOS minimal installer (over serial) to lay down the golden33 # system onto /dev/vda from the seed media. Driven by build-golden.sh.44 set -euo pipefail5+# Fast-fail signal for the driver instead of hanging until its timeout.6+trap 'echo "=== NINA_INSTALL_FAIL ==="; sync; sleep 2; poweroff -f' ERR57 68 SEED_DIR="$(cd "$(dirname "$0")" && pwd)"79 echo "=== NINA_INSTALL_START ==="@@ -10,9 +12,13 @@1012 parted -s /dev/vda mklabel msdos1113 parted -s /dev/vda mkpart primary ext4 1MiB 100%1214 parted -s /dev/vda set 1 boot on15+udevadm settle || true1316 mkfs.ext4 -F -L nixos /dev/vda117+udevadm settle || true1418 15-mount /dev/disk/by-label/nixos /mnt19+# Mount the partition device directly — the /dev/disk/by-label symlink may not20+# be populated by udev yet immediately after mkfs.21+mount /dev/vda1 /mnt1622 1723 # Generate hardware-configuration.nix for this disk, then drop in our config.1824 nixos-generate-config --root /mnt

view file