test: probe runtime image from its network namespace
Linux / verify (pull_request) Successful in 3m22s
Linux / keyless-cuda (pull_request) Skipped
Linux / static-cuda-package (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 20s
Linux / linux-static-cli (pull_request) Failing after 6m57s
Linux / release-cli (pull_request) Skipped

This commit is contained in:
Pavlo Ratushnyi
2026-10-06 00:32:38 +02:00
parent 096d21dcec
commit cb075ef762
2 changed files with 61 additions and 23 deletions
+53 -23
View File
@@ -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()<deadline:
try:
if request('/status')['ready']: return
except OSError: pass
time.sleep(.1)
raise AssertionError('container worker did not become ready')
def generate():
result = request('/v1/responses', {'model':'embedded-fixture','input':'Reply A',
'max_output_tokens':1,'reasoning':{'effort':'none'}})
assert result['status']=='completed'
assert result['output'][0]['content'][0]['text']=='A'
ready(); generate()
def probe():
# The Gitea job container and Docker daemon do not share the
# daemon host's loopback. A short-lived client joins the
# server's network namespace, so probes remain loopback-only
# and don't publish a runtime port from the CI host.
docker('run', '--rm', '--platform', 'linux/amd64', '--network', f'container:{name}',
'--read-only', '--cap-drop', 'ALL', '--security-opt', 'no-new-privileges',
'--user', '65532:65532', '-e', 'CUDA_VISIBLE_DEVICES=',
'-e', 'NVIDIA_VISIBLE_DEVICES=void',
'--mount', f'type=volume,src={fixture_volume},dst=/fixture,readonly',
'--entrypoint', '/bin/bash', base, '/fixture/probe.sh')
probe()
before = docker('exec', name, 'cat', '/tmp/worker.pid').stdout.strip()
assert before.isascii() and before.isdigit()
docker('exec', name, '/bin/sh', '-c', 'kill -KILL "$1"', 'strata-smoke', before)
@@ -83,7 +113,7 @@ def main(receipt):
while docker('exec', name, 'cat', '/tmp/worker.pid').stdout.strip()==before:
assert time.monotonic()<deadline
time.sleep(.1)
ready(); generate()
probe()
docker('stop', '--time', '10', name)
state = json.loads(docker('inspect','--format','{{json .State}}',name).stdout)
assert state['ExitCode']==0 and not state['OOMKilled']
+8
View File
@@ -3,6 +3,7 @@
import importlib.util
import json
from pathlib import Path
import subprocess
import tempfile
import unittest
from types import SimpleNamespace
@@ -11,6 +12,9 @@ from unittest.mock import patch
spec = importlib.util.spec_from_file_location('builder', Path(__file__).with_name('build-runtime-image.py'))
b = importlib.util.module_from_spec(spec)
spec.loader.exec_module(b)
smoke_spec = importlib.util.spec_from_file_location('smoke', Path(__file__).with_name('smoke-runtime-image.py'))
smoke = importlib.util.module_from_spec(smoke_spec)
smoke_spec.loader.exec_module(smoke)
class PackageTests(unittest.TestCase):
@@ -106,6 +110,10 @@ class PackageTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, 'size limit'):
b.frozen_file(self.pkg/b.NAME, Path(stage)/'out', 1)
def test_runtime_probe_script_has_valid_bash_syntax(self):
subprocess.run(['bash', '-n'], input=smoke.PROBE_SCRIPT, text=True,
capture_output=True, check=True)
if __name__ == '__main__':
unittest.main()