94 lines
3.6 KiB
Bash
Executable File
94 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Reproduce the lab4 mandatory and own checks on the running stand and keep
|
|
# their real stdout under evidence/commands/. No secrets are printed by these
|
|
# commands; the context block contains versions and image ids only.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
export BASE_URL=${BASE_URL:-http://127.0.0.1:8084}
|
|
PY39=/usr/bin/python3
|
|
out=evidence/commands
|
|
mkdir -p "$out"
|
|
stamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
|
|
{
|
|
echo "started_at: $stamp"
|
|
echo "base_url: $BASE_URL"
|
|
echo "git_revision: $(git rev-parse HEAD)"
|
|
echo "git_status_lines: $(git status --porcelain | wc -l | tr -d ' ')"
|
|
echo "python3: $(python3 --version 2>&1)"
|
|
echo "python39: $($PY39 --version 2>&1)"
|
|
echo "go: $(go version)"
|
|
echo "docker_server: $(docker version --format '{{.Server.Version}}')"
|
|
echo "docker_cpus_mem: $(docker info --format 'CPUs={{.NCPU}} MemTotal={{.MemTotal}}')"
|
|
echo "api_images:"
|
|
for id in $(./scripts/compose.sh --env-file .env ps -q api); do
|
|
docker inspect -f ' {{.Name}} image={{.Image}} started={{.State.StartedAt}}' "$id"
|
|
done
|
|
echo "s3_image:"
|
|
for id in $(./scripts/compose.sh --env-file .env ps -q s3); do
|
|
docker inspect -f ' {{.Name}} image={{.Image}}' "$id"
|
|
done
|
|
} | tee "$out/context.txt"
|
|
|
|
run() {
|
|
name=$1
|
|
shift
|
|
{
|
|
echo
|
|
echo "### $name"
|
|
echo "### command: $*"
|
|
echo "### started_at: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
} | tee "$out/$name.txt"
|
|
set +e
|
|
"$@" 2>&1 | tee -a "$out/$name.txt"
|
|
code=${PIPESTATUS[0]}
|
|
set -e
|
|
echo "### exit_code: $code" | tee -a "$out/$name.txt"
|
|
if [ "$code" -ne 0 ]; then
|
|
echo "evidence collection stopped: $name failed" >&2
|
|
exit "$code"
|
|
fi
|
|
}
|
|
|
|
restore_replicas() {
|
|
./scripts/compose.sh --env-file .env up -d --no-deps api >/dev/null
|
|
./scripts/wait-ready.sh
|
|
# The LB needs a moment to see the restarted backend. Do not continue until
|
|
# the public health endpoint reports two distinct X-Instance-Id values.
|
|
attempt=0
|
|
while [ "$attempt" -lt 60 ]; do
|
|
visible=$(for _ in $(seq 1 20); do
|
|
curl -fsS -D - -o /dev/null "$BASE_URL/health/ready" 2>/dev/null \
|
|
| tr -d '\r' | awk 'tolower($1)=="x-instance-id:"{print $2}'
|
|
done | sort -u | wc -l | tr -d ' ')
|
|
if [ "$visible" -ge 2 ]; then
|
|
return 0
|
|
fi
|
|
attempt=$((attempt + 1))
|
|
sleep 0.5
|
|
done
|
|
echo "restore_replicas: LB still sees fewer than two API instances" >&2
|
|
return 1
|
|
}
|
|
|
|
run make_check make PYTHON=$PY39 check
|
|
run make_validate make PYTHON=.venv/bin/python validate
|
|
run go_tests make PYTHON=$PY39 test-student
|
|
run go_race make PYTHON=$PY39 test-student-race
|
|
run smoke make PYTHON=$PY39 test
|
|
run smoke_python39 ./scripts/py39-tests.sh
|
|
run attachment_checks make PYTHON=$PY39 test-attachment
|
|
run container_checks make PYTHON=$PY39 test-container
|
|
run persistence_public make PYTHON=$PY39 test-persistence ACTION_SCRIPT=scripts/restart.sh
|
|
run persistence_evidence $PY39 scripts/persistence-evidence.py --base-url "$BASE_URL"
|
|
run failover_public make PYTHON=$PY39 test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
|
restore_replicas
|
|
run failover_upload $PY39 scripts/failover-upload.py --base-url "$BASE_URL"
|
|
run track2 make PYTHON=$PY39 test-consistency
|
|
run experiment make PYTHON=$PY39 experiment
|
|
run smoke_after_experiment make PYTHON=$PY39 test
|
|
|
|
echo "finished_at: $(date -u +%Y-%m-%dT%H:%M:%SZ)" | tee "$out/summary.txt"
|
|
grep -h '^### exit_code:' "$out"/*.txt | sort | uniq -c | tee -a "$out/summary.txt"
|
|
echo "PASS: evidence collection finished; raw command logs are in $out"
|