Files
NODEDC_MISSION_CORE/scripts/qualification/package_link_budget.py
T
DCCONSTRUCTIONS e06ff9a214 feat(fleet): add shared WireGuard profiles and bounded rover transport
Add portable shared WireGuard profiles while retaining Tailscale and Worker boundaries. Bound rover command/telemetry delivery, recovery and diagnostic capture across Core and Node.
2026-10-29 09:10:01 +03:00

164 lines
7.4 KiB
Python

"""Package exact Node sources for isolated, opt-in Worker 006 qualification."""
import argparse
import hashlib
import json
import shlex
import tarfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
NODE = ROOT / "apps/node-agent"
NETEM_IMAGE = "sha256:264a1dac982cafa1594654a728ba487fdddf04fc05476daba377f2b04bd2f917"
IMAGE = "sha256:83f487e0a63425e5b4d146fb5e5be574bcbe1b7b843d3ebafdd95eaf7767a7e5"
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--output", type=Path, default=ROOT / "outputs/link-budget-qualification")
parser.add_argument("--suite", choices=["budget", "transport", "contention"], default="budget")
parser.add_argument("--run-pattern")
parser.add_argument("--skip-pattern", default="")
args = parser.parse_args()
output = args.output
output.mkdir(parents=True, exist_ok=True)
toolchain = json.loads((NODE / "packaging/linux-toolchains.json").read_text())["files"][0]
compiler = NODE / "build/linux-toolchains" / toolchain["name"]
assert hashlib.sha256(compiler.read_bytes()).hexdigest() == toolchain["sha256"]
sources = {
str(p.relative_to(NODE)): p
for p in (NODE / "internal").rglob("*")
if p.is_file() and p.suffix in {".go", ".json"}
}
sources["go.mod"] = NODE / "go.mod"
qualification = {
"budget": "link_budget_load_test.go",
"contention": "rover_contention_test.go",
"transport": "rover_transport_test.go",
}[args.suite]
sources["internal/node/worker_" + qualification] = ROOT / "tests/qualification" / qualification
if args.suite in ("transport", "contention"):
sources["internal/node/worker_rover_datagram_test.go"] = (
ROOT / "tests/qualification/rover_datagram_test.go"
)
if args.suite == "contention":
sources["internal/node/worker_rover_transport_test.go"] = (
ROOT / "tests/qualification/rover_transport_test.go"
)
sources["internal/node/worker_rover_connect_test.go"] = (
ROOT / "tests/qualification/rover_connect_test.go"
)
fixtures = {
f"plugins/{plugin}/{name}": ROOT / "plugins" / plugin / name
for plugin in ("vesc", "usb-can")
for name in ("runtime/__init__.py", "packaging/prepare.py")
}
image = NETEM_IMAGE if args.suite == "contention" else IMAGE
go_timeout = "180s" if args.suite == "contention" else "90s"
capability = (
"--cap-add NET_ADMIN --env MISSION_CORE_ISOLATED_NETEM=1 "
if args.suite == "contention" else ""
)
selection = {
"budget": ("^(TestWorker|TestMedia|TestLink|TestBudgetReader|TestDev|TestRoverStream"
"|TestHeartbeat|TestOldHeartbeat)"),
"contention": (
"^(TestWorkerContentionMatrix|TestWorkerTransport|TestRover|TestLink|TestCommand)"
),
"transport": ("^(TestWorkerTransport|TestRoverStream|TestRoverLocalDelivery"
"|TestDelayedHTTPClock|TestObservationClock)"),
}[args.suite]
selection = args.run_pattern or selection
manifest = {
"schema": "missioncore.worker-link-qualification/v1",
"image": image,
"network_scope": "isolated-loopback-only" if args.suite == "contention" else "none",
"capability": "NET_ADMIN" if args.suite == "contention" else None,
"suite": args.suite,
"selection": selection,
"skip": args.skip_pattern,
"builder_sha256": hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
"toolchain": toolchain,
"sources": {k: hashlib.sha256(p.read_bytes()).hexdigest() for k, p in sources.items()},
"source_root": "apps/node-agent",
"fixtures": {k: hashlib.sha256(p.read_bytes()).hexdigest() for k, p in fixtures.items()},
"limits": {"cpus": 2, "memory": "2g", "pids": 256, "seconds": 240, "network": "none"},
}
identity = hashlib.sha256(json.dumps(manifest, sort_keys=True).encode()).hexdigest()[:20]
folder = output / ("worker-" + identity)
folder.mkdir(exist_ok=False)
with tarfile.open(folder / "source.tar", "w") as tar:
for name, p in sorted(sources.items()):
tar.add(p, arcname="apps/node-agent/" + name, recursive=False)
for name, p in sorted(fixtures.items()):
tar.add(p, arcname=name, recursive=False)
(folder / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
(folder / "run.sh").write_text("""#!/bin/sh
set -eu
mkdir -p /work/source /work/toolchain /work/cache /work/tmp
tar --no-same-owner -xzf /input/go.tar.gz -C /work/toolchain
tar --no-same-owner -xf /input/source.tar -C /work/source
export GOROOT=/work/toolchain/go GOCACHE=/work/cache GOTMPDIR=/work/tmp
export GOPROXY=off GOTOOLCHAIN=local CGO_ENABLED=0 GOMAXPROCS=2
cd /work/source/apps/node-agent
selection=@SELECTION@
skip=@SKIP@
timeout 240 /work/toolchain/go/bin/go test -p 1 -count=1 -timeout=@GO_TIMEOUT@ -v \\
./internal/node -run "$selection" -skip "$skip"
""".replace("@SELECTION@", shlex.quote(selection)).replace("@GO_TIMEOUT@", go_timeout)
.replace("@SKIP@", shlex.quote(args.skip_pattern)))
files = {
name: hashlib.sha256((folder / name).read_bytes()).hexdigest()
for name in ["source.tar", "manifest.json", "run.sh"]
}
files["go.tar.gz"] = toolchain["sha256"]
(folder / "files.json").write_text(json.dumps(files, indent=2) + "\n")
# The script owns this one container. It mounts only immutable test inputs,
# has no GPU/host sockets/credentials or network and always removes itself.
runner_script = (
"""$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$files = Get-Content (Join-Path $root 'files.json') -Raw | ConvertFrom-Json
foreach ($entry in $files.PSObject.Properties) {
$hash = (Get-FileHash (Join-Path $root $entry.Name) -Algorithm SHA256).Hash.ToLower()
if ($hash -ne $entry.Value) { throw 'Qualification input changed' }
}
$name = 'ndc-mission-core-link-budget-"""
+ identity
+ "'\n"
+ """$started = [DateTime]::UtcNow.ToString('o')
try {
$ErrorActionPreference = 'Continue'
& docker run --rm --pull never --name $name `
--label com.nodedc.product=mission-core --label com.nodedc.role=qualification `
--network none --cap-drop ALL @CAPABILITY@--security-opt no-new-privileges `
--cpus 2 --memory 2g --pids-limit 256 --read-only `
--tmpfs /work:rw,exec,size=1536m --tmpfs /tmp:rw,size=16m `
--mount "type=bind,source=$root,target=/input,readonly" --entrypoint /bin/sh """
+ image
+ """ /input/run.sh 2>&1 | Out-File (Join-Path $root 'result.log') -Encoding utf8
$exit = $LASTEXITCODE
$ErrorActionPreference = 'Stop'
@{
started_at=$started;finished_at=[DateTime]::UtcNow.ToString('o')
exit_code=$exit;container=$name
result_sha256=(Get-FileHash (Join-Path $root 'result.log') -Algorithm SHA256).Hash.ToLower()
} | ConvertTo-Json | Set-Content (Join-Path $root 'result.json') -Encoding utf8
if ($exit -ne 0) { throw 'Worker qualification failed; preserve result.log' }
} finally {
$ErrorActionPreference = 'Continue'
& docker rm -f $name 2>$null | Out-Null
}
"""
)
(folder / "run.ps1").write_text(runner_script.replace("@CAPABILITY@", capability))
print(
json.dumps(
{"id": identity, "folder": str(folder), "toolchain": str(compiler), "files": files}
)
)
if __name__ == "__main__":
main()