Skip to content

Commit ffa0dc3

Browse files
authored
[vstest]: clean up processes in server namespace at start (sonic-net#1353)
Signed-off-by: Guohan Lu <lguohan@gmail.com>
1 parent b16368c commit ffa0dc3

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/conftest.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(self, ctn_name, pid, i):
109109

110110
# create netns
111111
if os.path.exists("/var/run/netns/%s" % self.nsname):
112+
self.killall_processes()
112113
self.cleanup = False
113114
else:
114115
ensure_system("ip netns add %s" % self.nsname)
@@ -130,13 +131,16 @@ def __init__(self, ctn_name, pid, i):
130131
ensure_system("nsenter -t %d -n ip link set arp off dev %s" % (pid, self.pifname))
131132
ensure_system("nsenter -t %d -n sysctl -w net.ipv6.conf.%s.disable_ipv6=1" % (pid, self.pifname))
132133

134+
def killall_processes(self):
135+
pids = subprocess.check_output("ip netns pids %s" % (self.nsname), shell=True).decode('utf-8')
136+
if pids:
137+
for pid in pids.split('\n'):
138+
if len(pid) > 0:
139+
os.system("kill %s" % int(pid))
140+
133141
def destroy(self):
134142
if self.cleanup:
135-
pids = subprocess.check_output("ip netns pids %s" % (self.nsname), shell=True)
136-
if pids:
137-
for pid in pids.split('\n'):
138-
if len(pid) > 0:
139-
os.system("kill %s" % int(pid))
143+
self.killall_processes()
140144
ensure_system("ip netns delete %s" % self.nsname)
141145

142146
def runcmd(self, cmd):

0 commit comments

Comments
 (0)