Skip to content

Commit

Permalink
test: netns: Poll for MACVLAN removal completion
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wkz committed Nov 4, 2024
1 parent fbcf934 commit f6b24d9
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/infamy/netns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ctypes
import json
import multiprocessing
import os
import random
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f6b24d9

Please sign in to comment.