aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/ssh.py
diff options
context:
space:
mode:
authorPeter Mikus <pmikus@cisco.com>2019-02-06 16:15:58 +0000
committerJan Gelety <jgelety@cisco.com>2019-03-08 03:17:00 +0100
commit267eace4ff3200a7fa734d765d2b8c9ae3620e0e (patch)
treec909bddf701916a145dd1a640edb08853386bfcd /resources/libraries/python/ssh.py
parent06da48b3a9714e0eea684a2e4e9c63c0232b7bce (diff)
CSIT-845 Capture VPP core-dump from vpp crash on DUTsrls1901
Change-Id: I987dcd5092d8527c9aefbe093e1ed7ae144d191b Signed-off-by: Peter Mikus <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/python/ssh.py')
-rw-r--r--resources/libraries/python/ssh.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py
index a23d163768..60f62561be 100644
--- a/resources/libraries/python/ssh.py
+++ b/resources/libraries/python/ssh.py
@@ -22,7 +22,7 @@ from time import time, sleep
from paramiko import RSAKey, SSHClient, AutoAddPolicy
from paramiko.ssh_exception import SSHException, NoValidConnectionsError
from robot.api import logger
-from scp import SCPClient
+from scp import SCPClient, SCPException
__all__ = ["exec_cmd", "exec_cmd_no_error"]
@@ -467,3 +467,33 @@ def exec_cmd_no_error(node, cmd, timeout=600, sudo=False, message=None):
raise RuntimeError(msg)
return stdout, stderr
+
+def scp_node(node, local_path, remote_path, get=False, timeout=30):
+ """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.
+ :type node: dict
+ :type local_path: str
+ :type remote_path: str
+ :type get: bool
+ :type timeout: int
+ :raises RuntimeError: If SSH connection failed or SCP transfer failed.
+ """
+ ssh = SSH()
+
+ try:
+ ssh.connect(node)
+ except SSHException:
+ raise RuntimeError('Failed to connect to {host}!'
+ .format(host=node['host']))
+ try:
+ ssh.scp(local_path, remote_path, get, timeout)
+ except SCPException:
+ raise RuntimeError('SCP execution failed on {host}!'
+ .format(host=node['host']))