Skip to content

Commit 36e304d

Browse files
authored
[vstest]: print output when runcmd returns error (sonic-net#672)
* [vstest]: print output when runcmd returns error Signed-off-by: Guohan Lu <[email protected]>
1 parent aede5d4 commit 36e304d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/conftest.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ def destroy(self):
123123
ensure_system("ip netns delete %s" % self.nsname)
124124

125125
def runcmd(self, cmd):
126-
return os.system("ip netns exec %s %s" % (self.nsname, cmd))
126+
try:
127+
out = subprocess.check_output("ip netns exec %s %s" % (self.nsname, cmd), stderr=subprocess.STDOUT, shell=True)
128+
except subprocess.CalledProcessError as e:
129+
print "------rc={} for cmd: {}------".format(e.returncode, e.cmd)
130+
print e.output.rstrip()
131+
print "------"
132+
return e.returncode
133+
return 0
127134

128135
def runcmd_async(self, cmd):
129136
return subprocess.Popen("ip netns exec %s %s" % (self.nsname, cmd), shell=True)
@@ -294,6 +301,11 @@ def runcmd(self, cmd):
294301
except AttributeError:
295302
exitcode = 0
296303
out = res
304+
if exitcode != 0:
305+
print "-----rc={} for cmd {}-----".format(exitcode, cmd)
306+
print out.rstrip()
307+
print "-----"
308+
297309
return (exitcode, out)
298310

299311
def copy_file(self, path, filename):

0 commit comments

Comments
 (0)