From b87e6b790df06884c932349379c359ba83f9580f Mon Sep 17 00:00:00 2001 From: Stefan Saenger Date: Sun, 12 Jul 2026 17:52:40 +0200 Subject: [PATCH] feat: run-all-tests.sh auto-starts PG tunnel and telnet port-forward Check if the SSH tunnel to PostgreSQL (port 14322) and the kubectl port-forward for telnet (port 5582) are active before running the testsuite. Start them automatically if missing. Clean up the kubectl port-forward on exit if we started it. Part-of: --- run-all-tests.sh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/run-all-tests.sh b/run-all-tests.sh index 7bcb847..694b93e 100755 --- a/run-all-tests.sh +++ b/run-all-tests.sh @@ -8,8 +8,55 @@ # Tests that need compose-specific infrastructure (docker exec, MOCK_URL, # low smacks_hibernation_time) will skip automatically. # +# Prerequisites: +# 1. SSH tunnel to PostgreSQL: +# ssh -p 60024 developer@148.251.101.234 -f -N -M -S /tmp/vncddb.sock -L 14322:127.0.0.1:5432 +# 2. kubectl port-forward for telnet: +# kubectl port-forward services/telnet 5582:5582 -n prosody +# set -euo pipefail +# --------------------------------------------------------------------------- +# 0. Verify prerequisites: SSH tunnel (PG) and kubectl port-forward (telnet) +# --------------------------------------------------------------------------- +SSH_SOCK=/tmp/vncddb.sock +PG_PORT=14322 +TELNET_PORT=5582 + +check_pg_tunnel() { + if ! ss -tlnp 2>/dev/null | grep -q ":${PG_PORT} "; then + echo ">>> PostgreSQL tunnel not active — starting SSH tunnel" + ssh -p 60024 developer@148.251.101.234 -f -N -M -S "$SSH_SOCK" \ + -L ${PG_PORT}:127.0.0.1:5432 + sleep 1 + if ! ss -tlnp 2>/dev/null | grep -q ":${PG_PORT} "; then + echo "ERROR: SSH tunnel to PostgreSQL failed to start" >&2 + exit 1 + fi + fi + echo ">>> PostgreSQL tunnel OK (port ${PG_PORT})" +} + +check_telnet_pf() { + if ! ss -tlnp 2>/dev/null | grep -q ":${TELNET_PORT} "; then + echo ">>> Telnet port-forward not active — starting kubectl port-forward" + kubectl port-forward services/telnet ${TELNET_PORT}:5582 -n prosody & + KUBECTL_PF_PID=$! + sleep 2 + if ! ss -tlnp 2>/dev/null | grep -q ":${TELNET_PORT} "; then + echo "ERROR: kubectl port-forward for telnet failed to start" >&2 + exit 1 + fi + fi + echo ">>> Telnet port-forward OK (port ${TELNET_PORT})" +} + +check_pg_tunnel +check_telnet_pf + +# --------------------------------------------------------------------------- +# 1. Test env vars +# --------------------------------------------------------------------------- export XMPP_HOST=xmpp.microlab.zimbra-vnc.de export XMPP_PORT=30522 export XMPP_JID=lisa.porter@microlab.zimbra-vnc.de @@ -31,4 +78,15 @@ export PG_DB=prosody export PG_USER=prosody export PG_PASSWORD=eS5Gi7ahzo3chaiXiel0ief +# --------------------------------------------------------------------------- +# 2. Run the testsuite +# --------------------------------------------------------------------------- pytest tests/ -v -c tests/pytest.ini + +# --------------------------------------------------------------------------- +# 3. Cleanup kubectl port-forward if we started it +# --------------------------------------------------------------------------- +if [[ -n "${KUBECTL_PF_PID:-}" ]]; then + echo ">>> stopping kubectl port-forward (PID ${KUBECTL_PF_PID})" + kill "$KUBECTL_PF_PID" 2>/dev/null || true +fi