summaryrefslogtreecommitdiff
path: root/systest.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-06-29 13:06:33 +0100
committerLars Wirzenius <liw@liw.fi>2011-06-29 13:06:33 +0100
commit99fabeafd4d6307c24437e1a35a626abc952c709 (patch)
tree5058db0244fd2943ba264dd14ddac4b4d46880e4 /systest.py
parent2850e67282fa59c2c99aa8d3d924b5306167fdf5 (diff)
downloadsystest-99fabeafd4d6307c24437e1a35a626abc952c709.tar.gz
Set up a known hosts file, and use provided ssh private key for logging in.HEADmaster
Diffstat (limited to 'systest.py')
-rwxr-xr-xsystest.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/systest.py b/systest.py
index bdcb3b6..4bfbcfb 100755
--- a/systest.py
+++ b/systest.py
@@ -26,8 +26,10 @@ the hostname of the target system.
import logging
+import os
import re
import subprocess
+import tempfile
import unittest
@@ -59,16 +61,32 @@ class TestCase(unittest.TestCase):
def targetcmd(self, argv, *args, **kwargs):
'''Run command on test target.'''
- full_argv = (['ssh', '-l', self.settings['user'],
- '-p', str(self.settings['ssh-port']),
- self.settings['target']] +
- argv)
- returncode, out, err = self.runcmd(full_argv, *args, **kwargs)
+
+ self.setup_known_hosts()
+
+ prefix = ['ssh',
+ '-l', self.settings['user'],
+ '-p', str(self.settings['ssh-port']),
+ '-o', 'UserKnownHostsFile %s' % self.known_hosts,
+ ]
+ if self.settings['user-ssh-private-key']:
+ prefix += ['-i', self.settings['user-ssh-private-key']]
+ prefix += [self.settings['target'], '--']
+
+ returncode, out, err = self.runcmd(prefix + argv, *args, **kwargs)
if returncode:
msg = 'target command failed: %s\n%s' % (' '.join(argv), err)
raise AssertionError(msg)
return out
+ def setup_known_hosts(self):
+ '''Setup a temporary known hosts file, and add target's key there.'''
+
+ fd, self.known_hosts = tempfile.mkstemp()
+ out = self.hostcmd(['ssh-keyscan', self.settings['target']])
+ os.write(fd, out)
+ os.close(fd)
+
def assertMatches(self, pat, text, msg=None):
self.assert_(re.match(pat, text),
msg=('pattern %s does not match %s' % (pat, text)) or msg)