When we submit a client job in autotest server, only
client code will be copied to test machine, importing
modules in server code would fail.
This patch redefines a SSHHost() function if fail to
import SSHHost module from autotest.server

---
Tested in autotest server.

Changes from v1:
- fix typo

Signed-off-by: Amos Kong <[email protected]>
---
 client/virt/tests/netperf.py |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/client/virt/tests/netperf.py b/client/virt/tests/netperf.py
index 5fcb2f1..136a180 100644
--- a/client/virt/tests/netperf.py
+++ b/client/virt/tests/netperf.py
@@ -3,7 +3,20 @@ from autotest.client.shared import error
 from autotest.client import utils
 from autotest.client.virt import aexpect, virt_utils
 from autotest.client.virt import virt_test_utils
-from autotest.server.hosts.ssh_host import SSHHost
+try:
+    from autotest.server.hosts.ssh_host import SSHHost
+except ImportError:
+    pubkey = "%s/.ssh/id_dsa.pub" % os.environ['HOME']
+    if not os.path.exists(os.path.expandvars(pubkey)):
+        commands.getoutput('yes ""|ssh-keygen -t dsa -q -N ""')
+    def SSHHost(ip, user, port, password):
+        session = virt_utils.wait_for_login("ssh", ip, port, user, password,
+                                            "^\[.*\][\#\$]\s*$")
+        k = open(pubkey, "r")
+        session.cmd('echo "%s" >> ~/.ssh/authorized_keys' % k.read())
+        k.close()
+        session.close()
+
 
 def run_netperf(test, params, env):
     """

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to