69 lines
4.0 KiB
Python
69 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""One real-TA publication-point RP smoke inside the prepared replay namespace."""
|
|
import argparse
|
|
from datetime import datetime, timezone
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import time
|
|
|
|
from common import atomic_json, read_json
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--binary", type=Path, required=True)
|
|
parser.add_argument("--tal", type=Path, required=True)
|
|
parser.add_argument("--ta", type=Path, required=True)
|
|
parser.add_argument("--manifest", type=Path, required=True)
|
|
parser.add_argument("--out", type=Path, required=True)
|
|
parser.add_argument("--disable-rrdp", action="store_true", help="Force real rsync for a separately identified transport fixture")
|
|
args = parser.parse_args()
|
|
args.out.mkdir(parents=True)
|
|
(args.out / "tmp").mkdir()
|
|
manifest = read_json(args.manifest)
|
|
epoch = read_json(Path(manifest["epoch_path"]))
|
|
validation_time = datetime.fromtimestamp(epoch["validation_time_ms"] // 1000, timezone.utc).isoformat().replace("+00:00", "Z")
|
|
command = ["/usr/bin/time", "-v", str(args.binary), "--db", str(args.out / "db"), "--tal-path", str(args.tal),
|
|
"--cir-tal-uri", f"https://capture.rpki187.invalid/tal/{hashlib.sha256(args.tal.read_bytes()).hexdigest()}/{args.tal.name}",
|
|
"--ta-path", str(args.ta), "--http-root-cert", manifest["tls"]["ca"], "--max-instances", "1",
|
|
"--validation-time", validation_time, "--report-json", str(args.out / "report.json"),
|
|
"--report-json-compact", "--ccr-out", str(args.out / "result.ccr"),
|
|
"--cir-enable", "--cir-out", str(args.out / "input.cir"),
|
|
"--record-transport-dir", str(args.out / "transport"), "--rsync-mirror-root", str(args.out / "mirror")]
|
|
if args.disable_rrdp:
|
|
command.append("--disable-rrdp")
|
|
env = {key: value for key, value in os.environ.items() if key.lower() not in ("http_proxy", "https_proxy", "all_proxy")}
|
|
env["TMPDIR"] = str(args.out / "tmp")
|
|
started = time.monotonic()
|
|
with (args.out / "stdout.log").open("wb") as out, (args.out / "stderr.log").open("wb") as err:
|
|
result = subprocess.run(command, stdout=out, stderr=err, env=env, timeout=900)
|
|
log = (args.out / "stderr.log").read_text(errors="replace")
|
|
anchors = re.findall(r"wrote CIR: .*?trust_anchors=(\d+)", log)
|
|
report = read_json(args.out / "report.json") if (args.out / "report.json").exists() else {}
|
|
proof = {"exit_code": result.returncode, "wall_secs": time.monotonic() - started,
|
|
"profile": "functional_smoke_not_performance", "command": command,
|
|
"binary_sha256": hashlib.sha256(args.binary.read_bytes()).hexdigest(),
|
|
"ta_sha256": hashlib.sha256(args.ta.read_bytes()).hexdigest(), "ta_mode": "pinned genuine TA checked against real TAL",
|
|
"network_namespace": os.readlink("/proc/self/ns/net"), "validation_time": validation_time,
|
|
"trust_anchors": int(anchors[-1]) if anchors else 0, "tree": report.get("tree"),
|
|
"publication_points": len(report.get("publication_points", []))}
|
|
events = [read_json(path) for path in (args.out / "transport/events").glob("*.json")]
|
|
proof["forced_rsync_fixture"] = args.disable_rrdp
|
|
proof["successful_transport_events"] = {kind: sum(event["complete"] and event["transport"] == kind for event in events)
|
|
for kind in ("http", "rsync")}
|
|
proof["pass"] = (result.returncode == 0 and proof["trust_anchors"] == 1 and proof["publication_points"] == 1
|
|
and report["tree"]["instances_failed"] == 0)
|
|
if args.disable_rrdp:
|
|
proof["pass"] = proof["pass"] and proof["successful_transport_events"]["rsync"] > 0 and not proof["successful_transport_events"]["http"]
|
|
atomic_json(args.out / "smoke-proof.json", proof)
|
|
print(json.dumps(proof), flush=True)
|
|
return 0 if proof["pass"] else 2
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|