X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fssh.py;h=6ddf327f213cd4ee8a850fcdfb200915b0c7daf5;hb=6d7314e986c6359b59198d155a7baa31891e888f;hp=8ac3eaa3ad2665ab77b238e49a930d34ff994e7d;hpb=4d301304687229c841c15e325474ad946d883ff0;p=yardstick.git diff --git a/yardstick/ssh.py b/yardstick/ssh.py index 8ac3eaa3a..6ddf327f2 100644 --- a/yardstick/ssh.py +++ b/yardstick/ssh.py @@ -64,6 +64,7 @@ Eventlet: """ from __future__ import absolute_import import os +import io import select import socket import time @@ -81,6 +82,14 @@ from yardstick.common.utils import try_int from yardstick.network_services.utils import provision_tool +def convert_key_to_str(key): + if not isinstance(key, (paramiko.RSAKey, paramiko.DSSKey)): + return key + k = io.StringIO() + key.write_private_key(k) + return k.getvalue() + + class SSHError(Exception): pass @@ -370,6 +379,12 @@ class SSH(object): with SCPClient(client.get_transport()) as scp: scp.put(files, remote_path, recursive) + def get(self, remote_path, local_path='/tmp/', recursive=True): + client = self._get_client() + + with SCPClient(client.get_transport()) as scp: + scp.get(remote_path, local_path, recursive) + # keep shell running in the background, e.g. screen def send_command(self, command): client = self._get_client() @@ -423,11 +438,18 @@ class SSH(object): if mode is not None: sftp.chmod(remotepath, mode) + def get_file_obj(self, remotepath, file_obj): + client = self._get_client() + + with client.open_sftp() as sftp: + sftp.getfo(remotepath, file_obj) + class AutoConnectSSH(SSH): + # always wait or we will get OpenStack SSH errors def __init__(self, user, host, port=None, pkey=None, - key_filename=None, password=None, name=None, wait=False): + key_filename=None, password=None, name=None, wait=True): super(AutoConnectSSH, self).__init__(user, host, port, pkey, key_filename, password, name) self._wait = wait @@ -471,6 +493,10 @@ class AutoConnectSSH(SSH): self._connect() return super(AutoConnectSSH, self).put_file_obj(file_obj, remote_path, mode) + def get_file_obj(self, remote_path, file_obj): + self._connect() + return super(AutoConnectSSH, self).get_file_obj(remote_path, file_obj) + def provision_tool(self, tool_path, tool_file=None): self._connect() return super(AutoConnectSSH, self).provision_tool(tool_path, tool_file)