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.
This commit is contained in:
Tobias Waldekranz
2024-11-04 14:42:31 +01:00
parent a4a4a49eae
commit be828d46c9
+22 -1
View File
@@ -1,4 +1,5 @@
import ctypes
import json
import multiprocessing
import os
import random
@@ -87,9 +88,29 @@ class IsolatedMacVlans:
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()