- (rc, stdout, stderr) = exec_cmd(node, cmd, timeout=timeout, sudo=sudo)
- assert_equal(rc, 0, 'Command execution failed: "{}"\n{}'.
- format(cmd, stderr))
- return (stdout, stderr)
+ for _ in range(retries + 1):
+ ret_code, stdout, stderr = exec_cmd(
+ node, cmd, timeout=timeout, sudo=sudo, disconnect=disconnect)
+ if ret_code == 0:
+ break
+ sleep(1)
+ else:
+ msg = 'Command execution failed: "{cmd}"\nRC: {rc}\n{stderr}'.format(
+ cmd=cmd, rc=ret_code, stderr=stderr)
+ logger.info(msg)
+ if message:
+ if include_reason:
+ msg = message + '\n' + msg
+ else:
+ msg = message
+ raise RuntimeError(msg)
+
+ return stdout, stderr
+
+
+def scp_node(
+ node, local_path, remote_path, get=False, timeout=30, disconnect=False):
+ """Copy files from local_path to remote_path or vice versa.
+
+ :param node: SUT node.
+ :param local_path: Path to local file that should be uploaded; or
+ 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.
+ :param get: scp operation to perform. Default is put.
+ :param timeout: Timeout value in seconds.
+ :param disconnect: Close the opened SSH connection if True.
+ :type node: dict
+ :type local_path: str
+ :type remote_path: str
+ :type get: bool
+ :type timeout: int
+ :type disconnect: bool
+ :raises RuntimeError: If SSH connection failed or SCP transfer failed.
+ """
+ ssh = SSH()
+
+ try:
+ ssh.connect(node)
+ except SSHException as exc:
+ raise_from(RuntimeError(
+ 'Failed to connect to {host}!'.format(host=node['host'])), exc)
+ try:
+ ssh.scp(local_path, remote_path, get, timeout)
+ except SCPException as exc:
+ raise_from(RuntimeError(
+ 'SCP execution failed on {host}!'.format(host=node['host'])), exc)
+ finally:
+ if disconnect:
+ ssh.disconnect()