On Thu, Apr 26, 2012 at 2:22 AM, Amos Kong <[email protected]> wrote: > 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() > + ^ I forgot to comment on that.
I don't like the fact that SSHHost is a class on server, but you replace it with a callable if that can't be imported. It's an interface change potentially dangerous, if other users try to use this object in some unpredicted ways. So I'd rewrite a small SSHHost class with only the bare minimum to make it work, as you have done mostly with this patch. _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
