mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
nixos/test-driver: fix resource cleanup of vlan/qmp objects
Using __del__ is somewhat unsound resource cleanup in our clase the logger already closed its logfile and therefor fails with exception before the rest of the resources can be cleaned up.
This commit is contained in:
parent
8e125ab277
commit
ef9502a009
@ -99,7 +99,16 @@ class Driver:
|
|||||||
with self.logger.nested("cleanup"):
|
with self.logger.nested("cleanup"):
|
||||||
self.race_timer.cancel()
|
self.race_timer.cancel()
|
||||||
for machine in self.machines:
|
for machine in self.machines:
|
||||||
machine.release()
|
try:
|
||||||
|
machine.release()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"Error during cleanup of {machine.name}: {e}")
|
||||||
|
|
||||||
|
for vlan in self.vlans:
|
||||||
|
try:
|
||||||
|
vlan.stop()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"Error during cleanup of vlan{vlan.nr}: {e}")
|
||||||
|
|
||||||
def subtest(self, name: str) -> Iterator[None]:
|
def subtest(self, name: str) -> Iterator[None]:
|
||||||
"""Group logs under a given test name"""
|
"""Group logs under a given test name"""
|
||||||
|
@ -1234,6 +1234,9 @@ class Machine:
|
|||||||
self.monitor.close()
|
self.monitor.close()
|
||||||
self.serial_thread.join()
|
self.serial_thread.join()
|
||||||
|
|
||||||
|
if self.qmp_client:
|
||||||
|
self.qmp_client.close()
|
||||||
|
|
||||||
def run_callbacks(self) -> None:
|
def run_callbacks(self) -> None:
|
||||||
for callback in self.callbacks:
|
for callback in self.callbacks:
|
||||||
callback()
|
callback()
|
||||||
|
@ -49,7 +49,7 @@ class QMPSession:
|
|||||||
sock.connect(str(path))
|
sock.connect(str(path))
|
||||||
return cls(sock)
|
return cls(sock)
|
||||||
|
|
||||||
def __del__(self) -> None:
|
def close(self) -> None:
|
||||||
self.sock.close()
|
self.sock.close()
|
||||||
|
|
||||||
def _wait_for_new_result(self) -> dict[str, str]:
|
def _wait_for_new_result(self) -> dict[str, str]:
|
||||||
|
@ -59,7 +59,7 @@ class VLan:
|
|||||||
|
|
||||||
self.logger.info(f"running vlan (pid {self.pid}; ctl {self.socket_dir})")
|
self.logger.info(f"running vlan (pid {self.pid}; ctl {self.socket_dir})")
|
||||||
|
|
||||||
def __del__(self) -> None:
|
def stop(self) -> None:
|
||||||
self.logger.info(f"kill vlan (pid {self.pid})")
|
self.logger.info(f"kill vlan (pid {self.pid})")
|
||||||
self.fd.close()
|
self.fd.close()
|
||||||
self.process.terminate()
|
self.process.terminate()
|
||||||
|
Loading…
Reference in New Issue
Block a user