nixos-test-driver: fix vlan/bridge cleanup (#515874)

This commit is contained in:
Maximilian Bosch
2026-05-14 17:26:56 +00:00
committed by GitHub
2 changed files with 22 additions and 2 deletions

View File

@@ -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:

View File

@@ -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)