nixos/test-driver: fix test container shutdown (#522954)

This commit is contained in:
Martin Weinelt
2026-05-22 10:43:20 +00:00
committed by GitHub
@@ -1475,7 +1475,6 @@ class NspawnMachine(BaseMachine):
self.start_command = start_command
self.process = None
self.pid = None
self.machine_sock_path = self.tmp_dir / f"{self.name}-nspawn.sock"
@@ -1486,14 +1485,13 @@ class NspawnMachine(BaseMachine):
return f'ssh -o User=root -o ProxyCommand="{proxy_cmd}" bash'
def release(self) -> None:
if self.pid is None:
if self.process is None:
return
if self.machine_sock:
self.machine_sock.close()
self.logger.info(f"kill NspawnMachine (pid {self.pid})")
assert self.process is not None
self.logger.info(f"kill NspawnMachine (pid {self.process.pid})")
self.process.terminate()
# Wait for the wrapper to finish its context-manager cleanups
# (veth/bridge/netns teardown) before returning, so the driver's
@@ -1502,7 +1500,7 @@ class NspawnMachine(BaseMachine):
self.process.wait(timeout=30)
except subprocess.TimeoutExpired:
self.logger.error(
f"NspawnMachine {self.name} (pid {self.pid}) did not exit after SIGTERM; sending SIGKILL"
f"NspawnMachine {self.name} (pid {self.process.pid}) did not exit after SIGTERM; sending SIGKILL"
)
self.process.kill()
self.process.wait()
@@ -1694,9 +1692,7 @@ class NspawnMachine(BaseMachine):
stdout=subprocess.PIPE,
)
self.pid = self.process.pid
self.log(f"systemd-nspawn running (pid {self.pid})")
self.log(f"systemd-nspawn running (pid {self.process.pid})")
journal_thread = threading.Thread(target=self._stream_journal, daemon=True)
journal_thread.start()