diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-06-28 20:39:48 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-06-28 20:39:48 +0100 |
commit | 1d6b71ef69a3a26d2649c2856fed423ac8261d21 (patch) | |
tree | 5018ec1f4c4ecdaf5685ed6c9f84a26b7780ccb3 | |
parent | bcf4e09e46f5b0e4c570c34e39b08a71ae123e80 (diff) | |
download | systest-1d6b71ef69a3a26d2649c2856fed423ac8261d21.tar.gz |
Add logging and find_port_commands to systest.TestCase.
-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] + |