aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2019-06-10 10:40:12 +0200
committerTibor Frank <tifrank@cisco.com>2019-06-18 07:49:31 +0000
commit72ae46cda69c2f12efdbe731e37dce200a48f424 (patch)
treef988167ab4a51777fe2442aa8dbd7a6e6f13319d /resources/libraries/python
parent4e8fb0f0089c03e1bcb0f3cc66b24db15aab0412 (diff)
PAPI: Reduce the amount of logged information
Change-Id: I5cfd19a9ecca6891232d92d232a159422c0a835e Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/PapiExecutor.py2
-rw-r--r--resources/libraries/python/ssh.py31
2 files changed, 24 insertions, 9 deletions
diff --git a/resources/libraries/python/PapiExecutor.py b/resources/libraries/python/PapiExecutor.py
index 8261a5e331..e296e23c1f 100644
--- a/resources/libraries/python/PapiExecutor.py
+++ b/resources/libraries/python/PapiExecutor.py
@@ -501,7 +501,7 @@ class PapiExecutor(object):
json=json_data)
try:
ret_code, stdout, stderr = self._ssh.exec_command_sudo(
- cmd=cmd, timeout=timeout)
+ cmd=cmd, timeout=timeout, log_stdout_err=False)
except SSHTimeout:
logger.error("PAPI command(s) execution timeout on host {host}:"
"\n{apis}".format(host=self._node["host"],
diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py
index 9c7adc44e1..e89daf2915 100644
--- a/resources/libraries/python/ssh.py
+++ b/resources/libraries/python/ssh.py
@@ -140,17 +140,21 @@ class SSH(object):
logger.debug('Reconnecting peer done: {host}, {port}'.
format(host=node['host'], port=node['port']))
- def exec_command(self, cmd, timeout=10):
+ def exec_command(self, cmd, timeout=10, log_stdout_err=True):
"""Execute SSH command on a new channel on the connected Node.
:param cmd: Command to run on the Node.
:param timeout: Maximal time in seconds to wait until the command is
- done. If set to None then wait forever.
+ done. If set to None then wait forever.
+ :param log_stdout_err: If True, stdout and stderr are logged. stdout
+ and stderr are logged also if the return code is not zero
+ independently of the value of log_stdout_err.
:type cmd: str or OptionString
:type timeout: int
- :return return_code, stdout, stderr
+ :type log_stdout_err: bool
+ :returns: return_code, stdout, stderr
:rtype: tuple(int, str, str)
- :raise SSHTimeout: If command is not finished in timeout time.
+ :raises SSHTimeout: If command is not finished in timeout time.
"""
cmd = str(cmd)
stdout = StringIO.StringIO()
@@ -203,17 +207,27 @@ class SSH(object):
format(peer=peer, total=end-start))
logger.trace('return RC {rc}'.format(rc=return_code))
- logger.trace('return STDOUT {stdout}'.format(stdout=stdout.getvalue()))
- logger.trace('return STDERR {stderr}'.format(stderr=stderr.getvalue()))
+ if log_stdout_err or int(return_code):
+ logger.trace('return STDOUT {stdout}'.
+ format(stdout=stdout.getvalue()))
+ logger.trace('return STDERR {stderr}'.
+ format(stderr=stderr.getvalue()))
return return_code, stdout.getvalue(), stderr.getvalue()
- def exec_command_sudo(self, cmd, cmd_input=None, timeout=30):
+ def exec_command_sudo(self, cmd, cmd_input=None, timeout=30,
+ log_stdout_err=True):
"""Execute SSH command with sudo on a new channel on the connected Node.
:param cmd: Command to be executed.
:param cmd_input: Input redirected to the command.
:param timeout: Timeout.
+ :param log_stdout_err: If True, stdout and stderr are logged.
+ :type cmd: str
+ :type cmd_input: str
+ :type timeout: int
+ :type log_stdout_err: bool
:returns: return_code, stdout, stderr
+ :rtype: tuple(int, str, str)
:Example:
@@ -229,7 +243,8 @@ class SSH(object):
command = 'sudo -S {c}'.format(c=cmd)
else:
command = 'sudo -S {c} <<< "{i}"'.format(c=cmd, i=cmd_input)
- return self.exec_command(command, timeout)
+ return self.exec_command(command, timeout,
+ log_stdout_err=log_stdout_err)
def exec_command_lxc(self, lxc_cmd, lxc_name, lxc_params='', sudo=True,
timeout=30):