From ffa0dc3ce8ca264bf5efa8ea2dc4df48830a404e Mon Sep 17 00:00:00 2001 From: lguohan Date: Thu, 16 Jul 2020 17:18:38 -0700 Subject: [PATCH] [vstest]: clean up processes in server namespace at start (#1353) Signed-off-by: Guohan Lu --- tests/conftest.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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):