From 1d6b71ef69a3a26d2649c2856fed423ac8261d21 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 28 Jun 2011 20:39:48 +0100 Subject: Add logging and find_port_commands to systest.TestCase. --- systest.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'systest.py') 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] + -- cgit v1.2.1