forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es_ibs_log.py
executable file
·167 lines (158 loc) · 6.11 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
#!/bin/env python
from hashlib import sha1
import os, sys,json , re , datetime
from os import getenv
from os.path import exists, dirname, getmtime
from time import strftime , strptime
from es_utils import send_payload
import commands
from cmsutils import cmsswIB2Week
def send_unittest_dataset(datasets, payload, id, index, doc):
for ds in datasets:
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]
send_payload(index, doc, sha1(id + ds).hexdigest(), 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)
package = pathInfo[-3]+"/"+ pathInfo[-2]
utname = None
datasets = []
payload = {"type" : "unittest"}
payload["release"]=release
payload["architecture"]=architecture
payload["@timestamp"]=timestp
id = None
for l in file(logFile).read().split("\n"):
if l.startswith('===== Test "') and l.endswith('" ===='):
if utname: send_unittest_dataset(datasets, payload, id, "ib-dataset-"+week, "unittest-dataset")
datasets = []
utname = l.split('"')[1]
payload["name"] = "%s/%s" % (package, utname)
id = sha1(release + architecture + package + str(utname)).hexdigest()
elif " 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
if datasets: send_unittest_dataset(datasets, payload, id, "ib-dataset-"+week,"unittest-dataset")
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 = sha1(release + architecture + "addon" + payload["name"]).hexdigest()
for l in file(logFile).read().split("\n"):
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")
return
def process_ib_utests(logFile):
t = getmtime(logFile)
timestp = datetime.datetime.fromtimestamp(int(t)).strftime('%Y-%m-%d %H:%M:%S')
payload = {}
pathInfo = logFile.split('/')
architecture = pathInfo[4]
release = pathInfo[8]
#dat = re.findall('\d{4}-\d{2}-\d{2}',release)[0]
index = "ibs"
document = "unittests"
payload["release"] = release
payload["architecture"] = architecture
payload["@timestamp"] = timestp
if exists(logFile):
with open(logFile) as f:
try:
it = iter(f)
line = it.next()
while '--------' not in line:
line = it.next()
while True:
line=it.next().strip()
if ":" in line:
pkg = line.split(':')[0].strip()
payload["url"] = 'https://cmssdt.cern.ch/SDT/cgi-bin/buildlogs/'+ architecture +'/'+ release +'/unitTestLogs/' + pkg
line = it.next().strip()
while ':' not in line:
if "had ERRORS" in line:
payload["status"] = 1
else:
payload["status"] = 0
utest= line.split(' ')[0]
payload["package"] = pkg
payload["name"] = utest
id = sha1(release + architecture + utest).hexdigest()
send_payload(index,document,id,json.dumps(payload))
line = it.next().strip()
except Exception as e:
print "File processed:", e
else:
print "Invalid File Path"
#get log files
logs = commands.getstatusoutput("find /data/sdt/buildlogs -mindepth 6 -maxdepth 6 -name 'unitTests-summary.log'")
logs = logs[1].split('\n')
#process log files
for logFile in logs:
flagFile = logFile + '.checked'
if not exists(flagFile):
print "Working on ",logFile
process_ib_utests(logFile)
os.system('touch "' + flagFile + '"')
logs = commands.getstatusoutput("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 = commands.getstatusoutput("cd %s; rm -rf UT; mkdir UT; cd UT; unzip ../unitTestLogs.zip" % utdir)
err, utlogs = commands.getstatusoutput("find %s/UT -name 'unitTest.log' -type f" % utdir)
if not err:
for utlog in utlogs.split("\n"):
process_unittest_log(utlog)
commands.getstatusoutput("touch %s" % flagFile)
except Exception as e:
print "ERROR:",e
commands.getstatusoutput("rm -rf %s/UT" % utdir)
logs = commands.getstatusoutput("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 = commands.getstatusoutput("cd %s; rm -rf AO; mkdir AO; cd AO; unzip ../addOnTests.zip" % utdir)
err, utlogs = commands.getstatusoutput("find %s/AO -name '*.log' -type f" % utdir)
if not err:
for utlog in utlogs.split("\n"):
process_addon_log(utlog)
commands.getstatusoutput("touch %s" % flagFile)
except Exception as e:
print "ERROR:",e
commands.getstatusoutput("rm -rf %s/AO" % utdir)