mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-05 21:03:40 +00:00
nixos-test-driver: fix vlan/bridge cleanup (#515874)
This commit is contained in:
@@ -1495,6 +1495,17 @@ class NspawnMachine(BaseMachine):
|
||||
self.logger.info(f"kill NspawnMachine (pid {self.pid})")
|
||||
assert self.process is not None
|
||||
self.process.terminate()
|
||||
# Wait for the wrapper to finish its context-manager cleanups
|
||||
# (veth/bridge/netns teardown) before returning, so the driver's
|
||||
# subsequent vlan teardown does not race against it.
|
||||
try:
|
||||
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"
|
||||
)
|
||||
self.process.kill()
|
||||
self.process.wait()
|
||||
self.process = None
|
||||
|
||||
def is_up(self) -> bool:
|
||||
|
||||
@@ -101,8 +101,17 @@ def ensure_vlan_bridge(vlan: int) -> typing.Generator[str, None, None]:
|
||||
# releasing this vlan, grab an exclusive lock.
|
||||
with vlan_lock(vlan):
|
||||
if bridge_path.exists():
|
||||
child_intf_count = len(list((bridge_path / "brif").iterdir()))
|
||||
if child_intf_count == 0:
|
||||
# The VDE tap is owned by the test driver's vde_plug2tap
|
||||
# and shares its lifetime with the vlan, not with any
|
||||
# container. Don't count it when deciding whether the
|
||||
# bridge is still in use, otherwise the bridge would
|
||||
# never be deleted as long as vde_plug2tap is alive.
|
||||
child_intfs = [
|
||||
p.name
|
||||
for p in (bridge_path / "brif").iterdir()
|
||||
if p.name != tap_name
|
||||
]
|
||||
if not child_intfs:
|
||||
logger.info("deleting bridge %s", bridge_name)
|
||||
run_ip("link", "delete", bridge_name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user