#!/bin/sh

set -e

# With both conffiles in place, the user-owned values must flow into
# the script: OPENSTACK_RELEASE comes from openstack_release of the
# -local file, while the mirror values are derived by the stock file
# from REPO_TOKEN_DEBIAN_MIRROR_HOST of the -local file. The script is
# expected to fail after emitting the amphora-build call, as the
# sandbox holds no amphora image: what matters here is that the
# values reached it.
. ./lib.sh
SANDBOX=$(mktemp -d)
trap 'rm -rf ${SANDBOX}' EXIT
SCRIPT=$(setup_sandbox utils/usr/bin/oci-poc-provision-octavia-image "${SANDBOX}")
write_local_conf "${SANDBOX}" hibiscus

PATH="${SANDBOX}/bin:$PATH" sh "${SCRIPT}" >"${SANDBOX}/out.txt" 2>"${SANDBOX}/err.txt" || true

if ! grep -q "AMPHORA-BUILD-CALLED release=trixie mirror=http://deb.debian.org/debian security=http://deb.debian.org/debian-security OPENSTACK_RELEASE=hibiscus" "${SANDBOX}/out.txt" ; then
	echo "the -local values didn't flow through the stock derivations"
	cat "${SANDBOX}/out.txt" "${SANDBOX}/err.txt"
	exit 1
fi
exit 0
