Bugfix:fix a bug that yardstick_key.pub cannot be found in Yardstick docker
[yardstick.git] / yardstick / ssh.py
index 253fd2e..cf890df 100644 (file)
@@ -63,6 +63,7 @@ import socket
 import time
 
 import paramiko
+from scp import SCPClient
 import six
 import logging
 
@@ -120,7 +121,9 @@ class SSH(object):
             self._client.connect(self.host, username=self.user,
                                  port=self.port, pkey=self.pkey,
                                  key_filename=self.key_filename,
-                                 password=self.password, timeout=1)
+                                 password=self.password,
+                                 allow_agent=False, look_for_keys=False,
+                                 timeout=1)
             return self._client
         except Exception as e:
             message = ("Exception %(exception_type)s was raised "
@@ -254,3 +257,14 @@ class SSH(object):
                 time.sleep(interval)
             if time.time() > (start_time + timeout):
                 raise SSHTimeout("Timeout waiting for '%s'" % self.host)
+
+    def put(self, files, remote_path=b'.', recursive=False):
+        client = self._get_client()
+
+        with SCPClient(client.get_transport()) as scp:
+            scp.put(files, remote_path, recursive)
+
+    # keep shell running in the background, e.g. screen
+    def send_command(self, command):
+        client = self._get_client()
+        client.exec_command(command, get_pty=True)