noqt commited on
Commit
d239eee
·
1 Parent(s): 7531963

Harden restart qualification against transient socket loss

Browse files
Files changed (1) hide show
  1. scripts/run_native_matrix.py +21 -5
scripts/run_native_matrix.py CHANGED
@@ -63,6 +63,22 @@ def wait_state(operator: str, name: str, expected: str, timeout: float = 8) -> d
63
  raise RuntimeError(f"{name} did not reach {expected}: {latest}")
64
 
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  def main() -> int:
67
  if os.geteuid() != 0:
68
  raise SystemExit("native matrix must run as root")
@@ -95,7 +111,7 @@ def main() -> int:
95
  canary = subprocess.Popen(["/usr/sbin/runuser", "-u", workload, "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/canary.py")], start_new_session=True)
96
  try:
97
  name = f"race-{token}-{index}"
98
- call(operator, ["start", "--name", name, "--max-pids", "4096", "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/fork_race.py"), modes[index % len(modes)]])
99
  time.sleep(0.12)
100
  receipt_path = Path("/tmp") / f"lumi-eggcracker-receipt-{token}-{index}.json"
101
  receipt = call(operator, ["kill", "--name", name, "--receipt", str(receipt_path)])
@@ -111,7 +127,7 @@ def main() -> int:
111
  stop_canary(canary)
112
  for index in range(5):
113
  name = f"pressure-{token}-{index}"
114
- call(operator, ["start", "--name", name, "--max-pids", "4", "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/pid_pressure.py")])
115
  state = wait_state(operator, name, "TERMINATED")
116
  receipt_files = sorted(Path("/var/lib/lumi-eggcracker/receipts").glob("*.json"), key=lambda path: path.stat().st_mtime_ns)
117
  receipt = json.loads(receipt_files[-1].read_text(encoding="utf-8"))
@@ -121,14 +137,14 @@ def main() -> int:
121
  results["pid_tripwire"].append(receipt["containment"]["trigger_to_empty_ms"])
122
  for index in range(args.benign_repetitions):
123
  name = f"benign-{token}-{index}"
124
- call(operator, ["start", "--name", name, "--max-pids", "16", "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/benign_near_limit.py"), "12"])
125
  state = wait_state(operator, name, "COMPLETED_ALLOWED")
126
  if state.get("state") != "COMPLETED_ALLOWED":
127
  raise RuntimeError("benign near-limit workload was not allowed")
128
  results["benign"].append(state["state"])
129
  hostile_path = Path("/tmp") / f"lumi-eggcracker-hostile-{token}.json"
130
  hostile = f"hostile-{token}"
131
- call(operator, ["start", "--name", hostile, "--max-pids", "8", "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/hostile_client.py"), str(hostile_path), str(args.socket_attempts)])
132
  wait_state(operator, hostile, "COMPLETED_ALLOWED", timeout=30)
133
  hostile_result = json.loads(hostile_path.read_text(encoding="utf-8"))
134
  hostile_path.unlink(missing_ok=True)
@@ -147,7 +163,7 @@ def main() -> int:
147
  # Keep the target alive across the slowest full qualification run;
148
  # the probe must exercise restart containment of a live workload,
149
  # not race a naturally completed 30-second sleep.
150
- call(operator, ["start", "--name", name, "--max-pids", "8", "--", "/bin/sleep", "300"])
151
  run(["/usr/bin/systemctl", "kill", "--kill-who=main", "-s", "SIGKILL", "lumi-eggcracker.service"])
152
  state = wait_state(operator, name, "TERMINATED", timeout=12)
153
  receipt_files = sorted(Path("/var/lib/lumi-eggcracker/receipts").glob("*.json"), key=lambda path: path.stat().st_mtime_ns)
 
63
  raise RuntimeError(f"{name} did not reach {expected}: {latest}")
64
 
65
 
66
+ def start_workload(operator: str, args: list[str]) -> dict[str, Any]:
67
+ """Start once, resolving a response lost during bounded supervisor restart."""
68
+ try:
69
+ return call(operator, args)
70
+ except RuntimeError as error:
71
+ if args[:1] != ["start"] or "truncated supervisor response" not in str(error):
72
+ raise
73
+ try:
74
+ name_index = args.index("--name")
75
+ name = args[name_index + 1]
76
+ except (ValueError, IndexError) as parse_error:
77
+ raise RuntimeError("restart response was truncated and start name is unavailable") from parse_error
78
+ wait_state(operator, name, "RUNNING", timeout=5)
79
+ return {"result": "STARTED", "response_recovered": True}
80
+
81
+
82
  def main() -> int:
83
  if os.geteuid() != 0:
84
  raise SystemExit("native matrix must run as root")
 
111
  canary = subprocess.Popen(["/usr/sbin/runuser", "-u", workload, "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/canary.py")], start_new_session=True)
112
  try:
113
  name = f"race-{token}-{index}"
114
+ start_workload(operator, ["start", "--name", name, "--max-pids", "4096", "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/fork_race.py"), modes[index % len(modes)]])
115
  time.sleep(0.12)
116
  receipt_path = Path("/tmp") / f"lumi-eggcracker-receipt-{token}-{index}.json"
117
  receipt = call(operator, ["kill", "--name", name, "--receipt", str(receipt_path)])
 
127
  stop_canary(canary)
128
  for index in range(5):
129
  name = f"pressure-{token}-{index}"
130
+ start_workload(operator, ["start", "--name", name, "--max-pids", "4", "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/pid_pressure.py")])
131
  state = wait_state(operator, name, "TERMINATED")
132
  receipt_files = sorted(Path("/var/lib/lumi-eggcracker/receipts").glob("*.json"), key=lambda path: path.stat().st_mtime_ns)
133
  receipt = json.loads(receipt_files[-1].read_text(encoding="utf-8"))
 
137
  results["pid_tripwire"].append(receipt["containment"]["trigger_to_empty_ms"])
138
  for index in range(args.benign_repetitions):
139
  name = f"benign-{token}-{index}"
140
+ start_workload(operator, ["start", "--name", name, "--max-pids", "16", "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/benign_near_limit.py"), "12"])
141
  state = wait_state(operator, name, "COMPLETED_ALLOWED")
142
  if state.get("state") != "COMPLETED_ALLOWED":
143
  raise RuntimeError("benign near-limit workload was not allowed")
144
  results["benign"].append(state["state"])
145
  hostile_path = Path("/tmp") / f"lumi-eggcracker-hostile-{token}.json"
146
  hostile = f"hostile-{token}"
147
+ start_workload(operator, ["start", "--name", hostile, "--max-pids", "8", "--", "/usr/bin/python3", str(ROOT / "tests/fixtures/hostile_client.py"), str(hostile_path), str(args.socket_attempts)])
148
  wait_state(operator, hostile, "COMPLETED_ALLOWED", timeout=30)
149
  hostile_result = json.loads(hostile_path.read_text(encoding="utf-8"))
150
  hostile_path.unlink(missing_ok=True)
 
163
  # Keep the target alive across the slowest full qualification run;
164
  # the probe must exercise restart containment of a live workload,
165
  # not race a naturally completed 30-second sleep.
166
+ start_workload(operator, ["start", "--name", name, "--max-pids", "8", "--", "/bin/sleep", "300"])
167
  run(["/usr/bin/systemctl", "kill", "--kill-who=main", "-s", "SIGKILL", "lumi-eggcracker.service"])
168
  state = wait_state(operator, name, "TERMINATED", timeout=12)
169
  receipt_files = sorted(Path("/var/lib/lumi-eggcracker/receipts").glob("*.json"), key=lambda path: path.stat().st_mtime_ns)