diff --git a/deploy/containerlab/scripts/verify-fabric-api.sh b/deploy/containerlab/scripts/verify-fabric-api.sh index 1224b0df..cf7444f0 100755 --- a/deploy/containerlab/scripts/verify-fabric-api.sh +++ b/deploy/containerlab/scripts/verify-fabric-api.sh @@ -34,11 +34,22 @@ SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) source "${SCRIPT_DIR}/lib.sh" WORK=$(mktemp -d) +# stop_pf ends the gateway port-forward and waits for it, so no kubectl +# outlives the script. +PF_PID= +stop_pf() { + [[ -n "${PF_PID}" ]] || return 0 + kill "${PF_PID}" 2>/dev/null || true + wait "${PF_PID}" 2>/dev/null || true + PF_PID= +} cleanup() { - [[ -n "${PF_PID:-}" ]] && kill "${PF_PID}" 2>/dev/null || true + stop_pf rm -rf "${WORK}" } trap cleanup EXIT +trap 'exit 130' INT +trap 'exit 143' TERM echo "Building the fabric-api client..." (cd "${SCRIPT_DIR}/../../.." && CGO_ENABLED=0 go build -o "${WORK}/fabric-api" ./cmd/fabric-api) @@ -252,7 +263,9 @@ for site in dfw iad sjc; do # Gateway debug service, through a port-forward to its Service. port=$((19346 + RANDOM % 1000)) - k -n galactic-system port-forward svc/fabric-api-gateway "${port}:9346" >/dev/null 2>&1 & + # Call kubectl directly rather than through k: backgrounding a function + # forks a subshell, and $! would then name the subshell, not kubectl. + kubectl --kubeconfig "${kc}" -n galactic-system port-forward svc/fabric-api-gateway "${port}:9346" >/dev/null 2>&1 & PF_PID=$! for _ in $(seq 1 50); do (echo >/dev/tcp/127.0.0.1/${port}) 2>/dev/null && break @@ -270,8 +283,7 @@ for site in dfw iad sjc; do else bad "${site} gateway: public probe of a loopback: ${r}" fi - kill "${PF_PID}" 2>/dev/null || true - PF_PID= + stop_pf # FabricQuery end to end, written as NSO would write it on the hub. k create namespace fabric-api-verify --dry-run=client -o yaml | k apply -f - >/dev/null diff --git a/deploy/containerlab/scripts/verify-nat-active-active.sh b/deploy/containerlab/scripts/verify-nat-active-active.sh index 86444efd..893e6848 100755 --- a/deploy/containerlab/scripts/verify-nat-active-active.sh +++ b/deploy/containerlab/scripts/verify-nat-active-active.sh @@ -383,6 +383,10 @@ originate() { # SHARD yes|no cleanup() { local rc=$? set +e + if [ -n "${SOAK_PID:-}" ]; then + kill "${SOAK_PID}" 2>/dev/null + wait "${SOAK_PID}" 2>/dev/null + fi for p in "${PROHIBITED[@]}"; do unprohibit "${p}"; done [ -n "${WITHDRAWN}" ] && originate "${WITHDRAWN}" yes if [ -f "${STATE}/fresh" ]; then @@ -417,7 +421,9 @@ soak_start() { "ip6 and dst ${HOST6} and tcp dst port 80 and ip6[53] & 0x12 == 0x02" >"${cap}" 2>&1 & local tcpdump_pid=$! sleep 2 - pod_exec "$1" curl -s -o /dev/null -w '%{size_download} %{exitcode}' --limit-rate 150k --max-time 300 \ + # Run docker exec directly rather than through pod_exec: backgrounding a + # function forks a subshell, and $! would then name the subshell. + docker exec "${CP}" kubectl -n "${1%%/*}" exec "${1#*/}" -- curl -s -o /dev/null -w '%{size_download} %{exitcode}' --limit-rate 150k --max-time 300 \ "http://[${HOST6}]/active-active-soak" >"${STATE}/soak" 2>"${STATE}/soak.err" & SOAK_PID=$! wait "${tcpdump_pid}" || die "could not see the download's connection at the host" @@ -427,6 +433,7 @@ soak_start() { soak_check() { local rc=0 got="" code="" wait "${SOAK_PID}" || rc=$? + SOAK_PID="" read -r got code <"${STATE}/soak" || true if [ "${rc}" -ne 0 ] || [ "${got}" != "${SOAK_BYTES}" ] || [ "${code}" != 0 ]; then die "$1: the download ended at ${got:-nothing} of ${SOAK_BYTES} bytes (curl ${code:-none}, exec ${rc}): $(cat "${STATE}/soak.err")"