-
Notifications
You must be signed in to change notification settings - Fork 10
/
test-all.py
executable file
·216 lines (179 loc) · 5.34 KB
/
test-all.py
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/python
import os
import re
import sys
import argparse
import subprocess
from glob import glob
from tempfile import mkdtemp
from mlxredmine import MlxRedmine
MYNAME = os.path.basename(__file__)
MYDIR = os.path.abspath(os.path.dirname(__file__))
LOGDIR = mkdtemp(prefix='log')
TESTS = sorted(glob(MYDIR + '/test-*'))
IGNORE_TESTS = [MYNAME]
SKIP_TESTS = {
"test-eswitch-add-del-flows-during-flows-cleanup.sh": "RM #1013092",
"test-eswitch-no-carrier.sh": "RM #1124753",
"test-ovs-vxlan-in-ns-hw.sh": "Not a valid test?",
"test-tc-replace.sh": "RM #988519",
}
COLOURS = {
"black": 30,
"red": 31,
"green": 32,
"yellow": 33,
"blue": 34,
"magenta": 25,
"cyan": 36,
"light-gray": 37,
"dark-gray": 90,
"light-red": 91,
"light-green": 92,
"light-yellow": 93,
"light-blue": 94,
"light-magenta": 95,
"light-cyan": 96,
"white": 97,
}
class ExecCmdFailed(Exception):
def __init__(self, cmd, rc, logname):
self._cmd = cmd
self._rc = rc
self._logname = logname
def __str__(self):
retval = "(exited with %d)" % self._rc
return "Command execution failed %s: %s" % (retval, self._logname)
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', action='store_true',
help='verbose output')
parser.add_argument('--stop', '-s', action='store_true',
help='stop on first error')
parser.add_argument('--dry', '-d', action='store_true',
help='not to actually run the test')
parser.add_argument('--from_test', '-f',
help='start from test')
parser.add_argument('--exclude', '-e', action='append',
help='exclude test')
parser.add_argument('--glob', '-g',
help='glob of tests')
parser.add_argument('--parm', '-p',
help='Pass parm to each test')
args = parser.parse_args()
return args
def run_test(cmd):
logname = os.path.join(LOGDIR, os.path.basename(cmd)+'.log')
with open(logname, 'w') as f1:
# piping stdout to file seems to miss stderr msgs to we use pipe
# and write to file at the end.
subp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, close_fds=True)
out = subp.communicate()
f1.write(out[0])
if subp.returncode:
err = ExecCmdFailed(cmd, subp.returncode, logname)
raise err
return out
def deco(line, color):
return "\033[%dm%s\033[0m" % (COLOURS[color], line)
def print_result(res, out):
res_color = {
'SKIP': 'yellow',
'OK': 'green',
'DRY': 'yellow',
'FAILED': 'red',
'IGNORED': 'yellow',
}
color = res_color.get(res, 'red')
cres = deco(res, color)
if out:
if res == 'SKIP':
out = ' (%s)' % out
else:
out = '\n%s' % out
cres += deco(out, color)
print cres
def glob_tests(args, tests):
if not args.glob:
return
from fnmatch import fnmatch
for test in tests[:]:
name = os.path.basename(test)
if not fnmatch(name, args.glob):
tests.remove(test)
def update_skip_according_to_rm():
global SKIP_TESTS
print "Check redmine for open issues"
rm = MlxRedmine()
SKIP_TESTS = {}
for t in TESTS:
with open(t) as f:
data = f.read()
t = os.path.basename(t)
bugs = re.findall("Bug SW #([0-9]+):", data)
for b in bugs:
task = rm.get_issue(b)
if rm.is_issue_open(task):
SKIP_TESTS[t] = "RM #%s: %s" % (b, task['subject'])
print '.',
sys.stdout.flush()
print
def should_ignore_test(name):
if name in IGNORE_TESTS or name in ' '.join(IGNORE_TESTS):
return True
else:
return False
def main():
args = parse_args()
ignore = False
if args.from_test:
ignore = True
if args.exclude:
IGNORE_TESTS.extend(args.exclude)
glob_tests(args, TESTS)
print "Log dir: " + LOGDIR
try:
update_skip_according_to_rm()
except KeyboardInterrupt:
print 'Interrupted'
sys.exit(1)
tests_results = []
for test in TESTS:
name = os.path.basename(test)
if name == MYNAME:
continue
if ignore:
if args.from_test != name:
continue
ignore = False
print "Test: %-60s " % deco(name, 'blue'),
sys.stdout.flush()
failed = False
res = 'OK'
out = ''
if should_ignore_test(name):
res = 'IGNORED'
elif name in SKIP_TESTS:
res = 'SKIP'
out = SKIP_TESTS[name]
elif args.dry:
res = 'DRY'
else:
try:
cmd = test
if args.parm:
cmd += ' ' + args.parm
run_test(cmd)
except ExecCmdFailed, e:
failed = True
res = 'FAILED'
out = str(e)
except KeyboardInterrupt:
print 'Interrupted'
sys.exit(1)
print_result(res, out)
if args.stop and failed:
sys.exit(1)
if __name__ == "__main__":
main()