Merge "Bug in NSB Prox ACL Test 4 Port"
[yardstick.git] / yardstick / ssh.py
index 8ac3eaa..e98ee98 100644 (file)
@@ -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
 
@@ -423,11 +432,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 +487,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)