Files
spinifex/scripts/images/rds-postgres/rds-agent_initd_test.sh
T
Julian Sommer dafb001e06 feat: build the guest agent's engine from the image it is baked into
Define the composite engine interface and a newEngine() factory keyed by a per-engine layout table, so the agent's defaults, health probe and command implementation all come from the engine the image bakes rather than from PostgreSQL-shaped constants. Rename PGBin/PGData/PGUser to EngineBinDir/EngineDataDir/EngineUser, delete PGIsReady, and give engineProbe an injected state function with the pg_isready exit-code mapping moved into the PostgreSQL implementation.

setup.sh now stamps /etc/spinifex-rds/engine and buildAgentUserData emits RDS_ENGINE. The agent compares the two after registering and refuses to run when they disagree, reporting unhealthy before the bootstrap handoff is written so rds-init never unblocks and no datadir is touched.
2026-08-11 12:04:22 +10:00

49 lines
1.4 KiB
Bash

#!/bin/sh
set -eu
SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
CASE=$(mktemp -d)
trap 'rm -rf "${CASE}"' EXIT
source_time_handoff="${CASE}/source-time"
configured_handoff="${CASE}/configured"
mkdir -p "${configured_handoff}"
touch "${configured_handoff}/bootstrap.env"
{
printf 'RDS_HANDOFF_DIR=%s\n' "${configured_handoff}"
printf 'RDS_ENGINE=postgres\n'
} >"${CASE}/agent.env"
# Simulate OpenRC sourcing the service before start_pre loads agent.env.
export RDS_HANDOFF_DIR="${source_time_handoff}"
# shellcheck source=rds-agent.initd
. "${SCRIPT_DIR}/rds-agent.initd"
export AGENT_ENV="${CASE}/agent.env"
export handoff_timeout=0
EEND_STATUS=
ebegin() { :; }
einfo() { :; }
eend() { EEND_STATUS=$1; }
start_pre
start_post
if [ "${HANDOFF_ENV}" != "${configured_handoff}/bootstrap.env" ]; then
echo "FAIL: handoff path did not use RDS_HANDOFF_DIR from agent.env" >&2
exit 1
fi
if [ "${EEND_STATUS}" != "0" ]; then
echo "FAIL: post-start wait did not find the configured handoff" >&2
exit 1
fi
# The agent checks this against the engine its own image bakes. Left out of the
# export list it would read as no assertion at all, so a VM launched as the
# wrong engine would bootstrap instead of refusing.
if [ "${RDS_ENGINE:-}" != "postgres" ]; then
echo "FAIL: start_pre did not export RDS_ENGINE from agent.env" >&2
exit 1
fi
echo "rds-agent.initd: all tests passed"