From 36e304db4ab01ed9d75230b842ff44c1cda6b281 Mon Sep 17 00:00:00 2001 From: lguohan Date: Mon, 5 Nov 2018 12:30:36 -0800 Subject: [PATCH] [vstest]: print output when runcmd returns error (#672) * [vstest]: print output when runcmd returns error Signed-off-by: Guohan Lu --- tests/conftest.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index c1eb26e00a43..0c5cdda970d6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) @@ -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):