diff --git a/tests/conftest.py b/tests/conftest.py index 577d5602a65b..26aed021ab04 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -109,6 +109,7 @@ def __init__(self, ctn_name, pid, i): # create netns if os.path.exists("/var/run/netns/%s" % self.nsname): + self.killall_processes() self.cleanup = False else: ensure_system("ip netns add %s" % self.nsname) @@ -130,13 +131,16 @@ def __init__(self, ctn_name, pid, i): ensure_system("nsenter -t %d -n ip link set arp off dev %s" % (pid, self.pifname)) ensure_system("nsenter -t %d -n sysctl -w net.ipv6.conf.%s.disable_ipv6=1" % (pid, self.pifname)) + def killall_processes(self): + pids = subprocess.check_output("ip netns pids %s" % (self.nsname), shell=True).decode('utf-8') + if pids: + for pid in pids.split('\n'): + if len(pid) > 0: + os.system("kill %s" % int(pid)) + def destroy(self): if self.cleanup: - pids = subprocess.check_output("ip netns pids %s" % (self.nsname), shell=True) - if pids: - for pid in pids.split('\n'): - if len(pid) > 0: - os.system("kill %s" % int(pid)) + self.killall_processes() ensure_system("ip netns delete %s" % self.nsname) def runcmd(self, cmd):