Files
pxe-server/tests/vm/build-image.sh
cproudlock 6dc9761e67 build-usb: --site-vars puts the per-site vars on CIDATA; harness pins the VM NIC MACs
tests/vm/build-image.sh writes site-vars.yml with pxe_nic_mac (isolated
network NIC) and corp_nic_mac (NAT NIC) and passes it to build-usb.sh.
2026-10-15 08:56:45 -04:00

69 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Build the installer USB as a disk image FILE with build-usb.sh image mode,
# then upload it into the libvirt 'default' pool as volume pxetest-usb.img.
#
# Usage: tests/vm/build-image.sh [--with-enrollment] [--with-boot-tools] [--size SIZE]
# Default skips enrollment/, bios-staging/, drivers-staging/ and boot-tools/
# to keep the image small; SIZE defaults to "auto".
# Env: PXETEST_PAYLOAD_ROOT (where offline-packages/, boot-files/... live)
source "$(dirname "$0")/common.sh"
SIZE=auto
SKIPS=(--skip-enrollment --skip-bios --skip-drivers --skip-boot-tools)
while [ $# -gt 0 ]; do
case "$1" in
--with-enrollment) SKIPS=("${SKIPS[@]/--skip-enrollment}"); shift ;;
--with-boot-tools) SKIPS=("${SKIPS[@]/--skip-boot-tools}"); shift ;;
--size) SIZE="$2"; shift 2 ;;
*) die "unknown option $1" ;;
esac
done
ARGS=()
for s in "${SKIPS[@]}"; do [ -n "$s" ] && ARGS+=("$s"); done
[ -f "$UBUNTU_ISO" ] || die "no ISO at $UBUNTU_ISO; run tests/vm/fetch-iso.sh"
ensure_image_tools
# Report what the payload root has and lacks (do not invent content).
log "payload root: $PXETEST_PAYLOAD_ROOT"
for d in offline-packages pip-wheels boot-files boot-tools enrollment bios-staging drivers-staging; do
if [ -d "$PXETEST_PAYLOAD_ROOT/$d" ]; then
printf ' %-17s %s\n' "$d" "$(du -shL "$PXETEST_PAYLOAD_ROOT/$d" 2>/dev/null | cut -f1)"
else
printf ' %-17s MISSING\n' "$d"
fi
done
for f in ipxe-shimx64.efi ipxeboot.tar.gz wimboot boot.wim BCD boot.sdi bootx64.efi undionly.kpxe; do
[ -f "$PXETEST_PAYLOAD_ROOT/boot-files/$f" ] || log " boot-files/$f MISSING"
done
if [ -e "$USB_IMAGE" ] && [ ! -f "$USB_IMAGE" ]; then
die "$USB_IMAGE is not a regular file"
fi
# Site vars for the VM "site": pin the NICs by the fixed MACs from common.sh.
SITE_VARS="$PXETEST_CACHE/site-vars.yml"
cat >"$SITE_VARS" <<YML
---
# Generated by tests/vm/build-image.sh for the pxetest VMs.
pxe_nic_mac: "$SERVER_IMAGING_MAC" # pxetest-imaging (isolated)
corp_nic_mac: "$SERVER_GE_MAC" # libvirt default NAT ("GE/corp")
YML
log "site vars: pxe_nic_mac=$SERVER_IMAGING_MAC corp_nic_mac=$SERVER_GE_MAC"
"$REPO_ROOT/scripts/build-usb.sh" --yes --payload-root "$PXETEST_PAYLOAD_ROOT" \
--site-vars "$SITE_VARS" \
"${ARGS[@]}" --image "$USB_IMAGE" "$SIZE" "$UBUNTU_ISO"
BYTES=$(stat -c%s "$USB_IMAGE")
if dom_exists "$SERVER_VM" && [ "$(dom_state "$SERVER_VM")" != "shut off" ]; then
die "$SERVER_VM is running; stop it before replacing its USB volume"
fi
if vol_exists "$USB_VOL"; then
virsh vol-delete --pool "$POOL" "$USB_VOL" >/dev/null
fi
log "uploading $USB_IMAGE ($((BYTES / 1048576)) MiB) to pool $POOL as $USB_VOL"
virsh vol-create-as "$POOL" "$USB_VOL" "$BYTES" --format raw >/dev/null
virsh vol-upload --pool "$POOL" --sparse "$USB_VOL" "$USB_IMAGE"
log "done"