-
Notifications
You must be signed in to change notification settings - Fork 3
/
ReportPerfTestResult.py
executable file
·698 lines (582 loc) · 29.1 KB
/
ReportPerfTestResult.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
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
#!/usr/bin/env python3
import os
import smtplib
import configparser
from datetime import datetime
import glob
import socket
import re
from optparse import OptionParser
import sys
import inspect
import traceback
# Handle different Dev and Op environments for RegressionLogProcessor class
try:
from regressionLogProcessor import RegressionLogProcessor
except ImportError:
try:
from RegressionLogProcessor.regressionLogProcessor import RegressionLogProcessor
except ImportError:
RegressionLogProcessor = None
finally:
pass
# Handle different Dev and Op environments for ReportedTestCasesHistory class
try:
from ReportedTestCasesHistory import ReportedTestCasesHistory
except ImportError:
try:
from PerfStat.ReportedTestCasesHistory import ReportedTestCasesHistory
except ImportError:
ReportedTestCasesHistory = None
finally:
pass
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email import encoders as Encoders
msgText = MIMEMultipart('alternative')
class BuildNotificationConfig( object ):
def __init__(self, options, iniFile = 'ReportPerfTestResult.ini'):
self._buildDate = options.dateString
if not self.buildDate:
self.today = datetime.today()
self._buildDate = self.today.strftime("%Y-%m-%d")
self._buildTime = options.timeString
if not self._buildTime:
self._buildTime = self.today.strftime("%H:%M:%S")
self._buildTimeAsPathMemeber = self.today.strftime("%H-%M-%S")
else:
if re.match("[0-9][0-9]-[0-9][0-9]-[0-9][0-9]", self._buildTime):
self._buildTimeAsPathMemeber = self._buildTime
self._buildTime = self._buildTime.replace('-', ':')
elif re.match("[0-9][0-9]:[0-9][0-9]:[0-9][0-9]", self._buildTime):
self._buildTimeAsPathMemeber = self._buildTime.replace(':', '-')
else:
print("Unrecognised time format. Ignored and use current time")
self._buildTime = self.today.strftime("%H:%M:%S")
self._buildTimeAsPathMemeber = self.today.strftime("%H-%M-%S")
self.config = configparser.ConfigParser()
self.config.read( iniFile )
self._gitBranch = 'master'
self._gitBranchName = self._gitBranch
self._gitBranchDate = ''
self._gitBranchCommit = ''
self.processGitInfo()
def get( self, section, key ):
retVal = None
try:
retVal = self.config.get( section, key )
except:
retVal = "Missing value(section: %s, key: %s)" % (section, key)
return retVal
def __getattr__(self, name):
print('Attempt to acess missing attribute of {0}'.format(name))
return 'Attribute Error: {0}'.format(name)
@property
def buildDate( self ):
return self._buildDate
@property
def buildTime( self ):
return self._buildTime
@property
def buildTimeAsPathMemeber( self ):
return self._buildTimeAsPathMemeber
@property
def reportDirectory( self ):
return "{buildDate}/{buildSystem}/{buildTime}/{buildDirectory}".format(
buildDate = self.buildDate,
buildSystem = self.get( 'OBT', 'ObtSystem' ) + '-' + self.get( 'Environment', 'BuildSystem' ),
buildTime = self.buildTimeAsPathMemeber,
buildDirectory = self.get( 'Environment', 'BuildDirectory' ))
@property
def reportDirectoryURL( self ):
return "{urlBase}/{buildBranch}/{reportDirectory}".format(
urlBase=self.get( 'Environment', 'urlBase' ),
buildBranch=self.get('Environment', 'BuildBranch' ),
reportDirectory=self.reportDirectory )
@property
def reportObtSystem( self ):
return "{obtSystem}".format(
obtSystem=self.get( 'OBT', 'ObtSystem'))
@property
def logDirectory( self ):
return "{logDir}".format(
logDir=self.get( 'Environment', 'LogDir'))
@property
def obtLogDirectory( self ):
return os.path.expanduser("{ObtLogDir}".format(
ObtLogDir=self.get( 'Environment', 'ObtLogDir')))
@property
def gitBranch( self ):
return self._gitBranch
@property
def gitBranchName( self ):
return self._gitBranchName
@property
def gitBranchDate( self ):
return self._gitBranchDate
@property
def gitBranchCommit( self ):
return self._gitBranchCommit
@property
def gitLogFileSystem( self ):
return "{obtLogDirectory}/git_2days.log".format(
obtLogDirectory=self.obtLogDirectory)
def processGitInfo(self):
p_branch = re.compile('\s*git branch:\s*(.*)$')
p_date = re.compile('\s*Date:\s*(.*)$')
p_commit = re.compile('\s*commit\s*(.*)$')
self._gitBranch = ''
self._gitBranchName = 'NotFound'
gitBranchInfo = ''
self._gitBranchDate = ''
self._gitBranchCommit = ''
try:
gitLog = open( self.gitLogFileSystem )
for line in gitLog.readlines( ):
m = p_branch.match( line )
if m:
self._gitBranchName = m.group(1)
continue
m = p_date.match( line )
if m:
self._gitBranchDate = m.group(1)
continue
m = p_commit.match( line )
if m:
self._gitBranchCommit = m.group(1)
continue
except:
print("Exception in git log file processing:" + str(sys.exc_info()[0]) + " (line: " + str(inspect.stack()[0][2]) + ")" )
print("line: %s" % (line))
print("Exception in user code:")
print('-'*60)
traceback.print_exc(file=sys.stdout)
print('-'*60)
finally:
if self._gitBranchName == '':
self._gitBranchName = "NotFound"
if self._gitBranchDate != '':
self._gitBranchDate = self._gitBranchDate.replace(' +0000','')
gitBranchInfo += self._gitBranchDate
else:
self._gitBranchDate = self.today.ctime()
if self._gitBranchCommit != '':
if gitBranchInfo != '':
gitBranchInfo += ', '
gitBranchInfo += 'sha:'+self._gitBranchCommit
self._gitBranch += self._gitBranchName +' (' + gitBranchInfo + ')'
@property
def gitBranchCommitHtml( self ):
return '<b>' + self._gitBranchCommit[0:8].upper() + '</b> (' + self._gitBranchCommit[8:]+')'
@property
def buildType(self):
return "{buildType}".format(
buildType=self.get( 'Environment', 'BuildType'))
@property
def thorSlaves(self):
return "{thorSlaves}".format(
thorSlaves=self.get( 'Environment', 'ThorSlaves'))
@property
def thorChannelsPerSlave(self):
return "{thorChannelsPerSlave}".format(
thorChannelsPerSlave=self.get( 'Environment', 'ThorChannelsPerSlave'))
@property
def testMode(self):
return "{testMode}".format(
testMode=self.get( 'Performance', 'TestMode'))
class PerformanceSummary( object ):
def __init__( self, config ):
self.config = config
def getSummaryTable(self):
# Generated table layout
#
# ------------------------------------------------------------------------------------------------------------
# | | | Last two | Last five | All (max last 30) |
# | | |----------------------------+----------------------------+----------------------------+
# | Cluster | Time | d | Trend | % | d | Trend | % | d | Trend | % |
# | | |(sec/run)| | |(sec/run)| | |(sec/run)| | |
# ----------+---------+---------+-----------+------+---------+-----------+------+---------+-----------+------+
# | hthor | 9999.99 | 999.99 | unaltered | 999.9| 999.99 | unaltered | 999.9| 999.99 | unaltered | 999.9|
# ----------+---------+---------+-----------+------+---------+-----------+------+---------+-----------+------+
# | thor | 9999.99 | 999.99 | unaltered | 999.9| 999.99 | unaltered | 999.9| 999.99 | unaltered | 999.9|
# ----------+---------+---------+-----------+------+---------+-----------+------+---------+-----------+------+
# | | | | | | | | | | | |
#
retTable = '<table cellspacing="0" cellpadding="3" border="1" bordercolor="#828282">'
tableHeader = '<caption><H3>Performance Test results trend analysis for the last two, five and max 30 runs.</H3></caption>'
# First line of table header
tableHeader += '<thead><TR style="background-color:#CEE3F6">'
tableHeader += '<TH rowspan="2" width="10%">Cluster</TH>'
tableHeader += '<TH rowspan="2" width="10%">Time<br>(sec)</TH>'
tableHeader += '<TH colspan="3" width="25%">Last two</TH>'
tableHeader += '<TH colspan="3" width="25%">Last five</TH>'
tableHeader += '<TH colspan="3" width="25%">All (max last 30)</TH>'
tableHeader += '</TR>'
# Second line of table header
tableHeader += '<TR style="background-color:#CEE3F6">'
tableHeader += '<TH>d<br>(sec/run)</TH><TH>Trend</TH><TH>%</TH>'
tableHeader += '<TH>d<br>(sec/run)</TH><TH>Trend</TH><TH>%</TH>'
tableHeader += '<TH>d<br>(sec/run)</TH><TH>Trend</TH><TH>%</TH>'
tableHeader += '</TR></thead>'
retTable += tableHeader
tableRows = ''
logDir = self.config.obtLogDirectory
summaryFileName = logDir + '/perftest.summary'
summaryFile = open(summaryFileName, "r")
for line in summaryFile:
if line.startswith('#'):
# Comment, skip it
continue
tableRows += '<tr>'
lineItems = line.replace('\n', '').split(',')
for lineItem in lineItems:
if lineItems.index(lineItem) in [1, 2, 4, 5, 7, 8, 10]: # numeric columns
tableRows += '<td align="right">'
else:
tableRows += '<td align="center">'
tableRows += lineItem + '</td>'
tableRows += '</tr>'
summaryFile.close()
retTable += tableRows +'</table><br>\n'
retTable += 'Threshold is +-5% to detremine trend increased/decreased the execution time.<br>'
retTable += 'The "d (sec/run)" is the slope of the trend. "%" is equal with the slope divided by the value of first datapoint.<br>'
retTable += 'The attached PerformanceTestReport PDF contans same analysis for the individual test cases. The short report contains testcases with significant (outside the treshold) runtime changes only.<br>'
return retTable
class BuildNotification(object):
def __init__( self, config ):
self.config = config
self.hasBuild = True
self.summary = ''
self.status = ''
self.results = []
self.tasks = [ 'Install', 'Unittests', 'Setup', 'Hthor', 'Thor', 'Roxie', 'Uninstall' ]
self.msg = MIMEMultipart('mixed')
self.msgHTML = ''
self.msgText = ''
self.logFiles=[]
self.buildTaskIndex = 0
self.logReport = {}
def appendWithDelimiter(self, target, text, delimiter = ', '):
retVal = ''
if len(target) > 0:
retVal += delimiter
retVal += text
return retVal
def createMsg(self):
logDir = os.path.expanduser(self.config.get( 'Environment', 'LogDir' ))
print("logDir" +logDir)
curDir = os.getcwd()
os.chdir( logDir )
tests = self.config.get( 'Performance', 'TestList' ) .split(',')
self.msg['From'] = self.config.get( 'Email', 'Sender')
self.msg['To'] = self.config.get( 'Email', 'Receivers')
print("Build Result " + self.status)
print("From " + self.msg['From'])
print("To " + self.msg['To'])
logFiles=[]
# Begin email HTML body
msgHTML = "<!DOCTYPE html>\n"
msgHTML += "<html>\n"
msgHTML += "<head>\n"
msgHTML += "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n"
msgHTML += "<title>HPCC OBT Performance Test Report</title>\n"
msgHTML += "</head>\n"
msgHTML += "<body>\n"
msgHTML += "<H3>HPCC OBT Performance Test Report:</H3><br/>\n"
msgHTML += "<table>\n"
msgHTML += "<tr><td>Build date:</td><td><b>" + self.config.buildDate + "</b></td></tr>\n"
msgHTML += "<tr><td>Build system:</td><td>" + self.config.get('Environment', 'BuildSystem') + "</td></tr>\n"
msgHTML += "<tr><td>Hardware:</td><td>" + self.config.get('OBT', 'ObtSystemHw').replace('"', '') + "</td></tr>\n"
msgHTML += "<tr><td>IP Address:</td><td>" + socket.gethostbyname(socket.gethostname()) + " (" + self.config.reportObtSystem + ")</td></tr>\n"
msgHTML += "<tr><td align=\"right\">Build on git branch:</td><td><b>" + self.config.gitBranchName + "</b></td></tr>\n"
msgHTML += "<tr><td align=\"right\">Date:</td><td>" + self.config.gitBranchDate + "</td></tr>\n"
msgHTML += "<tr><td align=\"right\">SHA:</td><td>" + self.config.gitBranchCommitHtml + "</td></tr>\n"
msgHTML += "<tr><td align=\"right\">Build type:</td><td><b>" + self.config.buildType + "</b></td></tr>\n"
msgHTML += "<tr><td align=\"right\">Number of Thor slaves:</td><td><b>" + self.config.thorSlaves + "</b></td></tr>\n"
msgHTML += "<tr><td align=\"right\">Number of channels per Thor slave:</td><td><b>" + self.config.thorChannelsPerSlave + "</b></td></tr>\n"
msgHTML += "<tr><td align=\"right\">Test mode:</td><td><b>" + self.config.testMode + "</b></td></tr>\n"
# msgHTML += "<tr><td>Global exclusion:</td><td>" + self.results[self.buildTaskIndex].globalExclusion + "</td></tr>\n"
msgHTML += "</table><br>\n\n"
self.logReport['buildDate'] = self.config.buildDate.replace('-', '.')
self.logReport['gitBranchName'] = self.config.gitBranchName.replace('candidate-', '')
self.logReport['testMode'] = self.config.testMode
self.logReport['status'] = ''
self.logReport['gitBranchDate']= self.config.gitBranchDate
self.logReport['gitBranchCommit'] = self.config.gitBranchCommit[0:8].upper()
self.logReport['buildType'] = self.config.buildType[0:1]
self.logReport['reportObtSystem'] = self.config.reportObtSystem
self.logReport['thorConfig'] = 'T: ' + self.config.thorSlaves + 's/' + self.config.thorChannelsPerSlave + 'c'
self.logReport['diagram'] = '-'
self.logReport['stats'] = {}
msgHTML += "<table width=\"600\" cellspacing=\"0\" cellpadding=\"0\" border=\"1\">\n"
msgHTML += "<TR style=\"background-color:#CEE3F6\"><TH>Target</TH><TH>Status</TH><TH>Log</TH></TR>\n"
subjectSuffix='Result:'
subjectStatus = ''
subjectError = ''
testLogs = []
for test in tests:
queries = ''
passed = ''
failed = ''
file = test + "-performance-test.log"
files = glob.glob( test + \
".[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9].log" )
if files:
sortedFiles = sorted( files, key=str.lower, reverse=True )
file = sortedFiles[0]
print("processing file:"+file)
try:
temp = open(file).readlines( )
logFiles.append(file)
except IOError:
print("IOError in read '%s'" % (file))
continue
for line in temp:
if 'Queries:' in line:
fields = line.split()
queries = fields[1]
elif 'Passing:' in line:
fields = line.split()
passed = fields[1]
elif 'Failure:' in line:
fields = line.split()
failed = fields[1]
if failed != '0':
subjectSuffix += ' ' + failed +' ' + test
subjectError += self.appendWithDelimiter(subjectError, test)
if len(self.logReport['status']) != 0:
self.logReport['status'] +=', '
self.logReport['status'] += failed + test[0:1].upper()
result = 'total:'+queries+' passed:'+passed+' failed:'+failed
part = MIMEBase('application', 'octet-stream')
part.set_payload( ''.join(temp))
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % file)
# Dont attach the logfile yet, store it and attach after the email bodi generated and attached
testLogs.append(part)
# Test results HTML
msgHTML += "<TR align=\"center\">\n"
msgHTML += "<TD>" + test + "</TD>\n"
msgHTML += "<TD>" + result + "</TD>\n"
msgHTML += "<TD>"
logFileUrl = self.config.reportDirectoryURL + '/test/perf/'+file
msgHTML += "<a href=\"" + logFileUrl + "\" target=\"_blank\">" + file + "</a>"
msgHTML += "</TD>\n</TR>\n"
msgHTML += '</table><br>\n\n'
if RegressionLogProcessor:
# Use it if sucessfully imported
rlp = RegressionLogProcessor(curDir, 'Performance')
print("ZAPpath:" + self.config.reportDirectoryURL + "/test/ZAP")
rlp.setLogArchivePath(self.config.reportDirectoryURL + "/test/ZAP")
for file in logFiles:
try:
print("Process " + file)
rlp.ProcessFile(file)
rlp.ProcessResults()
rlp.SaveFaultedTestCases()
htmlResult = '\n'.join(rlp.GetHtmlResult())
if len(htmlResult) > 5:
msgHTML += htmlResult + "\n"
except:
print("Unexpected error:" + str(sys.exc_info()[0]) + " (line: " + str(inspect.stack()[0][2]) + ")" )
traceback.print_stack()
pass
finally:
pass
else:
print("RegressionLogProcessor not found.")
# Process summary graph
summaryGraph = glob.glob( self.config.obtLogDirectory + '/perftest-*.png')
embeddedImages = []
if len(summaryGraph) > 0:
print("Add summary graph")
msgHTML += '<H3>Performance Test results trend analysis.</H3>\n'
msgHTML += '<img src="cid:SummaryGraph" alt="Summary Graph"><br>\n'
try:
fp = open(summaryGraph[0], 'rb')
img = MIMEImage(fp.read(), 'png')
fp.close()
img.add_header('Content-ID', '<{}>'.format('SummaryGraph'))
img.add_header('Content-Disposition', 'inline', filename='SummaryGraph.png')
# Dont attach the image yet, store it and attach after the email body generated and attached
embeddedImages.append(img)
except:
print("Unexpected error:" + str(sys.exc_info()[0]) + " (line: " + str(inspect.stack()[0][2]) + ")" )
traceback.print_stack()
msgHTML += 'Error in processing SummaryGraph.<br>\n'
pass
else:
print("Summary graph not found.")
if ReportedTestCasesHistory:
try:
print("Add history table")
diagramsPath = self.config.reportDirectoryURL + "/test/diagrams"
print("Diagrams path: %s" %(diagramsPath) )
# Test with default number (7) of days data
rtch = ReportedTestCasesHistory(self.config.obtLogDirectory + '/PerformanceIssues-all.csv')
rtch.readFile()
rtch.buildHistoryTable(diagramsPath)
msgHTML += rtch.getHistoryHtml()
self.logReport['stats'] = rtch.getStats()
except:
print("Unexpected error:" + str(sys.exc_info()[0]) + " (line: " + str(inspect.stack()[0][2]) + ")" )
traceback.print_stack()
pass
else:
print("ReportedTestCasesHistory not found.")
self.logReport['stats'] = {}
# It should be a global parameter enableAttachDiagrams or something
# similar from .ini
enableAttachDiagrams = False
if enableAttachDiagrams:
# Process test cases graph
images = glob.glob( self.config.obtLogDirectory +"/[0-9][0-9]*.png" )
if len(images) > 0:
print("Add problematic testcases diagram")
if not ReportedTestCasesHistory:
msgHTML += '<H3>Problematic test case(s).</H3>\n'
index = 1
for image in sorted(images):
print("Image:'%s'" % (image))
msgHTML += '<img src="cid:image{}" alt="Image-{}"><br>\n'.format(index, index)
try:
fp = open(image, 'rb')
img = MIMEImage(fp.read(), 'png')
fp.close()
img.add_header('Content-Type', 'image/png', name='graph{}.png'.format(index))
img.add_header('Content-ID', '<{}{}>'.format('image', index))
img.add_header('Content-Disposition', 'inline', filename='graph{}.png'.format(index))
# Dont attach the image yet, store it and attach after the email body generated and attached
embeddedImages.append(img)
except:
print("Unexpected error:" + str(sys.exc_info()[0]) + " (line: " + str(inspect.stack()[0][2]) + ")" )
traceback.print_stack()
msgHTML += 'Error in processing ' + image +'.<br>\n'
pass
index += 1
if subjectSuffix == 'Result:':
subjectSuffix += " PASSED"
subjectStatus = "PASSED"
self.logReport['status'] = "PASSED"
else:
subjectStatus = "FAILED: "
subjectSuffix += " failure"
if len( self.logReport['status']) == 0:
self.logReport['status'] = "Failure"
self.msg['Subject'] = self.config.gitBranchName[0].upper() + self.config.gitBranchName[1:] + ' ' + subjectStatus + subjectError + ". " + self.config.reportObtSystem + " Performance Test Result on " + self.config._buildDate # + " " + subjectSuffix
# Add links
logArchiveLink = self.config.reportDirectoryURL+"/test" #"/log-archive"
msgHTML += "<ul><li><a href=\"" + logArchiveLink + "\" target=\"_blank\">Nightly Build Log Archive</a></li></ul>"
# End HTML
#msgHTML += "<br><hr>\n"
#msgHTML += "Links to results in old OBT system (Wiki pages)<br>\n"
#msgHTML += "<ul>\n"
#msgHTML += "<li><a href=\"http://10.176.152.123/wiki/index.php/HPCC_Nightly_Builds\" target=\"_blank\">Nightly Builds Web Page</a></li>\n"
#msgHTML += "<li><a href=\"http://10.176.32.10/builds/\" target=\"_blank\">HPCC Builds Archive</a></li>\n"
#msgHTML += "</ul>\n"
msgHTML += "</body>\n"
msgHTML += "</html>\n"
# Email HTML body ready attach it to the msg
self.msg.attach( MIMEText( msgHTML, 'html' ))
# For check the email size limit use:
# smtp = smtplib.SMTP('server.name')
# smtp.ehlo()
# max_limit_in_bytes = int( smtp.esmtp_features['size'] )
# For kep the generated email size in side the limit use len(self.msg.as_string()))
# Attach images after the email text
for image in embeddedImages:
self.msg.attach(image)
# Attach logfiles at the end, before the PDF stuff (if there any)
for part in testLogs:
self.msg.attach(part)
# It should be a global parameter enableAttachPDF or something
# similar from .ini
enableAttachPDF = False
if enableAttachPDF:
# Attach result PDFs
files = glob.glob( self.config.obtLogDirectory +"/PerformanceTest*.pdf" )
if files:
for file in files:
print("processing file:"+file)
try:
temp = open(file).readlines( )
logFiles.append(file)
except IOError:
continue
part = MIMEBase('application', 'octet-stream')
part.set_payload( ''.join(temp))
Encoders.encode_base64(part)
fileName = file.replace(self.config.obtLogDirectory +"/","")
part.add_header('Content-Disposition', 'attachment; filename="%s"' % fileName )
self.msg.attach(part)
os.chdir( curDir )
pass
def send(self):
self.msg.attach( MIMEText( self.msgHTML, 'html' ))
server = bnc.get( 'Email', 'SMTPServer' )
fromaddr= bnc.get( 'Email', 'Sender' )
toList = self.msg['To'].split( ',' )
try:
if server == "smtp.ntlworld.com":
# My current dev env only supports SMTP on SSL
smtpObj = smtplib.SMTP_SSL( server, 465 )
else:
smtpObj = smtplib.SMTP( server, 25 )
smtpObj.set_debuglevel(0)
smtpObj.sendmail( fromaddr, toList, self.msg.as_string() )
#print( self.msg.as_string() )
except smtplib.SMTPException:
print( "Error: unable to send email" )
#smtpObj.quit()
def storeLogRecord(self):
sequence = ['buildDate', 'gitBranchName', 'testMode', 'thorConfig', 'status', 'gitBranchDate', 'gitBranchCommit', 'buildType', 'diagram', 'stats']
statsSeq = ['testNum', 'Good', 'Bad', 'Ugly', 'Ugly and Bad', 'Neutral', 'Known']
bTimeStr = self.logReport['gitBranchDate']
print("bTimeStr: %s" % (bTimeStr))
if ('+' in bTimeStr) or ('-' in bTimeStr):
# Remove time differece at the end of the time string
bTimeStr = bTimeStr.rsplit(' ', 1)[0]
#Convert it to timedate
bTime = datetime.strptime(bTimeStr, "%a %b %d %H:%M:%S %Y")
# Format it to YYYY.MM.DD HH:MM
self.logReport['gitBranchDate'] = bTime.strftime("%Y.%m.%d %H:%M")
try:
logRecordFile = open(self.logReport['reportObtSystem']+'.txt', "a" )
for item in sequence:
if item == 'stats':
if len(self.logReport['stats']) > 0:
for statsItem in statsSeq:
logRecordFile.write("%d\t" % (self.logReport[item][statsItem]))
else:
logRecordFile.write("%s\t" % (self.logReport[item]))
logRecordFile.write('\n')
except:
print("Exception in storeLogRecord():" + str(sys.exc_info()[0]) + " (line: " + str(inspect.stack()[0][2]) + ")" )
print("Exception in user code:")
print('-'*60)
traceback.print_exc(file=sys.stdout)
print('-'*60)
finally:
logRecordFile.close()
#
#----------------------------------------------------------
#
if __name__ == "__main__":
usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
parser.add_option("-d", "--date", dest="dateString", default = None, type="string",
help="Date to generate report Default is '' (empty) for today. Use 'yy-mm-dd' or 'yyyy-mm-dd' to get result on specified days.", metavar="DATE_FOR_QUERY")
parser.add_option("-t", "--time", dest="timeString", default = None, type="string",
help="Time to generate report Default is '' (empty) for current time. Use 'hh-mm-ss' 'hh-mm' to get result on specified time.", metavar="TIME_FOR_QUERY")
parser.add_option("-v", "--verbose", dest="verbose", default=False, action="store_true",
help="Show more info. Default is False"
, metavar="VERBOSE")
(options, args) = parser.parse_args()
bnc = BuildNotificationConfig(options)
bn = BuildNotification(bnc)
bn.createMsg()
bn.send()
bn.storeLogRecord()
print("Report sent. End.")