diff options
Diffstat (limited to 'systest.py')
-rwxr-xr-x | systest.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -25,6 +25,7 @@ the hostname of the target system. ''' +import logging import re import subprocess import unittest @@ -40,6 +41,7 @@ class TestCase(unittest.TestCase): ''' def runcmd(self, argv, stdin='', *args, **kwargs): + logging.debug('systest.TestCase.runcmd: argv=%s' % repr(argv)) p = subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE, @@ -57,7 +59,7 @@ class TestCase(unittest.TestCase): def targetcmd(self, argv, *args, **kwargs): '''Run command on test target.''' - full_argv = (['ssh', '-l', self.settings['user'], + full_argv = (['ssh', '-l', self.settings['user'], self.settings['target']] + argv) returncode, out, err = self.runcmd(full_argv, *args, **kwargs) @@ -70,3 +72,17 @@ class TestCase(unittest.TestCase): self.assert_(re.match(pat, text), msg=('pattern %s does not match %s' % (pat, text)) or msg) + def find_open_ports(self): + '''Return list of open ports. + + Each port is shown as '22/tcp', where '22' is the port number, + and 'tcp' indicates the TCP protocol. See nmap documentation for + more info on ports. + + ''' + + out = self.hostcmd(['nmap', self.settings['target']]) + return [line.split()[0] + for line in out.splitlines() + if ' open ' in line] + |