#!/usr/bin/python # Copyright 2011 Lars Wirzenius # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import cliapp import imp import logging import os import re import subprocess import unittest import systest class SystemTest(cliapp.Application): def add_settings(self): self.settings.string(['target'], 'target domain name or IP address') self.settings.integer(['ssh-port'], 'target ssh port', default=22) self.settings.string(['user'], 'user on target') self.settings.string(['user-password'], 'password for target user') self.settings.string(['user-ssh-private-key'], 'user\'s private key for logging in') def process_args(self, args): loader = unittest.defaultTestLoader loader.suiteClass = self.create_suite suite = unittest.TestSuite() for filename in args: module = self.load_module(filename) suite.addTest(loader.loadTestsFromModule(module)) unittest.TextTestRunner().run(suite) def create_suite(self, tests): for test in tests: test.settings = self.settings suite = unittest.TestSuite(tests) return suite def load_module(self, filename): for t in imp.get_suffixes(): suffix, mode, kind = t if filename.endswith(suffix): module_name = os.path.basename(filename[:-len(suffix)]) with open(filename, mode) as f: return imp.load_module(module_name, f, filename, t) raise Exception("Unknown module: %s" % filename) if __name__ == '__main__': SystemTest().run()