summaryrefslogtreecommitdiffstats
path: root/cts/lab/CTSlab.py.in
blob: bd990fda42360650dcfbc84719586acc99d099b9 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!@PYTHON@
""" Command-line interface to Pacemaker's Cluster Test Suite (CTS)
"""

__copyright__ = "Copyright 2001-2023 the Pacemaker project contributors"
__license__ = "GNU General Public License version 2 or later (GPLv2+) WITHOUT ANY WARRANTY"

import sys, signal, os

pdir = os.path.dirname(sys.path[0])
sys.path.insert(0, pdir) # So that things work from the source directory

try:
    from cts.CM_corosync  import *
    from cts.CTSaudits    import AuditList
    from cts.CTStests     import TestList
    from cts.CTSscenarios import *

    from pacemaker._cts.CTS import CtsLab
    from pacemaker._cts.logging import LogFactory
except ImportError as e:
    sys.stderr.write("abort: %s\n" % e)
    sys.stderr.write("check your install and PYTHONPATH; couldn't find cts libraries in:\n%s\n" %
                     ' '.join(sys.path))
    sys.exit(1)

# These are globals so they can be used by the signal handler.
scenario = None
LogFactory().add_stderr()


def sig_handler(signum, frame) :
    LogFactory().log("Interrupted by signal %d"%signum)
    if scenario: scenario.summarize()
    if signum == 15 :
        if scenario: scenario.TearDown()
        sys.exit(1)


def plural_s(n, uppercase=False):
    if n == 1:
        return ""
    elif uppercase:
        return "S"
    else:
        return "s"


if __name__ == '__main__':

    Environment = CtsLab(sys.argv[1:])
    NumIter = Environment["iterations"]
    Tests = []

    # Set the signal handler
    signal.signal(15, sig_handler)
    signal.signal(10, sig_handler)

    # Create the Cluster Manager object
    cm = None
    if Environment["Stack"] == "corosync 2+":
        cm = crm_corosync()
        
    else:
        LogFactory().log("Unknown stack: "+Environment["stack"])
        sys.exit(1)

    if Environment["TruncateLog"]:
        if Environment["OutputFile"] is None:
            LogFactory().log("Ignoring truncate request because no output file specified")
        else:
            LogFactory().log("Truncating %s" % Environment["OutputFile"])
            with open(Environment["OutputFile"], "w") as outputfile:
                outputfile.truncate(0)

    Audits = AuditList(cm)

    if Environment["ListTests"]:
        Tests = TestList(cm, Audits)
        LogFactory().log("Total %d tests"%len(Tests))
        for test in Tests :
            LogFactory().log(str(test.name));
        sys.exit(0)

    elif len(Environment["tests"]) == 0:
        Tests = TestList(cm, Audits)

    else:
        Chosen = Environment["tests"]
        for TestCase in Chosen:
           match = None

           for test in TestList(cm, Audits):
               if test.name == TestCase:
                   match = test

           if not match:
               LogFactory().log("--choose: No applicable/valid tests chosen")
               sys.exit(1)
           else:
               Tests.append(match)

    # Scenario selection
    if Environment["scenario"] == "basic-sanity":
        scenario = RandomTests(cm, [ BasicSanityCheck(Environment) ], Audits, Tests)

    elif Environment["scenario"] == "all-once":
        NumIter = len(Tests)
        scenario = AllOnce(
            cm, [ BootCluster(Environment) ], Audits, Tests)
    elif Environment["scenario"] == "sequence":
        scenario = Sequence(
            cm, [ BootCluster(Environment) ], Audits, Tests)
    elif Environment["scenario"] == "boot":
        scenario = Boot(cm, [ LeaveBooted(Environment)], Audits, [])
    else:
        scenario = RandomTests(
            cm, [ BootCluster(Environment) ], Audits, Tests)

    LogFactory().log(">>>>>>>>>>>>>>>> BEGINNING " + repr(NumIter) + " TEST" + plural_s(NumIter, True) + " ")
    LogFactory().log("Stack:                  %s (%s)" % (Environment["Stack"], Environment["Name"]))
    LogFactory().log("Schema:                 %s" % Environment["Schema"])
    LogFactory().log("Scenario:               %s" % scenario.__doc__)
    LogFactory().log("CTS Exerciser:          %s" % Environment["cts-exerciser"])
    LogFactory().log("CTS Logfile:            %s" % Environment["OutputFile"])
    LogFactory().log("Random Seed:            %s" % Environment["RandSeed"])
    LogFactory().log("Syslog variant:         %s" % Environment["syslogd"].strip())
    LogFactory().log("System log files:       %s" % Environment["LogFileName"])
    if Environment.has_key("IPBase"):
        LogFactory().log("Base IP for resources:  %s" % Environment["IPBase"])
    LogFactory().log("Cluster starts at boot: %d" % Environment["at-boot"])

    Environment.dump()
    rc = Environment.run(scenario, NumIter)
    sys.exit(rc)