From f6b24d925262756cc7b0473f744392d5362aa640 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Mon, 4 Nov 2024 12:28:26 +0100 Subject: [PATCH] test: netns: Poll for MACVLAN removal completion Now that we're using the `passthru` mode of MACVLANs, it seems we can rely on the parent interface's promiscuity going down to 0 as an indication that the kernel has completed the removal of the interface, and will accept the creation of a new one. --- test/infamy/netns.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/infamy/netns.py b/test/infamy/netns.py index bb9b15fe..8c38acb8 100644 --- a/test/infamy/netns.py +++ b/test/infamy/netns.py @@ -1,4 +1,5 @@ import ctypes +import json import multiprocessing import os import random @@ -87,9 +88,29 @@ def start(self): def stop(self): self.sleeper.kill() self.sleeper.wait() + + for n in range(100): + promisc = False + for parent in self.ifmap.keys(): + iplink = subprocess.run(f"ip -d -j link show dev {parent}".split(), + stdout=subprocess.PIPE, check=True) + link = json.loads(iplink.stdout)[0] + if link["promiscuity"]: + # Use promisc as a substitute for an indicator + # of whether the kernel has actually removed + # the passthru MACVLAN yet or not + promisc = True + break + + if not promisc: + break + + time.sleep(.1) + else: + raise TimeoutError("Lingering MACVLAN") + if self in self.Instances: self.Instances.remove(self) - time.sleep(0.5) def __enter__(self): return self.start()