summaryrefslogtreecommitdiff
path: root/systest
blob: 577adc1283d8299a434dde70fcf07d6390ff73b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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 <http://www.gnu.org/licenses/>.

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()