From 305e6db0b2c2244afdc281f6c1b9b0a4db7de929 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Wed, 18 Mar 2026 16:20:47 +0500 Subject: [PATCH] Added destroy-infra.bash --- test/infra/control/destroy-infras.bash | 78 ++++++++++++++++++++++++++ test/scripts/bin/proxysql-tester.py | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 test/infra/control/destroy-infras.bash diff --git a/test/infra/control/destroy-infras.bash b/test/infra/control/destroy-infras.bash new file mode 100755 index 000000000..d6f9c96ef --- /dev/null +++ b/test/infra/control/destroy-infras.bash @@ -0,0 +1,78 @@ +#!/bin/bash +set -e +set -o pipefail + +# Derive Workspace relative to script +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)" +export WORKSPACE="${REPO_ROOT}" + +# Default INFRA_ID if not provided +export INFRA_ID="${INFRA_ID:-dev-$USER}" + +if [ -z "${TAP_GROUP}" ]; then + echo "ERROR: TAP_GROUP is not set." + echo "Usage: TAP_GROUP= ./destroy-infras.bash" + echo "Example: TAP_GROUP=mysql84-g1 ./destroy-infras.bash" + exit 1 +fi + +# 1. Determine Base Group (strip subgroup suffix) +BASE_GROUP=$(echo "${TAP_GROUP}" | sed -E "s/[-_]g[0-9]+.*//") +LST_PATH="" + +if [ -f "${WORKSPACE}/test/tap/groups/${TAP_GROUP}/infras.lst" ]; then + LST_PATH="${WORKSPACE}/test/tap/groups/${TAP_GROUP}/infras.lst" +elif [ -f "${WORKSPACE}/test/tap/groups/${BASE_GROUP}/infras.lst" ]; then + LST_PATH="${WORKSPACE}/test/tap/groups/${BASE_GROUP}/infras.lst" +fi + +INFRAS="" +if [ -n "${LST_PATH}" ]; then + INFRAS=$(cat "${LST_PATH}") + echo ">>> Found infrastructure requirements for group '${TAP_GROUP}' in '${LST_PATH}'" +else + if [ -n "${INFRA_TYPE}" ]; then + echo ">>> No infras.lst found. Using fallback INFRA_TYPE: ${INFRA_TYPE}" + INFRAS="${INFRA_TYPE}" + else + echo "ERROR: Could not find infrastructure requirements (infras.lst) for group '${TAP_GROUP}' or '${BASE_GROUP}'." + echo "Please ensure test/tap/groups/${BASE_GROUP}/infras.lst exists." + exit 1 + fi +fi + +# 2. Ensure Docker Compose helper is available +COMPOSE_CMD="docker compose" +if ! $COMPOSE_CMD version &>/dev/null; then COMPOSE_CMD="docker-compose"; fi + +# 3. Stop ProxySQL Control Plane +echo ">>> Stopping ProxySQL..." +"${SCRIPT_DIR}/stop-proxysql-isolated.bash" || true + +# 4. Destroy Required Backends (in reverse order) +echo ">>> Destroying backends for group '${TAP_GROUP}'..." +for INFRA_NAME in ${INFRAS}; do + INFRA_DIR="${WORKSPACE}/test/infra/${INFRA_NAME}" + if [ ! -d "${INFRA_DIR}" ]; then + echo "WARNING: Infrastructure directory '${INFRA_DIR}' not found, skipping..." + continue + fi + + COMPOSE_PROJECT="${INFRA_NAME}-${INFRA_ID}" + echo ">>> Destroying backend '${INFRA_NAME}' (Project: ${COMPOSE_PROJECT})..." + + if [ -f "${INFRA_DIR}/docker-compose-destroy.bash" ]; then + cd "${INFRA_DIR}" + ./docker-compose-destroy.bash || echo "WARNING: Failed to destroy ${INFRA_NAME}" + cd - >/dev/null + else + echo ">>> Using docker compose down for '${INFRA_NAME}'..." + cd "${INFRA_DIR}" + $COMPOSE_CMD -p "${COMPOSE_PROJECT}" down -v 2>/dev/null || true + cd - >/dev/null + fi +done + +echo ">>> Cleanup complete for group '${TAP_GROUP}' (INFRA_ID: ${INFRA_ID})." +echo ">>> To re-initialize, run: TAP_GROUP=${TAP_GROUP} ./ensure-infras.bash" diff --git a/test/scripts/bin/proxysql-tester.py b/test/scripts/bin/proxysql-tester.py index e5f57da5d..2b8b69c1f 100755 --- a/test/scripts/bin/proxysql-tester.py +++ b/test/scripts/bin/proxysql-tester.py @@ -700,7 +700,7 @@ CREATE TABLE stats_history.mysql_server_read_only_log ( for fo_num, fo_cmd in enumerate(tap_tests): # omitted from groups.json (only check if groups.json has content and TAP_GROUP is not set or group has tests) - if groups and (not TAP_GROUP or group_has_tests) and os.path.basename(fo_cmd) not in groups: + if groups and (not TAP_GROUP or group_has_tests) and os.path.basename(fo_cmd) not in groups: log.debug(f"{TAP} test {fo_num+1}/{len(tap_tests)} '{os.path.basename(fo_cmd)}' omitted.") log.debug(f"omitted: not present in groups.json: '{os.path.realpath(fo_cmd)}'") summary.append((fo_cmd, None))