From cb075ef762c96ce93f42d97853eadece81a8e4a1 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Tue, 6 Oct 2026 00:32:38 +0200 Subject: [PATCH] test: probe runtime image from its network namespace --- scripts/smoke-runtime-image.py | 76 ++++++++++++++++++++++++---------- scripts/test-runtime-image.py | 8 ++++ 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/scripts/smoke-runtime-image.py b/scripts/smoke-runtime-image.py index 8842653c..9e6da635 100644 --- a/scripts/smoke-runtime-image.py +++ b/scripts/smoke-runtime-image.py @@ -7,9 +7,45 @@ import subprocess import sys import tempfile import time -import urllib.request import uuid +PROBE_SCRIPT = r'''#!/bin/bash +set -euo pipefail +request() { + local method="$1" path="$2" body="${3-}" request status line response + if ! { exec 3<>/dev/tcp/127.0.0.1/8081; } 2>/dev/null; then return 1; fi + if [[ -n "$body" ]]; then + printf -v request '%s %s HTTP/1.0\r\nHost: localhost\r\nContent-Type: application/json\r\nContent-Length: %s\r\n\r\n%s' \ + "$method" "$path" "${#body}" "$body" + else + printf -v request '%s %s HTTP/1.0\r\nHost: localhost\r\nConnection: close\r\n\r\n' "$method" "$path" + fi + printf '%s' "$request" >&3 + IFS= read -r status <&3 || { exec 3<&-; exec 3>&-; return 1; } + status="${status%$'\r'}" + while IFS= read -r line <&3; do + line="${line%$'\r'}" + [[ -n "$line" ]] || break + done + response="$(cat <&3)" + exec 3<&- + exec 3>&- + [[ "${status:9:3}" == 200 ]] || { echo "HTTP request failed: $status $response" >&2; return 1; } + printf '%s' "$response" +} +deadline=$((SECONDS + 15)) +until status="$(request GET /status)"; do + if (( SECONDS >= deadline )); then echo 'worker did not become ready within 15s' >&2; exit 1; fi + sleep 0.1 +done +[[ "$status" == *'"ready":true'* ]] || { echo "unexpected /status response: $status" >&2; exit 1; } +result="$(request POST /v1/responses '{"model":"embedded-fixture","input":"Reply A","max_output_tokens":1,"reasoning":{"effort":"none"}}')" +[[ "$result" == *'"status":"completed"'* && "$result" == *'"text":"A"'* ]] || { + echo "unexpected Responses result: $result" >&2 + exit 1 +} +''' + def docker(*args, check=True): try: @@ -32,14 +68,15 @@ def main(receipt): fixture_container = 'strata-runtime-fixture-' + uuid.uuid4().hex fixture_volume = 'strata-runtime-fixture-' + uuid.uuid4().hex base = proof['base'] - opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) with tempfile.TemporaryDirectory(prefix='strata-container-fixture-') as tmp: root = Path(tmp); root.chmod(0o755) helper.tokenizer(root) (root/'config.json').write_text(json.dumps({'bind': '0.0.0.0:8081', 'model': 'embedded-fixture', 'engine_probe': True, 'engine': {'executable': '@embedded', 'args': ['/tmp/worker.pid'], 'tokenizer_dir': '/fixture', 'startup_timeout_s': 5, 'max_restarts': 1}})) + (root/'probe.sh').write_text(PROBE_SCRIPT) for path in root.iterdir(): path.chmod(0o644) + (root/'probe.sh').chmod(0o755) try: # The Docker daemon may be outside the job container. A job-local # /tmp bind source is therefore not guaranteed to exist on it. @@ -54,28 +91,21 @@ def main(receipt): docker('run', '-d', '--name', name, '--platform', 'linux/amd64', '--read-only', '--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--user', '65532:65532', '--tmpfs', '/tmp:rw,nosuid,nodev,size=64m', '-e', 'CUDA_VISIBLE_DEVICES=', - '-e', 'NVIDIA_VISIBLE_DEVICES=void', '-p', '127.0.0.1::8081', + '-e', 'NVIDIA_VISIBLE_DEVICES=void', '--mount', f'type=volume,src={fixture_volume},dst=/fixture,readonly', image, 'serve', '--config', '/fixture/config.json') - port = int(docker('port', name, '8081/tcp').stdout.strip().rsplit(':', 1)[1]) - def request(route, body=None): - req = urllib.request.Request(f'http://127.0.0.1:{port}{route}', - data=json.dumps(body).encode() if body else None, headers={'Content-Type': 'application/json'}) - with opener.open(req, timeout=5) as response: return json.load(response) - def ready(): - deadline = time.monotonic()+15 - while time.monotonic()