forked from mtusi2026/mtusi2026lab7
wip: apply pki-ingress-mtls groups 1-4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""Alias процесса в `src/infra/early_stop.py` (спек `service-configuration`,
|
||||
«Ранняя остановка без hostname»; change `pki-ingress-mtls`, design, решение
|
||||
9). Отдельный интерпретатор: `install()` меняет окружение и обработчики
|
||||
сигналов процесса.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from src.config.settings import BASE_DIR
|
||||
|
||||
PROBE = """
|
||||
import os, signal
|
||||
from src.infra import early_stop
|
||||
early_stop.install()
|
||||
first = os.environ["APP__INSTANCE_ID"]
|
||||
early_stop.install()
|
||||
assert os.environ["APP__INSTANCE_ID"] == first, "alias changed"
|
||||
print(first, flush=True)
|
||||
os.kill(os.getpid(), signal.SIGTERM)
|
||||
"""
|
||||
|
||||
|
||||
def run_probe(**env: str) -> list[str]:
|
||||
base = {
|
||||
key: value
|
||||
for key, value in os.environ.items()
|
||||
if key != "APP__INSTANCE_ID"
|
||||
}
|
||||
done = subprocess.run( # noqa: S603
|
||||
[sys.executable, "-c", PROBE],
|
||||
cwd=BASE_DIR,
|
||||
env={**base, **env},
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
check=False,
|
||||
)
|
||||
assert done.returncode == 0, done.stderr
|
||||
return done.stdout.splitlines()
|
||||
|
||||
|
||||
def test_early_stop_record_has_alias() -> None:
|
||||
alias, record_line = run_probe()
|
||||
record = json.loads(record_line)
|
||||
assert re.fullmatch(r"[0-9a-f]{16}", alias)
|
||||
assert record["event"] == "Stopped API before startup"
|
||||
assert record["signal"] == signal.SIGTERM.name
|
||||
assert record["instance_id"] == alias
|
||||
assert alias != socket.gethostname()
|
||||
|
||||
|
||||
def test_explicit_instance_id_kept() -> None:
|
||||
alias, record_line = run_probe(APP__INSTANCE_ID="api-a")
|
||||
assert alias == "api-a"
|
||||
assert json.loads(record_line)["instance_id"] == "api-a"
|
||||
Reference in New Issue
Block a user