summaryrefslogtreecommitdiff
path: root/systest.py
diff options
context:
space:
mode:
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)