:param chan: SSH channel with opened terminal.
:param cmd: Command to be executed.
:param prompt: Command prompt, sequence of characters used to
- indicate readiness to accept commands.
+ indicate readiness to accept commands.
:returns: Command output.
.. warning:: Interruptingcow is used here, and it uses
connect() method has to be called first!
:param local_path: Path to local file that should be uploaded; or
- path where to save remote file.
+ path where to save remote file.
:param remote_path: Remote path where to place uploaded file; or
- path to remote file which should be downloaded.
+ path to remote file which should be downloaded.
:param get: scp operation to perform. Default is put.
:param timeout: Timeout value in seconds.
:param wildcard: If path has wildcard characters. Default is false.
logger.trace(f"SCP took {end-start} seconds")
-def exec_cmd(node, cmd, timeout=600, sudo=False, disconnect=False):
+def exec_cmd(
+ node, cmd, timeout=600, sudo=False, disconnect=False,
+ log_stdout_err=True):
"""Convenience function to ssh/exec/return rc, out & err.
Returns (rc, stdout, stderr).
:param timeout: Timeout value in seconds. Default: 600.
:param sudo: Sudo privilege execution flag. Default: False.
:param disconnect: Close the opened SSH connection if True.
+ :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 node: dict
:type cmd: str or OptionString
:type timeout: int
:type sudo: bool
:type disconnect: bool
+ :type log_stdout_err: bool
:returns: RC, Stdout, Stderr.
:rtype: tuple(int, str, str)
"""
try:
if not sudo:
- ret_code, stdout, stderr = ssh.exec_command(cmd, timeout=timeout)
+ ret_code, stdout, stderr = ssh.exec_command(
+ cmd, timeout=timeout, log_stdout_err=log_stdout_err
+ )
else:
ret_code, stdout, stderr = ssh.exec_command_sudo(
- cmd, timeout=timeout
+ cmd, timeout=timeout, log_stdout_err=log_stdout_err
)
except SSHException as err:
logger.error(repr(err))
def exec_cmd_no_error(
node, cmd, timeout=600, sudo=False, message=None, disconnect=False,
- retries=0, include_reason=False):
+ retries=0, include_reason=False, log_stdout_err=True):
"""Convenience function to ssh/exec/return out & err.
Verifies that return code is zero.
:param disconnect: Close the opened SSH connection if True.
:param retries: How many times to retry on failure.
:param include_reason: Whether default info should be appended to message.
+ :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 node: dict
:type cmd: str or OptionString
:type timeout: int
:type disconnect: bool
:type retries: int
:type include_reason: bool
+ :type log_stdout_err: bool
:returns: Stdout, Stderr.
:rtype: tuple(str, str)
:raises RuntimeError: If bash return code is not 0.
"""
for _ in range(retries + 1):
ret_code, stdout, stderr = exec_cmd(
- node, cmd, timeout=timeout, sudo=sudo, disconnect=disconnect
+ node, cmd, timeout=timeout, sudo=sudo, disconnect=disconnect,
+ log_stdout_err=log_stdout_err
)
if ret_code == 0:
break