Skip to content

Commit

Permalink
[vstest]: clean up processes in server namespace at start (#1353)
Browse files Browse the repository at this point in the history
Signed-off-by: Guohan Lu <[email protected]>
  • Loading branch information
lguohan authored Jul 17, 2020
1 parent b16368c commit ffa0dc3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit ffa0dc3

Please sign in to comment.