-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathes_ibs_log.py
executable file
·290 lines (260 loc) · 10.7 KB
/
es_ibs_log.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/env python3
from __future__ import print_function
from hashlib import sha1
import os, json, datetime, sys, copy, re
from glob import glob
from os.path import exists, dirname, getmtime
from es_utils import send_payload
from _py2with3compatibility import run_cmd
from cmsutils import cmsswIB2Week
from logreaderUtils import transform_and_write_config_file, add_exception_to_config, ResultTypeEnum
import traceback
def sha1hexdigest(data):
return sha1(data.encode()).hexdigest()
def send_unittest_dataset(datasets, payload, id, index, doc):
for ds in datasets:
print("Processing ", ds)
if not "root://" in ds:
continue
ds_items = ds.split("?", 1)
ds_items.append("")
ibeos = "/store/user/cmsbuild"
if ibeos in ds_items[0]:
ds_items[0] = ds_items[0].replace(ibeos, "")
else:
ibeos = ""
payload["protocol"] = ds_items[0].split("/store/", 1)[0] + ibeos
payload["protocol_opts"] = ds_items[1]
payload["lfn"] = "/store/" + ds_items[0].split("/store/", 1)[1].strip()
print("Sending", index, doc, sha1hexdigest(id + ds), json.dumps(payload))
send_payload(index, doc, sha1hexdigest(id + ds), json.dumps(payload))
def process_unittest_log(logFile):
t = getmtime(logFile)
timestp = int(t * 1000)
pathInfo = logFile.split("/")
architecture = pathInfo[4]
release = pathInfo[8]
week, rel_sec = cmsswIB2Week(release)
es_index = "ibs-" + week
package = pathInfo[-3] + "/" + pathInfo[-2]
payload_dataset = {"type": "unittest"}
payload_dataset["release"] = release
release_queue = "_".join(release.split("_", -1)[:-1]).split("_", 3)
payload_dataset["release_queue"] = "_".join(release_queue[0:3])
flavor = release_queue[-1]
if flavor == "X":
flavor = "DEFAULT"
payload_dataset["flavor"] = flavor
payload_dataset["architecture"] = architecture
payload_dataset["@timestamp"] = timestp
payload_utest = copy.deepcopy(payload_dataset)
del payload_utest["type"]
inStacktrace = False
stacktrace = []
datasets = []
config_list = []
custom_rule_set = [
{
"str_to_match": "test (.*) had ERRORS",
"name": "{0} failed",
"control_type": ResultTypeEnum.ISSUE,
},
{
"str_to_match": r'===== Test "([^\s]+)" ====',
"name": "{0}",
"control_type": ResultTypeEnum.TEST,
},
]
pkgTestStartRe = re.compile('^===== Test\s+"([^\s]+)" ====')
pkgTestEndRe = re.compile(r"^\^\^\^\^ End Test\s+([^\s]+)\s+\^\^\^\^")
pkgTestResultRe = re.compile(".*---> test\s+([^\s]+)\s+(had ERRORS|succeeded)")
with open(logFile, encoding="ascii", errors="ignore") as f:
utname = None
datasets = []
test_status = 0
for index, l in enumerate(f):
l = l.strip()
config_list = add_exception_to_config(l, index, config_list, custom_rule_set)
if m := pkgTestStartRe.match(l):
utname = m[1]
test_status = 0
datasets = []
continue
if m := pkgTestResultRe.match(l):
if m[1] != utname:
print(
"ERROR: Unit test name mismatch - expected {0}, got {1}".format(
utname, m[1]
)
) # TODO: do we want a more visible error (exit 1)? Or maybe skip this file?
else:
test_status = 1 if m[2] == "had ERRORS" else 0
continue
if m := pkgTestEndRe.match(l):
if m[1] != utname:
print(
"ERROR: Unit test name mismatch - expected {0}, got {1}".format(
utname, m[1]
)
) # TODO: do we want a more visible error (exit 1)? Or maybe skip this file?
continue
if test_status == -1:
print("ERROR: test state for UT {0} unknown".format(utname))
continue
payload_utest["url"] = (
"https://cmssdt.cern.ch/SDT/cgi-bin/buildlogs/"
+ architecture
+ "/"
+ release
+ "/unitTestLogs/"
+ package
)
payload_utest["status"] = test_status
payload_utest["name"] = utname
payload_utest["package"] = package
if stacktrace:
payload_utest["stacktrace"] = "\n".join(stacktrace)
stacktrace = []
utest_id = sha1hexdigest(release + architecture + utname)
print("==> ", json.dumps(payload_utest) + "\n")
send_payload(es_index, "unittests", utest_id, json.dumps(payload_utest))
payload_dataset["name"] = "%s/%s" % (package, utname)
dataset_id = sha1hexdigest(release + architecture + package + utname)
print("==> ", json.dumps(payload_dataset) + "\n")
send_unittest_dataset(
datasets, payload_dataset, dataset_id, "ib-dataset-" + week, "unittest-dataset"
)
continue
if " Initiating request to open file " in l:
try:
rootfile = l.split(" Initiating request to open file ")[1].split(" ")[0]
if (not "file:" in rootfile) and (not rootfile in datasets):
datasets.append(rootfile)
except Exception as e:
print("ERROR: ", logFile, e)
traceback.print_exc(file=sys.stdout)
continue
if "sig_dostack_then_abort" in l:
inStacktrace = True
continue
if inStacktrace and not l.startswith("#"):
inStacktrace = False
continue
if inStacktrace:
if len(stacktrace) < 20:
stacktrace.append(l)
continue
transform_and_write_config_file(logFile + "-read_config", config_list)
return
def process_addon_log(logFile):
t = getmtime(logFile)
timestp = int(t * 1000)
pathInfo = logFile.split("/")
architecture = pathInfo[4]
release = pathInfo[8]
week, rel_sec = cmsswIB2Week(release)
datasets = []
payload = {"type": "addon"}
payload["release"] = release
payload["architecture"] = architecture
payload["@timestamp"] = timestp
payload["name"] = pathInfo[-1].split("-")[1].split("_cmsRun_")[0].split("_cmsDriver.py_")[0]
id = sha1hexdigest(release + architecture + "addon" + payload["name"])
config_list = []
with open(logFile, encoding="ascii", errors="ignore") as f:
for index, l in enumerate(f):
l = l.strip()
config_list = add_exception_to_config(l, index, config_list)
if " Initiating request to open file " in l:
try:
rootfile = l.split(" Initiating request to open file ")[1].split(" ")[0]
if (not "file:" in rootfile) and (not rootfile in datasets):
datasets.append(rootfile)
except:
pass
send_unittest_dataset(datasets, payload, id, "ib-dataset-" + week, "addon-dataset")
transform_and_write_config_file(logFile + "-read_config", config_list)
return
def process_hlt_log(logFile):
t = getmtime(logFile)
timestp = int(t * 1000)
pathInfo = logFile.split("/")
architecture = pathInfo[-2]
release = pathInfo[-3]
week, rel_sec = cmsswIB2Week(release)
datasets = []
payload = {"type": "hlt"}
payload["release"] = release
payload["architecture"] = architecture
payload["@timestamp"] = timestp
payload["name"] = pathInfo[-1][:-4]
id = sha1hexdigest(release + architecture + "hlt" + payload["name"])
with open(logFile, encoding="ascii", errors="ignore") as f:
for index, l in enumerate(f):
l = l.strip()
if " Initiating request to open file " in l:
try:
rootfile = l.split(" Initiating request to open file ")[1].split(" ")[0]
if (not "file:" in rootfile) and (not rootfile in datasets):
datasets.append(rootfile)
except:
pass
send_unittest_dataset(datasets, payload, id, "ib-dataset-" + week, "hlt-dataset")
return
logs = run_cmd("find /data/sdt/buildlogs -mindepth 6 -maxdepth 6 -name 'unitTestLogs.zip'")
logs = logs[1].split("\n")
# process zip log files
for logFile in logs:
flagFile = logFile + ".checked"
if not exists(flagFile):
utdir = dirname(logFile)
print("Working on ", logFile)
try:
err, utlogs = run_cmd(
"cd %s; rm -rf UT; mkdir UT; cd UT; unzip ../unitTestLogs.zip" % utdir
)
err, utlogs = run_cmd("find %s/UT -name 'unitTest.log' -type f" % utdir)
if not err:
for utlog in utlogs.split("\n"):
process_unittest_log(utlog)
run_cmd("touch %s" % flagFile)
except Exception as e:
print("ERROR: ", logFile, e)
traceback.print_exc(file=sys.stdout)
run_cmd("cd %s/UT ; zip -r ../unitTestLogs.zip ." % utdir)
run_cmd("rm -rf %s/UT" % utdir)
logs = run_cmd("find /data/sdt/buildlogs -mindepth 6 -maxdepth 6 -name 'addOnTests.zip'")
logs = logs[1].split("\n")
# process zip log files
for logFile in logs:
flagFile = logFile + ".checked"
if not exists(flagFile):
utdir = dirname(logFile)
print("Working on ", logFile)
try:
err, utlogs = run_cmd(
"cd %s; rm -rf AO; mkdir AO; cd AO; unzip ../addOnTests.zip" % utdir
)
err, utlogs = run_cmd("find %s/AO -name '*.log' -type f" % utdir)
if not err:
for utlog in utlogs.split("\n"):
process_addon_log(utlog)
run_cmd("touch %s" % flagFile)
except Exception as e:
print("ERROR:", e)
run_cmd("cd %s/AO ; zip -r ../addOnTests.zip ." % utdir)
run_cmd("rm -rf %s/AO" % utdir)
dirs = run_cmd(
"find /data/sdt/SDT/jenkins-artifacts/HLT-Validation -maxdepth 2 -mindepth 2 -type d"
)[1].split("\n")
for d in dirs:
flagFile = d + ".checked"
if exists(flagFile):
continue
for logFile in glob(d + "/*.log"):
print("Working on ", logFile)
try:
process_hlt_log(logFile)
except Exception as e:
print("ERROR:", e)
run_cmd("touch %s" % flagFile)