summaryrefslogtreecommitdiff
path: root/systest.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-06-28 20:39:48 +0100
committerLars Wirzenius <liw@liw.fi>2011-06-28 20:39:48 +0100
commit1d6b71ef69a3a26d2649c2856fed423ac8261d21 (patch)
tree5018ec1f4c4ecdaf5685ed6c9f84a26b7780ccb3 /systest.py
parentbcf4e09e46f5b0e4c570c34e39b08a71ae123e80 (diff)
downloadsystest-1d6b71ef69a3a26d2649c2856fed423ac8261d21.tar.gz
Add logging and find_port_commands to systest.TestCase.
Diffstat (limited to 'systest.py')
-rwxr-xr-xsystest.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/systest.py b/systest.py
index 028480a..b514a12 100755
--- a/systest.py
+++ b/systest.py
@@ -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]
+