Add reproducible Python baseline and Guacamole graphics presets

This commit is contained in:
cabbage committed 2026-10-08 06:55:14 +00:00
1 parent 620f882fe2
commit 98a474696b
8 files changed
+380 -35

No files matched your search

+103 -8
View File
@@ -12,7 +12,7 @@ repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)
usage() {
cat <<'EOF'
usage: scripts/windows/test-host ACTION [--run-id ID] [--bundle DIRECTORY] [--endpoint HOST:PORT] [--fail-contexts LIST]
usage: scripts/windows/test-host ACTION [--run-id ID] [--bundle DIRECTORY] [--endpoint HOST:PORT] [--fail-contexts LIST] [--snapshot-name NAME]
Actions:
status read-only VM/snapshot identity and state check
@@ -27,6 +27,9 @@ Actions:
stop stop RVBox through SCM and request a graceful guest shutdown
reset stop the guest if necessary, restore the declared baseline, and leave it off
recover read-only fixture/run-state check for a stopped-resumable run
provision-python install/verify pinned Python, pip, and venv in the clean leased VM
capture-python-baseline verify the clean Python fixture, shut it down, take a
new snapshot (--snapshot-name NAME), and release the run lease
Optional environment:
The documented Helium fixture identity and password-file path are defaults.
@@ -37,6 +40,7 @@ Optional environment:
(default Administrator and the documented fixture password file)
RVBOX_TEST_HOST_STAGE_ROOT (default /home/cabbage/.local/state/rvbox-test-runs)
RVBOX_TEST_RUN_ROOT (default .test-runs/windows-vm)
RVBOX_TEST_PYTHON_DOWNLOAD_PROXY (default empty/direct; optional host SOCKS5)
RVBOX_TEST_ACCEL_HTTP_URL, RVBOX_TEST_ACCEL_HTTP_AUTH,
RVBOX_TEST_ACCEL_HTTP_PUBLISH_DIR, RVBOX_TEST_ACCEL_SOCKS5
(documented accelerated HTTP stage route; empty URL disables it)
@@ -77,18 +81,26 @@ run_id=
bundle=
endpoint=
fail_contexts=
snapshot_name=
while [ "$#" -gt 0 ]; do
case $1 in
--run-id) [ "$#" -ge 2 ] || fail "--run-id needs a value"; run_id=$2; shift 2 ;;
--bundle) [ "$#" -ge 2 ] || fail "--bundle needs a value"; bundle=$2; shift 2 ;;
--endpoint) [ "$#" -ge 2 ] || fail "--endpoint needs a value"; endpoint=$2; shift 2 ;;
--fail-contexts) [ "$#" -ge 2 ] || fail "--fail-contexts needs a value"; fail_contexts=$2; shift 2 ;;
--snapshot-name) [ "$#" -ge 2 ] || fail "--snapshot-name needs a value"; snapshot_name=$2; shift 2 ;;
--help|-h) usage; exit 0 ;;
*) fail "unknown argument $1" ;;
esac
done
case $action in status|prepare|stage|install|run|logoff|collect|inspect|logs|stop|reset|recover) ;; *) usage >&2; fail "unknown action $action" ;; esac
case $action in status|prepare|stage|install|run|logoff|collect|inspect|logs|stop|reset|recover|provision-python|capture-python-baseline) ;; *) usage >&2; fail "unknown action $action" ;; esac
if [ "$action" = capture-python-baseline ]; then
[ -n "$snapshot_name" ] || fail "capture-python-baseline requires --snapshot-name"
safe_id "$snapshot_name"
else
[ -z "$snapshot_name" ] || fail "--snapshot-name is valid only with capture-python-baseline"
fi
if [ "$action" != status ]; then
[ -n "$run_id" ] || fail "$action requires --run-id"
safe_id "$run_id"
@@ -109,12 +121,17 @@ if [ -n "$fail_contexts" ]; then safe_word fail_contexts "$fail_contexts"; fi
: "${RVBOX_TEST_VBOX_HOST:=helium-remote}"
: "${RVBOX_TEST_VBOX_VM:=rvbox-win10-test}"
: "${RVBOX_TEST_VBOX_VM_UUID:=6cdc114f-71e5-4167-a394-e922e14e6f5c}"
: "${RVBOX_TEST_VBOX_SNAPSHOT:=baseline-clean-administrator}"
: "${RVBOX_TEST_VBOX_SNAPSHOT_UUID:=ba5ce5f1-77e3-44b0-8d91-534becce27ff}"
: "${RVBOX_TEST_VBOX_SNAPSHOT:=baseline-clean-python-ready}"
: "${RVBOX_TEST_VBOX_SNAPSHOT_UUID:=dfadee95-156f-43ee-bdab-a10a44be4070}"
: "${RVBOX_TEST_GUEST_USER:=rvboxtest}"
: "${RVBOX_TEST_GUEST_PASSWORD_FILE:=/home/cabbage/.local/share/rvbox-secrets/rvbox-win10-test.password}"
: "${RVBOX_TEST_PROVISIONER_USER:=Administrator}"
: "${RVBOX_TEST_PROVISIONER_PASSWORD_FILE:=$RVBOX_TEST_GUEST_PASSWORD_FILE}"
: "${RVBOX_TEST_PYTHON_DOWNLOAD_PROXY:=}"
if [ -n "$RVBOX_TEST_PYTHON_DOWNLOAD_PROXY" ]; then
safe_word RVBOX_TEST_PYTHON_DOWNLOAD_PROXY "$RVBOX_TEST_PYTHON_DOWNLOAD_PROXY"
case $RVBOX_TEST_PYTHON_DOWNLOAD_PROXY in socks5://*|socks5h://*) ;; *) fail "Python download proxy must use socks5" ;; esac
fi
: "${RVBOX_TEST_ACCEL_HTTP_URL:=http://x1.xcel.me:9124}"
: "${RVBOX_TEST_ACCEL_HTTP_AUTH:=x1:x1}"
: "${RVBOX_TEST_ACCEL_HTTP_PUBLISH_DIR:=/home/ubuntu/Downloads}"
@@ -170,7 +187,7 @@ remote() {
# retry. Lifecycle transitions remain single-attempt: their caller must
# inspect/recover rather than risk a duplicate reset, shutdown, or logoff.
case $remote_action in
status|recover|prepare-stage|stage|stage-create-root|stage-copy-exe|stage-copy-config|stage-copy-ca|collect|inspect|logs|install|run)
status|recover|prepare-stage|provision-python-stage|stage|stage-create-root|stage-copy-exe|stage-copy-config|stage-copy-ca|collect|inspect|logs|install|run)
retry_limit=4
;;
esac
@@ -179,7 +196,7 @@ remote() {
retry_attempt=1
while [ "$retry_attempt" -le "$retry_limit" ]; do
if ssh -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=10 -o ServerAliveCountMax=2 "$RVBOX_TEST_VBOX_HOST" \
"sh -s -- '$1' '$RVBOX_TEST_VBOX_VM' '$RVBOX_TEST_VBOX_VM_UUID' '$RVBOX_TEST_VBOX_SNAPSHOT' '$RVBOX_TEST_VBOX_SNAPSHOT_UUID' '$RVBOX_TEST_GUEST_USER' '$RVBOX_TEST_GUEST_PASSWORD_FILE' '$host_stage' '$guest_root' '$remote_endpoint' '$provisioner_user' '$provisioner_password_file' '$remote_fail_contexts'" <<'REMOTE'
"sh -s -- '$1' '$RVBOX_TEST_VBOX_VM' '$RVBOX_TEST_VBOX_VM_UUID' '$RVBOX_TEST_VBOX_SNAPSHOT' '$RVBOX_TEST_VBOX_SNAPSHOT_UUID' '$RVBOX_TEST_GUEST_USER' '$RVBOX_TEST_GUEST_PASSWORD_FILE' '$host_stage' '$guest_root' '$remote_endpoint' '$provisioner_user' '$provisioner_password_file' '$remote_fail_contexts' '$snapshot_name' '$RVBOX_TEST_PYTHON_DOWNLOAD_PROXY'" <<'REMOTE'
set -eu
action=$1
@@ -196,6 +213,8 @@ endpoint=$1
provisioner_user=$2
provisioner_password_file=$3
fail_contexts=$4
snapshot_name=$5
python_download_proxy=$6
[ "$endpoint" = - ] && endpoint=
[ "$fail_contexts" = - ] && fail_contexts=
@@ -304,7 +323,7 @@ assert_provisioner_absent() {
wait_guest_additions() {
attempt=0
while [ "$attempt" -lt 60 ]; do
while [ "$attempt" -lt 240 ]; do
properties=$(VBoxManage guestproperty enumerate "$vm" 2>/dev/null || true)
if printf '%s\n' "$properties" | grep -q '/VirtualBox/GuestAdd/Version' && \
printf '%s\n' "$properties" | grep -q '/VirtualBox/GuestInfo/OS/Release'; then
@@ -313,7 +332,7 @@ wait_guest_additions() {
attempt=$((attempt + 1))
sleep 1
done
fail "Guest Additions did not publish version and Windows OS-release properties"
fail "Guest Additions did not publish version and Windows OS-release properties within 240 seconds"
}
configure_display_keepalive() {
@@ -390,6 +409,77 @@ case "$action" in
guest_run --exe 'C:\Windows\System32\cmd.exe' --wait-stdout --wait-stderr --unquoted-args -- \
/d /s /c 'whoami /groups & query user & echo RVBOX_GUEST_OK' >/dev/null
;;
provision-python-stage)
assert_identity
require_lease
[ "$(state)" = running ] || fail "Python provisioning requires a running prepared VM"
assert_clean_guest
assert_provisioner_elevated
install -d -m 700 "$host_stage"
provisioner_run --exe 'C:\Windows\System32\cmd.exe' --wait-stdout --wait-stderr --unquoted-args -- \
/d /s /c 'mkdir C:\ProgramData\RVBoxFixture\python >NUL 2>&1 & if exist C:\ProgramData\RVBoxFixture\python echo RVBOX_GUEST_OK' || fail "Python staging directory is unavailable"
;;
provision-python)
assert_identity
require_lease
[ "$(state)" = running ] || fail "Python provisioning requires a running prepared VM"
assert_clean_guest
assert_provisioner_elevated
# Pin must match provision-python.ps1. Default to direct HTTPS on
# Helium; only use its metered proxy when explicitly configured.
# Retain partial bytes for explicit resumable retries.
python_version=3.13.16
python_digest=fb4f9f5d438b2396da0086dc70b935c530cb578e37adc6d354f7ad2037fee83b
python_installer=$host_stage/python-$python_version-amd64.exe
if [ ! -f "$python_installer" ] || [ "$(sha256sum "$python_installer" | awk '{print $1}')" != "$python_digest" ]; then
set --
if [ -n "$python_download_proxy" ]; then set -- --proxy "$python_download_proxy"; fi
curl --fail --silent --show-error --continue-at - --retry 2 --retry-all-errors \
--connect-timeout 15 --max-time 120 "$@" --output "$python_installer.new" \
"https://www.python.org/ftp/python/$python_version/python-$python_version-amd64.exe"
[ "$(sha256sum "$python_installer.new" | awk '{print $1}')" = "$python_digest" ] || fail "Python installer digest mismatch; inspect retained host-stage bytes"
mv "$python_installer.new" "$python_installer"
fi
VBoxManage guestcontrol "$vm" --username "$provisioner_user" --passwordfile "$provisioner_password_file" \
copyto "$host_stage/provision-python.ps1" 'C:\ProgramData\RVBoxFixture\provision-python.ps1' </dev/null
VBoxManage guestcontrol "$vm" --username "$provisioner_user" --passwordfile "$provisioner_password_file" \
copyto "$python_installer" 'C:\ProgramData\RVBoxFixture\python\python-3.13.16-amd64.exe' </dev/null
provisioner_run --exe 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' --wait-stdout --wait-stderr --timeout 1200000 --unquoted-args -- \
-NoProfile -NonInteractive -ExecutionPolicy Bypass -File 'C:\ProgramData\RVBoxFixture\provision-python.ps1' -Mode Install || fail "Python install/verification failed"
guest_run --exe 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' --wait-stdout --wait-stderr --timeout 120000 --unquoted-args -- \
-NoProfile -NonInteractive -ExecutionPolicy Bypass -File 'C:\ProgramData\RVBoxFixture\provision-python.ps1' -Mode Verify || fail "Python unavailable to ordinary fixture user"
step provision-python-verified
;;
capture-python-baseline)
assert_identity
require_lease
[ "$(state)" = running ] || fail "baseline capture requires a running prepared VM"
# Never overwrite or delete a retained baseline. The new name is a
# constrained argument, and snapshot capture is never blindly retried.
if VBoxManage snapshot "$vm" list --machinereadable | grep -Fq "=\"$snapshot_name\""; then
fail "snapshot name already exists: $snapshot_name"
fi
assert_clean_guest
guest_run --exe 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' --wait-stdout --wait-stderr --timeout 120000 --unquoted-args -- \
-NoProfile -NonInteractive -ExecutionPolicy Bypass -File 'C:\ProgramData\RVBoxFixture\provision-python.ps1' -Mode VerifyClean || fail "clean Python baseline verification failed"
assert_provisioner_absent
provisioner_run --exe 'C:\Windows\System32\cmd.exe' --wait-stdout --wait-stderr --unquoted-args -- \
/d /s /c 'rmdir /s /q C:\ProgramData\RVBoxFixture && echo RVBOX_GUEST_OK' >/dev/null || fail "could not remove Python provisioning files"
VBoxManage controlvm "$vm" acpipowerbutton >/dev/null
attempt=0
while [ "$attempt" -lt 90 ]; do
[ "$(state)" = poweroff ] && break
attempt=$((attempt + 1))
sleep 1
done
[ "$(state)" = poweroff ] || fail "VM did not shut down cleanly; baseline was not captured"
VBoxManage snapshot "$vm" take "$snapshot_name" --description 'Clean RVBox fixture; full-token Administrator; Python 3.13.16 amd64, pip and venv; no RVBox installation' >/dev/null
new_snapshot_uuid=$(vm_field CurrentSnapshotUUID)
[ "$(vm_field CurrentSnapshotName)" = "$snapshot_name" ] && [ -n "$new_snapshot_uuid" ] || fail "new snapshot identity could not be verified"
release_lease
step capture-python-baseline-complete
printf 'python_baseline=%s uuid=%s state=poweroff\n' "$snapshot_name" "$new_snapshot_uuid"
;;
stage)
assert_identity
require_lease
@@ -671,6 +761,11 @@ case $action in
remote prepare
printf 'prepared vm=%s stage=%s\n' "$RVBOX_TEST_VBOX_VM" "$host_stage"
;;
provision-python)
remote provision-python-stage
copy_stage_file "$repo_root/scripts/windows/provision-python.ps1" provision-python.ps1
remote provision-python
;;
stage)
printf 'stage: verify prepared VM and lease\n'
remote prepare-stage