Skip to content

Commit

Permalink
[vstest]: print output when runcmd returns error (#672)
Browse files Browse the repository at this point in the history
* [vstest]: print output when runcmd returns error

Signed-off-by: Guohan Lu <gulv@microsoft.com>
  • Loading branch information
lguohan committed Nov 5, 2018
1 parent aede5d4 commit 36e304d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ def destroy(self):
ensure_system("ip netns delete %s" % self.nsname)

def runcmd(self, cmd):
return os.system("ip netns exec %s %s" % (self.nsname, cmd))
try:
out = subprocess.check_output("ip netns exec %s %s" % (self.nsname, cmd), stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as e:
print "------rc={} for cmd: {}------".format(e.returncode, e.cmd)
print e.output.rstrip()
print "------"
return e.returncode
return 0

def runcmd_async(self, cmd):
return subprocess.Popen("ip netns exec %s %s" % (self.nsname, cmd), shell=True)
Expand Down Expand Up @@ -294,6 +301,11 @@ def runcmd(self, cmd):
except AttributeError:
exitcode = 0
out = res
if exitcode != 0:
print "-----rc={} for cmd {}-----".format(exitcode, cmd)
print out.rstrip()
print "-----"

return (exitcode, out)

def copy_file(self, path, filename):
Expand Down

0 comments on commit 36e304d

Please sign in to comment.