forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport-summary-merged-prs
executable file
·1210 lines (1007 loc) · 43.7 KB
/
report-summary-merged-prs
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env python
from optparse import OptionParser
import subprocess
import re
import json
import pickle
from pickle import Unpickler
from gitmergesgraph import *
from os.path import basename
from glob import glob
#-----------------------------------------------------------------------------------
#---- Parser Options
#-----------------------------------------------------------------------------------
parser = OptionParser(usage="usage: %prog CMSSW_REPO CMSDIST_REPO COMPARISON_PAIRS"
"\n CMSSW_REPO: location of the cmssw repository. This must be a bare clone ( git clone --bare )"
"\n CMSDIST_REPO: location of the cmsdist repository. This must be a normal clone"
"\n GITHUB_IO_REPO: location of the github.io repository. This must be a normal clone"
"\n for example: cmssw.git or /afs/cern.ch/cms/git-cmssw-mirror/cmssw.git"
"\n START_DATE: the date of the earliest IB to show. It must be in the format"
"\n <year>-<day>-<month>-<hour>"
"\n For example:"
"\n 2014-10-08-1400")
parser.add_option( "-v" , "--verbose" , dest="verbose" , action="store_true", help="Do not post on Github", default=False )
(options, args) = parser.parse_args()
#-----------------------------------------------------------------------------------
#---- Output Schema
#-----------------------------------------------------------------------------------
#
# comparisons": [ <DictA>, <DictB>, <DictC> ]
#
# Each dict contains the result of the comparison between 2 tags in cmssw. For example
# CMSSW_5_3_X_2015-02-03-0200 with CMSSW_5_3_X_2015-02-04-0200 which correspond
# to the IB CMSSW_5_3_X_2015-02-04-0200
#
# The schema of the dictionary is as folows:
# {
# "addons": [],
# "builds": [],
# "compared_tags": "",
# "utests": [],
# "cmsdistTags": {},
# "relvals": [],
# "static_checks": "",
# "isIB": Boolean,
# "tests_archs": [],
# "release_name": "",
# "merged_prs": [],
# "RVExceptions" : Boolean
#
# }
#-----------------------------------------------------------------------------------
#---- Review of arguments
#-----------------------------------------------------------------------------------
if (len(args)<3):
print 'not enough arguments\n'
parser.print_help()
exit()
# Remember that the cmssw repo is a bare clone while cmsdist is a complete clone
CMSSW_REPO = args[ 0 ]
GITHUB_IO_REPO = args[ 1 ]
CMSDIST_REPO = args[ 2 ]
START_DATE = args[ 3 ]
#-----------------------------------------------------------------------------------
#---- Fuctions
#-----------------------------------------------------------------------------------
#
# Takes into account the verbose option. If the option is activated it douesn't print anything.
#
def print_verbose( msg ):
if options.verbose:
print ( msg )
# reads a line of config.map and returns a dictionary with is parameters
def parse_config_map_line ( line ):
params = {}
parts = line.split( ';' )
for part in parts:
if part == '':
continue
key = part.split( '=' )[ 0 ]
value = part.split( '=' )[ 1 ]
params[ key ] = value
return params
# gets the list of architectures by reading config.map, they are saved in ARCHITECTURES
# gets the releases branches from config.map, they are saved in RELEASES_BRANCHES
# it maps the branches for all the releases this is to take into account the case in which the base branch
# is different from the release queue
def get_config_map_params():
f = open( CONFIG_MAP_FILE , 'r' )
for line in f.readlines():
params = parse_config_map_line ( line.rstrip() )
print params
arch = params[ 'SCRAM_ARCH' ]
if arch not in ARCHITECTURES:
ARCHITECTURES.append( arch )
release_queue = params[ 'RELEASE_QUEUE' ]
base_branch = params.get( 'RELEASE_BRANCH' )
if base_branch:
RELEASES_BRANCHES[ release_queue ] = base_branch
else:
RELEASES_BRANCHES[ release_queue ] = release_queue
sp_rel_name = release_queue.split( '_' )[ 3 ]
if sp_rel_name != 'X' and sp_rel_name not in SPECIAL_RELEASES:
SPECIAL_RELEASES.append( sp_rel_name )
if not params.get( 'DISABLED' ):
if not RELEASES_ARCHS.get( release_queue ):
RELEASES_ARCHS[ release_queue ] = []
RELEASES_ARCHS[ release_queue ].append( arch )
if release_queue not in RELEASE_QUEUES:
RELEASE_QUEUES.append( release_queue )
additional_tests = params.get( 'ADDITIONAL_TESTS' )
if additional_tests:
if not RELEASE_ADITIONAL_TESTS.get( release_queue ):
RELEASE_ADITIONAL_TESTS[ release_queue ] = {}
RELEASE_ADITIONAL_TESTS[ release_queue ][ arch ] = [ test for test in additional_tests.split( ',' ) if test != 'baseline' and test != 'dqm' ]
SP_REL_REGEX = "|".join(SPECIAL_RELEASES)
RELEASE_QUEUES.sort()
print
print '---------------------------'
print 'Read config.map:'
print 'ARCHS:'
print ARCHITECTURES
print '--'
print RELEASES_ARCHS
print 'RELEASES_BRANCHES:'
print RELEASES_BRANCHES
print 'special releases'
print SPECIAL_RELEASES
print 'aditional tests'
print RELEASE_ADITIONAL_TESTS
print 'I am going to show:'
print RELEASE_QUEUES
print '---------------------------'
print
# Tells if the pr comes from a merge commit it reads the first part of the line that
# was obtained from git log --graph
def is_pr_from_merge_commit(graph_part):
return graph_part.startswith('|')
def get_pr_number(line_parts):
number_and_name = line_parts[1].replace('"','')
number = re.sub(' from .*', '', number_and_name)
number = re.sub('Merge pull request #', '', number)
return number
def get_pr_author_login(line_parts):
number_and_name = line_parts[1].replace('"','')
name = re.sub('^Merge .* from ', '', number_and_name)
name = name.split('/')[0]
return name
def get_pr_commit_hash(line_parts):
hash = line_parts[0].replace('"','')
return hash
def get_pr_title(line_parts):
title = line_parts[2].replace('"','').strip()
return title
# gets the information of the pull request
def get_info_pr( line , graph ):
pull_request = {}
line_parts = line.split(',')
pull_request['hash'] = get_pr_commit_hash(line_parts)
pull_request['number'] = get_pr_number(line_parts)
pull_request['author_login'] = get_pr_author_login(line_parts)
pull_request['title'] = get_pr_title(line_parts)
pull_request['url'] = 'https://github.com/cms-sw/cmssw/pull/%d' % int(pull_request['number'])
pull_request['from_merge_commit'] = graph[pull_request['hash']].is_from_merge
pull_request['is_merge_commit'] = False
return pull_request
def get_info_merge_commit( line , graph ):
merge_commit = {}
line_parts = line.split(',')
merge_commit['hash'] = get_pr_commit_hash(line_parts)
merge_commit['number'] = merge_commit['hash'][0:7]
merge_commit['is_merge_commit'] = True
merge_commit['from_merge_commit'] = False
brought_commits = get_prs_brought_by_commit( graph , merge_commit['hash'] )
merge_commit['brought_prs'] = [ pr.pr_number for pr in brought_commits ]
return merge_commit
#reads a line of the output of git log and returns the tags that it contains
#if there are no tags it returns an empty list
#it applies filters according to the release queue to only get the
#tags related to the current release queue
def get_tags_from_line( line , release_queue):
if 'tags->' not in line:
return []
tags_str = line.split('tags->')[1]
if re.match( '.*SLHC$', release_queue):
filter = release_queue[:-6]+'[X|0-9]_SLHC.*'
else:
filter = release_queue[:-1]+'[X|0-9].*'
## if the tags part is equal to ," there are no tags
if tags_str != ',"':
tags = tags_str.split(',',1)[1].strip().replace('(','').replace(')','').split(',')
#remove te word "tag: "
tags = [t.replace('tag: ','') for t in tags ]
#I also have to remove the branch name because it otherwise will always appear
#I also remove tags that have the string _DEBUG_TEST, they are used to create test IBs
tags = [ t for t in tags if re.match(filter,t.strip()) and ( t.strip().replace('"','') != release_queue ) and ( 'DEBUG_TEST' not in t ) ]
return [ t.replace('"','').replace('tag:','').strip() for t in tags ]
else:
return []
# Returns all pull request found in a list of comparisons, it returns then in a
# dictionary in which the key is the pr number
def get_all_prs(comparisons):
prs = {}
for comp in comparisons:
for pr in comp['merged_prs']:
prs[pr['number']] = pr
return prs
#-----------------------------------------------------------------------------------
#---- Fuctions -- Analize Git ouputs
#-----------------------------------------------------------------------------------
def determine_build_error(nErrorInfo):
a = BuildResultsKeys.COMP_ERROR in nErrorInfo.keys()
b = BuildResultsKeys.LINK_ERROR in nErrorInfo.keys()
c = BuildResultsKeys.MISC_ERROR in nErrorInfo.keys()
d = BuildResultsKeys.DWNL_ERROR in nErrorInfo.keys()
e = BuildResultsKeys.DICT_ERROR in nErrorInfo.keys()
f = BuildResultsKeys.PYTHON_ERROR in nErrorInfo.keys()
return a or b or c or d or e or f
def determine_build_warning(nErrorInfo):
return BuildResultsKeys.COMP_WARNING in nErrorInfo.keys()
def get_results_one_addOn_file(file):
look_for_err_cmd = 'grep "failed" %s' %file
result,err,ret_code = get_output_command(look_for_err_cmd)
if '0 failed' in result:
return True
else:
return False
#
# given a unitTests-summary.log it determines if the test passed or not
# it returns a tuple, the first element is one of the possible values of PossibleUnitTestResults
# The second element is a dictionary which indicates how many tests failed
#
def get_results_one_unitTests_file(file):
look_for_err_cmd = 'grep -c "ERROR" %s' %file
result,err,ret_code = get_output_command(look_for_err_cmd)
result = result.rstrip()
details = { 'num_fails':result }
if result != '0':
return PossibleUnitTestResults.FAILED,details
else:
return PossibleUnitTestResults.PASSED,details
#
# given a runall-report-step123-.log file it returns the result of the relvals
# it returns a tuple, the first element indicates if the tests passed or not
# the second element is a dictionary which shows the details of how many relvals pased
# and how meny failed
#
def get_results_one_relval_file(filename):
print_verbose( 'Analyzing: ' + filename )
lines = file(filename).read().split("\n")
results = [x for x in lines if ' tests passed' in x]
out = results.pop()
num_passed_sep = out.split(',')[0].replace( ' tests passed' , '' ).strip()
num_failed_sep = out.split(',')[1].replace( ' failed' , '' ).strip()
details = { 'num_passed' : 0,
'num_failed' : 1}
try:
details["num_passed"] = sum( [ int(num) for num in num_passed_sep.split(' ') ] )
details["num_failed"] = sum( [ int(num) for num in num_failed_sep.split(' ') ] )
except ValueError, e:
print "Error while reading file %s" % filename
print e
return False, details
if details["num_failed"] == 0:
return True,details
else:
return False,details
#
# Given a logAnalysis.pkl file, it determines if the tests passed or not
# it returns a tuple, the first element is one of the values of PossibleBuildResults
# The second element is a dictionary contaning the details of the results.
# If the tests are all ok this dictionary is empty
#
def get_results_details_one_build_file(file):
summFile = open(file,'r')
pklr = Unpickler(summFile)
[rel, plat, anaTime] = pklr.load()
errorKeys = pklr.load()
nErrorInfo = pklr.load()
summFile.close()
if determine_build_error(nErrorInfo):
return PossibleBuildResults.ERROR,nErrorInfo
elif determine_build_warning(nErrorInfo):
return PossibleBuildResults.WARNING,nErrorInfo
else:
return PossibleBuildResults.PASSED,nErrorInfo
return True,nErrorInfo
#
# parses the tests results for each file in output. It distinguishes if it is
# build, unit tests, relvals, or addon tests logs. The the result of the parsing
# is saved in the parameter results.
# type can be 'relvals', 'utests', 'addON', 'builds'
#
# schema of results:
# {
# "<IBName>": [ result_arch1, result_arch2, ... result_archN ]
# }
# schema of result_arch
# {
# "arch" : "<architecture>"
# "file" : "<location of the result>"
# "passed" : <true or false> ( if not applicable the value is true )
# "details" : <details for the tests> ( can be empty if not applicable, but not undefined )
# }
#
def analyze_tests_results( output, results, arch, type ):
for line in output.splitlines():
m = re.search('CMSSW.*[0-9]/', line)
if not m:
print_verbose( 'Ignoring file:\n%s' % line )
continue
rel_name = line[m.start():m.end()-1]
result_arch = {}
result_arch['arch'] = arch
result_arch['file'] = line
details = {}
if type == 'relvals':
passed,details = get_results_one_relval_file(line)
elif type == 'utests':
passed,details = get_results_one_unitTests_file(line)
elif type == 'addOn':
passed = get_results_one_addOn_file(line)
elif type == 'builds':
passed,details = get_results_details_one_build_file(line)
else:
print 'not a valid test type %s' %type
exit(1)
result_arch['passed'] = passed
result_arch['details'] = details
if rel_name not in results.keys():
results[rel_name] = []
results[rel_name].append(result_arch)
#
# Searchs in github.io for the results for relvals exceptions
#
def execute_magic_command_find_rv_exceptions_results( ):
print ( 'Finding relval exceptions results...')
command_to_execute = MAGIC_COMMAND_FIND_EXCEPTIONS_RESULTS_RELVALS
out,err,ret_code = get_output_command(command_to_execute)
rv_exception_results = {}
for line in out.splitlines():
line_parts = line.split( '/' )
ib_name = line_parts[ -1 ].replace( 'EXCEPTIONS.json', '' ) + line_parts[ -2 ]
rv_exception_results[ ib_name ] = True
return rv_exception_results
#
# Searchs in github.io for incomplete results. It fills a structure with the results found
# this is done to discard tags at the begining
#
def fill_list_incomplete_results( type ):
print( 'Getting incomplete ', type, ' results...')
dict = {}
if type == 'relvals':
command_to_execute = MAGIC_COMMAD_FIND_INCOMPLETE_RESULTS_RELVALS
dict = INCOMPLETE_RELVALS_RESULTS
elif type == 'builds':
command_to_execute = MAGIC_COMMAD_FIND_INCOMPLETE_RESULTS_BUILD
dict = INCOMPLETE_BUILD_RESULTS
else:
print( "I don't know this type of result", type )
exit( 0 )
out,err,ret_code = get_output_command(command_to_execute)
for line in out.splitlines():
line_parts = line.split( '/' )
ib_name = line_parts[ -1 ].replace( 'INCOMPLETE.json', '' ) + line_parts[ -2 ]
arch = line_parts[ -3 ]
if not dict.get( ib_name ):
dict[ ib_name ] = []
dict[ ib_name ].append( arch )
else:
dict[ ib_name ].append( arch )
print_verbose( type )
print_verbose( dict )
#
# Searchs in github.io for incomplete results.
# It looks into the existing results and adds them to the structure.
#
def execute_magic_command_find_incomplete_results( results, type ):
print( 'Adding incomplete results...' )
dict = {}
if type == 'relvals':
dict = INCOMPLETE_RELVALS_RESULTS
elif type == 'builds':
dict = INCOMPLETE_BUILD_RESULTS
else:
print( "I don't know this type of result", type )
exit( 0 )
for ib_name in dict.keys():
for arch in dict[ ib_name ]:
result_arch = { "arch" : arch,
"passed" : True,
"file" : "not-ready",
"details" : {}
}
if not results.get( ib_name ):
results[ ib_name ] = []
# if there is a result for that arch, I don't add the incomplete one
if not [ r['arch'] for r in results[ ib_name ] if r['arch'] == arch ]:
results[ ib_name ].append( result_arch )
print_verbose( 'Added incomplete: ' + type + ', ' + arch +', ' + ib_name )
else:
print_verbose( 'NOT Added incomplete: ' + type + ', ' + arch +', ' + ib_name )
# returns a list of tags based on git log output
# It uses the release queue name to filter the tags, this avoids having
# in the result tags from other queues that may come from automatic merges.
# For example, if release_queue is 7_2_X, it will drop tags like CMSSW_7_2_THREADED_X_2014-09-15-0200
def get_tags( git_log_output , release_queue ):
tags = []
for line in git_log_output.splitlines():
tags += get_tags_from_line(line, release_queue)
if (len(tags) ==0):
print "ATTENTION:"
print "looks like %s has not changed between the tags specified!" % release_queue
command_to_execute = MAGIC_COMMAND_FIND_FIRST_MERGE_WITH_TAG.replace('END_TAG',release_queue)
out,err,ret_code = get_output_command(command_to_execute)
print out
tags = get_tags_from_line(out, release_queue)
print tags
return tags
#returns the number of the day of a tag
#if it is not an IB tag, it returns -1
def get_day_number_tag(tag):
parts = tag.split("-")
if len(parts) == 1:
return -1
else:
day = parts[2]
try:
return int(day)
except ValueError:
return -1
# uses some heuristics to tell if the list of tags seems to be too short
def is_tag_list_suspicious(tags):
if len(tags) < 7:
return True
day_first_tag = get_day_number_tag(tags[-1])
day_second_tag = get_day_number_tag(tags[-2])
return day_second_tag-day_first_tag > 1
# determines if the error is because one of the tags does not exist
# this can happen when the branch that is being analyzed has been
# created recently
def is_recent_branch(err):
return "unknown revision or path not in the working tree" in err
#-----------------------------------------------------------------------------------
#---- Fuctions -- Execute Magic commands
#-----------------------------------------------------------------------------------
# this calls the git log command with the first tag to look for missing
# tags that were not found previously
def look_for_missing_tags(start_tag, release_queue):
command_to_execute = MAGIC_COMMAND_FIND_FIRST_MERGE_WITH_TAG.replace('END_TAG',start_tag)
out,err,ret_code = get_output_command(command_to_execute)
tags = get_tags_from_line(out, release_queue)
return tags
# Executes the command that is given as parameter, returns a tuple out,err,ret_code
# with the output, error and return code obtained
def get_output_command(command_to_execute):
print_verbose( 'Executing:' )
print_verbose( command_to_execute )
p = subprocess.Popen(command_to_execute, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = p.communicate()
ret_code = p.returncode
if ret_code != 0:
print_verbose( ret_code )
print_verbose( 'Error:' )
print_verbose( err )
return out,err,ret_code
# Gets the tags between start_tag and end_tag, the release_queue is used as a filter
# to ignore tags that are from other releases
def execute_magic_command_tags( start_tag, end_tag, release_queue, release_branch ):
# if it is a special release queue based on a branch with a different name, I use the release_branch as end tag
if release_queue == release_branch:
real_end_tag = end_tag
else:
sp_rel_name = release_queue.split( '_' )[ 3 ]
real_end_tag = end_tag.replace( '_'+sp_rel_name , '' )
tags = []
command_to_execute = MAGIC_COMMAND_TAGS.replace( 'START_TAG' , start_tag ).replace( 'END_TAG' , real_end_tag )
out,err,ret_code = get_output_command(command_to_execute)
# check if the end_tag exists, but the start_tag doesn't
# this could mean that the release branch has been created recently
if ret_code != 0:
if is_recent_branch(err):
print_verbose( 'looks like this branch has been created recently' )
command_to_execute = MAGIC_COMMAND_FIND_ALL_TAGS.replace( 'END_TAG' , real_end_tag ).replace( 'RELEASE_QUEUE' , release_branch )
out,err,ret_code = get_output_command(command_to_execute)
tags = get_tags(out,release_queue)
tags.append(start_tag)
#check if the tags list could be missing tags
# this means that the release branch has not changed much from the start_tag
if is_tag_list_suspicious(tags):
print_verbose( 'this list could be missing something!' )
print_verbose( tags )
new_tags = look_for_missing_tags(start_tag, release_branch)
tags.pop()
tags += new_tags
tags = [t for t in reversed(tags)]
return tags
def execute_command_compare_tags(start_tag,end_tag , graph ):
command_to_execute = MAGIC_COMMAND_PRS.replace('START_TAG',start_tag).replace('END_TAG',end_tag)
output,err,ret_code = get_output_command(command_to_execute)
comp = {}
comp['compared_tags'] = '%s-->%s' % (start_tag,end_tag)
comp[ 'release_name' ] = end_tag
prs = []
for line in output.splitlines():
if 'Merge remote branch ' in line:
pr = get_info_merge_commit( line , graph )
if pr['brought_prs'] == []:
continue
elif 'Merge pull ' in line:
pr = get_info_pr( line , graph )
else:
continue
prs.append(pr)
comp['merged_prs'] = prs
return comp
def compare_tags( tags , graph ):
comparisons = []
for i in range(len(tags)-1):
comp = execute_command_compare_tags(tags[i],tags[i+1] , graph )
comparisons.append(comp)
return comparisons
#
# Executes the command to get the tags
# schema of all_tags_found:
# {
# "<IBName>": {
# "<arch_name>" : "<tag_name>"
# }
# }
def execute_magic_command_get_cmsdist_tags():
all_tags_found = {}
for arch in ARCHITECTURES:
command_to_execute = MAGIC_COMMAND_CMSDIST_TAGS.replace( 'ARCHITECTURE' , arch )
out,err,ret_code = get_output_command( command_to_execute )
for line in out.splitlines():
m = re.search('CMSSW.*[0-9]/', line)
if not m:
print 'Ignoring line:\n%s' % line
continue
rel_name = line[m.start():m.end()-1]
if not all_tags_found.get( rel_name ):
all_tags_found[ rel_name ] = {}
all_tags_found[ rel_name ][ arch ] = line
print 'ALL TAGS'
print all_tags_found
return all_tags_found
#
# Executes the a command to get the results for the relvals, unit tests,
# addon tests, and compitlation tests
# It saves the results in the parameter 'results'
# type can be 'relvals', 'utests', 'addON', 'builds'
#
def execute_magic_command_find_results( results, type ):
for arch in ARCHITECTURES:
if type == 'relvals':
base_command = MAGIC_COMMAD_FIND_RESULTS_RELVALS
elif type == 'utests':
base_command = MAGIC_COMMAND_FIND_RESULTS_UNIT_TESTS
elif type == 'addOn':
base_command = MAGIC_COMMAND_FIND_RESULTS_ADDON
elif type == 'builds':
base_command = MAGIC_COMMAND_FIND_RESULTS_BUILD
else:
print 'not a valid test type %s' %type
exit(1)
command_to_execute = base_command.replace( 'ARCHITECTURE' , arch )
out,err,ret_code = get_output_command( command_to_execute )
analyze_tests_results( out , results , arch , type )
def print_results(results):
print "Results:"
print
print
for rq in results:
print
print rq['release_name']
print '/////////////////////////'
for comp in rq['comparisons']:
print comp['compared_tags']
print '\t' + 'HLT Tests: ' + comp['hlt_tests']
print '\t' + 'Static Checks: ' + comp['static_checks']
cmsdist_tags = comp['cmsdistTags']
print '\t' + 'cmsdist Tags:'+ str( cmsdist_tags )
builds_results = [res['arch']+':'+str(res['passed'])+':'+str(res['details']) for res in comp['builds'] ]
print '\t' + 'Builds:'+ str(builds_results)
relvals_results = [res['arch']+':'+str(res['passed'])+":"+str(res['details']) for res in comp['relvals'] ]
print '\t' + 'RelVals:'+ str(relvals_results)
utests_results = [res['arch']+':'+str(res['passed']) +':'+str(res['details']) for res in comp['utests'] ]
print '\t' + 'UnitTests:' + str(utests_results)
addons_results = [res['arch']+':'+str(res['passed']) for res in comp['addons'] ]
print '\t' + 'AddOns:' + str(addons_results)
merged_prs = [pr['number'] for pr in comp['merged_prs']]
print '\t' + 'PRs:' + str(merged_prs)
from_merge_commit = [pr['number'] for pr in comp['merged_prs'] if pr['from_merge_commit']]
print '\t' + 'From merge commit' + str(from_merge_commit)
print '\t' + 'RVExceptions: ' + str( comp.get( 'RVExceptions' ) )
print '\t' + 'inProgress: ' + str( comp.get( 'inProgress' ) )
#
# Iterates over the IBs comparisons, if an IB doesn't have a tag for an architecture, the previous tag is
# assigned. For example, for arch slc6_amd64_gcc481
# 1. CMSSW_7_1_X_2014-10-02-1500 was built using the tag IB/CMSSW_7_1_X_2014-10-02-1500/slc6_amd64_gcc481
# 2. There is no tag for CMSSW_7_1_X_2014-10-03-0200 in cmsdist
#
# Then, it assumes that the tag used for CMSSW_7_1_X_2014-10-03-0200 was IB/CMSSW_7_1_X_2014-10-02-1500/slc6_amd64_gcc481
#
def fill_missing_cmsdist_tags( results ):
for rq in results:
previous_cmsdist_tags = {}
for comp in rq['comparisons']:
rel_name = comp['compared_tags'].split('-->')[1]
for arch in comp['tests_archs']:
current_ib_tag_arch = comp[ 'cmsdistTags' ].get( arch )
if current_ib_tag_arch:
previous_cmsdist_tags[ arch ] = current_ib_tag_arch
else:
if previous_cmsdist_tags.get( arch ):
comp[ 'cmsdistTags' ][ arch ] = previous_cmsdist_tags[ arch ]
else:
comp[ 'cmsdistTags' ][ arch ] = 'Not Found'
#
# merges the results of the tests with the structure of the IBs tags and the pull requests
# it also marks the comparisons that correspond to an IB
#
def add_tests_to_results( results, unit_tests, relvals_results,
addon_results , build_results, cmsdist_tags_results,
rv_Exceptions_Results ):
for rq in results:
for comp in rq['comparisons']:
rel_name = comp['compared_tags'].split('-->')[1]
rvsres = relvals_results.get(rel_name)
utres = unit_tests.get(rel_name)
adonres = addon_results.get(rel_name)
buildsres = build_results.get(rel_name)
cmsdist_tags = cmsdist_tags_results.get(rel_name)
comp[ 'relvals' ] = rvsres if rvsres else []
comp[ 'utests' ] = utres if utres else []
comp[ 'addons' ] = adonres if adonres else []
comp[ 'builds' ] = buildsres if buildsres else []
comp[ 'cmsdistTags' ] = cmsdist_tags if cmsdist_tags else {}
comp[ 'isIB' ] = '-' in rel_name
comp[ 'RVExceptions' ] = rv_Exceptions_Results.get( rel_name )
comp[ 'inProgress' ] = rel_name in ALL_BUILDING_IBS
if not comp.get( 'static_checks' ):
comp[ 'static_checks' ] = 'not-found'
if not comp.get( 'hlt_tests' ):
comp['hlt_tests' ] = 'not-found'
a = [t['arch'] for t in utres] if utres else []
b = [t['arch'] for t in rvsres] if rvsres else []
c = [t['arch'] for t in buildsres] if buildsres else []
not_complete_archs = [arch for arch in c if arch not in a]
for nca in not_complete_archs:
result = {}
result['arch'] = nca
result['file'] = str([res['file'] for res in buildsres if res['arch'] == nca])
result['passed'] = PossibleUnitTestResults.UNKNOWN
result['details'] = {}
comp['utests'].append(result)
comp['tests_archs'] = list(set(a+b+c))
#
# Finds for an IB the results of the static tests
#
def find_static_results( comparisons , architecture ):
for comp in comparisons:
rel_name = comp['compared_tags'].split('-->')[1]
print 'Looking for static tests results for ', rel_name
comp['static_checks'] = find_one_static_check( rel_name , architecture )
#
# Finds for an IB the results of the HLT tests
#
def find_hlt_tests_results( comparisons ):
for comp in comparisons:
rel_name = comp[ 'compared_tags' ].split('-->')[1]
print 'Looking for HLT tests results for ', rel_name
comp[ 'hlt_tests' ] = find_one_hlt_test( rel_name )
#
# Looks for one static-tests result for the IB, if it finds it, the value is 'found' if not, the value is ''
#
def find_one_static_check( release_name , architecture ):
command_to_execute = MAGIC_COMMAND_FIND_STATIC_CHECKS.replace('RELEASE_NAME',release_name)
command_to_execute = command_to_execute.replace('ARCHITECTURE', architecture )
out,err,ret_code = get_output_command(command_to_execute)
if '200 OK' in out:
print 'found'
return architecture
print 'not-found'
return 'not-found'
#
# Looks for one hlt test result for the IB, if it finds it, the value is 'found' if not, the value is ''
#
def find_one_hlt_test( release_name ):
command = MAGIC_COMMAND_FIND_HLT_TESTS.replace('RELEASE_NAME', release_name)
out,err,ret_code = get_output_command(command)
if '200 OK' in out:
print 'found'
return 'found'
print 'not-found'
return 'not-found'
# reads the results and generates a separated json for each release_queue
# it also generates a csv file with statistics per release_queue and a general one
def generate_separated_json_results( results ):
all_ibs_list = []
all_prs_list = []
for rq in results:
file_name = rq['release_name'] + ".json"
summary_file_name = rq['release_name'] + "_summary.txt"
out_json = open(file_name, "w")
json.dump(rq,out_json,indent=4)
out_json.close()
f_summary = open(summary_file_name, "w")
ibs = [ comp['release_name'] for comp in rq['comparisons']
if (comp['release_name'] != rq['base_branch']) and comp['isIB'] ]
all_ibs_list.extend( ibs )
# Ignore forward ported prs, and merge commits
only_prs_list = []
for comp in rq['comparisons']:
only_prs_list.extend( [ pr['number'] for pr in comp['merged_prs']
if not ( pr['is_merge_commit'] or pr['from_merge_commit'] ) ] )
all_prs_list.extend( only_prs_list )
f_summary.write( "IBs:%s\n" % ibs )
f_summary.write( "NumIBs:%d\n" % len(ibs) )
f_summary.write( "PRs:%s\n" % only_prs_list )
f_summary.write( "NumPRs:%d\n" % len(only_prs_list) )
f_summary.close()
all_ibs_list = list( set(all_ibs_list) )
all_ibs_list.sort()
all_prs_list = list( set(all_prs_list) )
all_prs_list.sort()
f_summary_all = open('ibsSummaryAll.txt', "w")
f_summary_all.write( "IBs:%s\n" % all_ibs_list )
f_summary_all.write( "NumIBs:%d\n" % len(all_ibs_list) )
f_summary_all.write( "PRs:%s\n" % all_prs_list )
f_summary_all.write( "NumPRs:%d\n" % len(all_prs_list) )
#
# Generates a json file with the global status of the last IB for each architecture,
# per each Release Queue
# Schema of short_summary
# [ releaseQueue1, releaseQueue2, ... , releaseQueueN ]
# Schema of releaseQueueN
# {
# "<ReleaseQueue>": {
# "<arch>": {
# "status": "ok|warning|error|unknown"
# "latest_IB" : "<latest IB>"
# }
# }
# }
def generate_ib_json_short_summary( results ):
short_summary = {}
for rq in results:
# this should not be called 'release name', this should be fixed
rq_name = rq[ 'release_name' ]
enabled_archs = RELEASES_ARCHS[ rq_name ]
for arch in enabled_archs:
ibs_for_current_arch = [rel for rel in rq[ 'comparisons' ] if arch in rel[ "tests_archs" ] ]
# it starts as ok and checks the conditions
ib_status = 'ok'
if len( ibs_for_current_arch ) == 0:
latest_IB = 'N/A'
ib_status = 'unknown'
else:
latest_IB_info = ibs_for_current_arch[ -1 ]
latest_IB_name = latest_IB_info[ 'release_name' ]
build_info = [ b for b in latest_IB_info[ "builds" ] if b[ 'arch' ] == arch ]
if len( build_info ) == 0:
build_passed = 'unknown'
else:
build_passed = build_info[ 0 ][ "passed" ]
unit_tests_info = [ u for u in latest_IB_info[ "utests" ] if u[ 'arch' ] == arch ]
if len( unit_tests_info ) == 0:
utests_passed = 'unknown'
else:
utests_passed = unit_tests_info[ 0 ][ "passed" ]
relvals_info = [ r for r in latest_IB_info[ "relvals" ] if r[ 'arch' ] == arch ]
if len( relvals_info ) == 0:
relvals_passed = 'unknown'
else:
relvals_passed = relvals_info[ 0 ][ "passed" ]
if not short_summary.get( rq_name ):
short_summary[ rq_name ] = {}
short_summary[ rq_name ][ arch ] = {}
short_summary[ rq_name ][ arch ][ "latest_IB" ] = latest_IB_name
merged_statuses = "%s-%s-%s" % (build_passed,utests_passed,relvals_passed)
if 'unknown' in merged_statuses:
ib_status = 'unknown'
elif 'failed' in merged_statuses or 'False' in merged_statuses:
ib_status = 'error'
elif 'warning' in merged_statuses:
ib_status = 'warning'
short_summary[ rq_name ][ arch ][ "status" ] = ib_status
short_summary[ 'all_archs' ] = ARCHITECTURES
out_json = open( 'LatestIBsSummary.json' , "w" )
json.dump( short_summary , out_json , indent=4 )
out_json.close()
# Identifies and groups the releases accodring to their prefix
# For example if the release queues are:
# CMSSW_7_1_X, CMSSW_7_0_X, CMSSW_6_2_X, CMSSW_5_3_X, CMSSW_7_1_THREADED_X
# CMSSW_7_1_BOOSTIO_X, CMSSW_7_1_ROOT6_X, CMSSW_7_1_GEANT10_X, CMSSW_6_2_X_SLHC
# CMSSW_7_1_DEVEL_X, CMSSW_7_1_CLANG_X, CMSSW_7_2_X, CMSSW_7_2_DEVEL_X, CMSSW_7_2_CLANG_X
# CMSSW_7_2_GEANT10_X
# It will organize them like this:
# CMSSW_5_3_X: CMSSW_5_3_X
# CMSSW_7_2_X: CMSSW_7_2_X, CMSSW_7_2_DEVEL_X, CMSSW_7_2_CLANG_X, CMSSW_7_2_GEANT10_X
# CMSSW_6_2_X: CMSSW_6_2_X CMSSW_6_2_X_SLHC
# CMSSW_7_0_X: CMSSW_7_0_X
# CMSSW_7_1_X: CMSSW_7_1_X, CMSSW_7_1_THREADED_X, CMSSW_7_1_BOOSTIO_X, CMSSW_7_1_ROOT6_X',
# CMSSW_7_1_GEANT10_X, CMSSW_7_1_DEVEL_X, CMSSW_7_1_CLANG_X
#
# It returns a dictionary in which the keys are the release prefixes, and the values are
# the release queues
def identify_release_groups(results):
releases = [rq['release_name'] for rq in results]
releases.sort(reverse=True)
groups = {}
for rel in releases:
prefix = rel[:10] + 'X'
group = groups.get(prefix)
if not group:
groups[prefix] = []
groups[prefix].append(rel)
keys = groups.keys()
keys.sort()
groups['all_prefixes'] = keys
groups['all_release_queues'] = releases
return groups
#
# Using the original list of tags and the latest installed IB, it infers which IBs are currently building
# and IB is currently building if is after lastInstalledIB and incomplete compilation results are found.
# returns a list of the IBs that are currenyl being built.
#
def getBuildingIBs( originalTags, lastInstalled ):
print_verbose( 'last Installed: ' + lastInstalled )
print_verbose( 'Original tags: ' + str( originalTags ) )
print_verbose( 'index: ' + str( originalTags.index( lastInstalled ) ) )
#these are te tags that are between the latest installed release and the head of the branch
latestTags = originalTags[ (originalTags.index( lastInstalled )+1): ]
print_verbose( 'latestTags: ' + str( latestTags ) )