tests: remote host stderr workaround

In case we are using ssh MUX (which speed up a lot test execution) with
remotehost we could hit cases where ssh will hang up. This depends on
different ssh versions and remotehost implementation.

stderr as a tmpfile fixes this problem.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@gmail.com>
This commit is contained in:
Janusz Dziedzic 2020-09-26 13:26:53 +02:00 committed by Jouni Malinen
parent ac6595f281
commit fed855d5dd

View File

@ -7,6 +7,7 @@
import logging import logging
import subprocess import subprocess
import threading import threading
import tempfile
logger = logging.getLogger() logger = logging.getLogger()
@ -17,12 +18,15 @@ def remote_compatible(func):
def execute_thread(command, reply): def execute_thread(command, reply):
cmd = ' '.join(command) cmd = ' '.join(command)
logger.debug("thread run: " + cmd) logger.debug("thread run: " + cmd)
err = tempfile.TemporaryFile()
try: try:
status = 0 status = 0
buf = subprocess.check_output(command, stderr=subprocess.STDOUT).decode() buf = subprocess.check_output(command, stderr=err).decode()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
status = e.returncode status = e.returncode
buf = e.output err.seek(0)
buf = err.read()
err.close()
logger.debug("thread cmd: " + cmd) logger.debug("thread cmd: " + cmd)
logger.debug("thread exit status: " + str(status)) logger.debug("thread exit status: " + str(status))
@ -46,12 +50,15 @@ class Host():
def local_execute(self, command): def local_execute(self, command):
logger.debug("execute: " + str(command)) logger.debug("execute: " + str(command))
err = tempfile.TemporaryFile()
try: try:
status = 0 status = 0
buf = subprocess.check_output(command, stderr=subprocess.STDOUT) buf = subprocess.check_output(command, stderr=err)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
status = e.returncode status = e.returncode
buf = e.output err.seek(0)
buf = err.read()
err.close()
logger.debug("status: " + str(status)) logger.debug("status: " + str(status))
logger.debug("buf: " + str(buf)) logger.debug("buf: " + str(buf))
@ -64,12 +71,15 @@ class Host():
cmd = ["ssh", self.user + "@" + self.host, ' '.join(command)] cmd = ["ssh", self.user + "@" + self.host, ' '.join(command)]
_cmd = self.name + " execute: " + ' '.join(cmd) _cmd = self.name + " execute: " + ' '.join(cmd)
logger.debug(_cmd) logger.debug(_cmd)
err = tempfile.TemporaryFile()
try: try:
status = 0 status = 0
buf = subprocess.check_output(cmd, stderr=subprocess.STDOUT) buf = subprocess.check_output(cmd, stderr=err)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
status = e.returncode status = e.returncode
buf = e.output err.seek(0)
buf = err.read()
err.close()
logger.debug(self.name + " status: " + str(status)) logger.debug(self.name + " status: " + str(status))
logger.debug(self.name + " buf: " + str(buf)) logger.debug(self.name + " buf: " + str(buf))