diff --git a/nixos/lib/test-driver/src/test_driver/machine/__init__.py b/nixos/lib/test-driver/src/test_driver/machine/__init__.py index 3dc4f1f8d171..790da705cf4f 100644 --- a/nixos/lib/test-driver/src/test_driver/machine/__init__.py +++ b/nixos/lib/test-driver/src/test_driver/machine/__init__.py @@ -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()