From 920d9b5694c402188526b8c12e737a081f8ed680 Mon Sep 17 00:00:00 2001 From: Alexey Bodanyuk <144894236+wfa22@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:06:29 +0300 Subject: [PATCH] =?UTF-8?q?stop-one:=20alias=20=D1=80=D0=B5=D0=BF=D0=BB?= =?UTF-8?q?=D0=B8=D0=BA=20=D1=87=D0=B8=D1=82=D0=B0=D0=B5=D1=82=D1=81=D1=8F?= =?UTF-8?q?=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BB=D0=BB=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE,=20docker=20stop=20=D0=B2=20=D1=84=D0=BE=D0=BD=D0=B5=20(?= =?UTF-8?q?=D1=85=D1=83=D0=BA=20<=2010=20=D1=81=20=D0=BD=D0=B0=20Windows);?= =?UTF-8?q?=20check=5Fdashboard=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20Grafana=20=D0=BF=D1=83=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=87=D0=BD=D1=8B=D0=BC=20CA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/check_dashboard.py | 4 ++-- scripts/collect_evidence.py | 6 +++--- scripts/stop-one.sh | 37 +++++++++++++++++++++++++------------ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/scripts/check_dashboard.py b/scripts/check_dashboard.py index a283a6d..e36c10d 100644 --- a/scripts/check_dashboard.py +++ b/scripts/check_dashboard.py @@ -25,7 +25,7 @@ def post(path: str, body: dict) -> dict: request = urllib.request.Request(obs.GRAFANA + path, data=json.dumps(body).encode(), method="POST", headers={"Authorization": obs._auth(), "Content-Type": "application/json"}) try: - with urllib.request.urlopen(request, timeout=60) as response: + with urllib.request.urlopen(request, timeout=60, context=obs.TLS) as response: return json.loads(response.read()) except urllib.error.HTTPError as exc: return json.loads(exc.read() or b"{}") | {"_status": exc.code} @@ -33,7 +33,7 @@ def post(path: str, body: dict) -> dict: def get(path: str) -> dict: request = urllib.request.Request(obs.GRAFANA + path, headers={"Authorization": obs._auth()}) - with urllib.request.urlopen(request, timeout=30) as response: + with urllib.request.urlopen(request, timeout=30, context=obs.TLS) as response: return json.loads(response.read()) diff --git a/scripts/collect_evidence.py b/scripts/collect_evidence.py index 2d56150..a292b53 100644 --- a/scripts/collect_evidence.py +++ b/scripts/collect_evidence.py @@ -120,7 +120,7 @@ def failover_both() -> None: text=True, env=ENV).stdout.split()} rc = step(f"failover run {attempt}", filename, [PY, "tests/resilience.py", "--mode", "failover", "--action-script", hook("stop-one"), "--ca-file", CA], - ["docker", "compose", "ps", "-a", "--format", "{{.Name}} {{.Status}}", "api"], append=True) + ["docker", "compose", "ps", "-a", "api"], append=True) results.pop() code = code or rc after = {c for c in subprocess.run(["docker", "compose", "ps", "-q", "api"], cwd=ROOT, capture_output=True, @@ -149,9 +149,9 @@ def main() -> int: step("OpenBao allow/deny, root credential отсутствует в app", "bao-check.txt", sh("bao_check.sh"), [PY, "scripts/bao_operator.py", "status"]) step("make test-persistence (рестарт всех процессов, unseal)", "persistence.txt", - ["docker", "compose", "ps", "-a", "--format", "{{.Name}} {{.State}} {{.Status}}"], + ["docker", "compose", "ps", "-a"], [PY, "tests/resilience.py", "--mode", "persistence", "--action-script", hook("restart"), "--ca-file", CA], - ["docker", "compose", "ps", "-a", "--format", "{{.Name}} {{.State}} {{.Status}}"], timeout=600) + ["docker", "compose", "ps", "-a"], timeout=600) failover_both() argon2_bench() step("Телеметрия по mTLS: trace + logs", "trace-demo.txt", [PY, "scripts/trace_demo.py"]) diff --git a/scripts/stop-one.sh b/scripts/stop-one.sh index 2e73fe2..22c641d 100644 --- a/scripts/stop-one.sh +++ b/scripts/stop-one.sh @@ -8,7 +8,11 @@ # scripts/restore-api.sh (make restore). # STOP_MODE=stop (default) SIGTERM: readiness 503, 3 s drain, graceful exit (~4 s) # STOP_MODE=kill SIGKILL at once (`docker stop -t 0`): crash of the process -# Returns within 10 s. The test hides the output; run by hand to see it (no secrets printed). +# The test requires the hook to return within 10 s. On Windows one `docker exec` costs ~1.8 s, so +# the aliases are read IN PARALLEL, and `docker stop` runs in the background: Docker marks the +# container as stopped by the user at once (the restart policy will not bring it back), the drain +# and exit happen while the test is already sending requests. WAIT=1 waits for the stop (by hand). +# The test hides the output; run by hand to see it (no secrets printed). set -eu cd "$(dirname "$0")/.." export MSYS_NO_PATHCONV=1 # Git Bash: keep /tmp/instance_id a container path @@ -17,22 +21,31 @@ case "$TARGET_INSTANCE_ID" in *[!A-Za-z0-9._-]*) echo "stop-one: invalid TARGET_INSTANCE_ID" >&2; exit 2 ;; esac mode="${STOP_MODE:-stop}" +case "$mode" in + stop) grace=15 ;; + kill) grace=0 ;; + *) echo "stop-one: STOP_MODE must be stop or kill" >&2; exit 2 ;; +esac -target="" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT # Only RUNNING containers of THIS compose project's service `api` are candidates. for id in $(docker compose ps -q api); do - if [ "$(docker exec "$id" cat /tmp/instance_id 2>/dev/null | tr -d '\r\n')" = "$TARGET_INSTANCE_ID" ]; then - target="$id" - fi + (docker exec "$id" cat /tmp/instance_id 2>/dev/null | tr -d '\r\n' > "$tmp/$id") & +done +wait +target="" +for f in "$tmp"/*; do + [ -f "$f" ] && [ "$(cat "$f")" = "$TARGET_INSTANCE_ID" ] && target="$(basename "$f")" done if [ -z "$target" ]; then echo "stop-one: no running api replica with X-Instance-Id=$TARGET_INSTANCE_ID" >&2 exit 3 fi -name="$(docker inspect -f '{{.Name}}' "$target")" -case "$mode" in - stop) docker stop --time 15 "$target" >/dev/null ;; - kill) docker stop --time 0 "$target" >/dev/null ;; - *) echo "stop-one: STOP_MODE must be stop or kill" >&2; exit 2 ;; -esac -echo "stop-one: $mode $name (X-Instance-Id=$TARGET_INSTANCE_ID) -> $(docker inspect -f '{{.State.Status}} exit={{.State.ExitCode}}' "$target")" +if [ "${WAIT:-0}" = 1 ]; then + docker stop --time "$grace" "$target" >/dev/null + echo "stop-one: $mode $target (X-Instance-Id=$TARGET_INSTANCE_ID) -> $(docker inspect -f '{{.State.Status}} exit={{.State.ExitCode}}' "$target")" +else + nohup docker stop --time "$grace" "$target" >/dev/null 2>&1 & + echo "stop-one: $mode $target (X-Instance-Id=$TARGET_INSTANCE_ID) requested; the container stops in the background" +fi