blob: 9cf5e7b1a8f75052af381fcac715304819f09311 [file] [log] [blame]
Devin Lime1346f42018-05-15 15:41:36 -07001#!groovy
Devin Limf5175192018-05-14 19:13:22 -07002// Copyright 2017 Open Networking Foundation (ONF)
3//
4// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7//
8// TestON is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation, either version 2 of the License, or
11// (at your option) any later version.
12//
13// TestON is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21// This is the dependency Jenkins script.
22// it has some common functions that runs test and generate graph.
23
Jon Hall6af749d2018-05-29 12:59:47 -070024import groovy.time.TimeCategory
25import groovy.time.TimeDuration
26
Devin Limb734ea52018-05-14 14:13:05 -070027generalFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/GeneralFuncs.groovy' )
28fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
Devin Limfe9a4cb2018-05-11 17:06:21 -070029
30fileRelated.init()
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -080031
Devin Lim61643762017-12-07 15:55:38 -080032def initializeTrend( machine ){
Jon Hall6af749d2018-05-29 12:59:47 -070033 // For initializing any trend graph jobs
34 // machine : Either VM,BM, or Fabric#
Devin Limf5175192018-05-14 19:13:22 -070035
Jon Hall6af749d2018-05-29 12:59:47 -070036 table_name = "executed_test_tests"
37 result_name = "executed_test_results"
38 testMachine = "TestStation-" + machine + "s"
39 this.machine = machine
40 isSCPF = false
41 isTrend = true
Devin Lim61643762017-12-07 15:55:38 -080042}
Jon Hall6af749d2018-05-29 12:59:47 -070043
Devin Lim61643762017-12-07 15:55:38 -080044def initialize( type, SCPFfuncs ){
Jon Hall6af749d2018-05-29 12:59:47 -070045 // Initializing for SCPF tests
46 // type : type of the test ( SR,FUNC,SCPF... )
47 // Passing the SCPFfunction which will be PerformanceFuncs.groovy
Devin Limf5175192018-05-14 19:13:22 -070048
Jon Hall6af749d2018-05-29 12:59:47 -070049 init( type )
50 SCPFfunc = SCPFfuncs
51 isSCPF = true
52 machine = machineType[ type ]
Devin Lim61643762017-12-07 15:55:38 -080053}
Jon Hall6af749d2018-05-29 12:59:47 -070054
Devin Lim61643762017-12-07 15:55:38 -080055def initialize( type ){
Jon Hall6af749d2018-05-29 12:59:47 -070056 // initializing for FUNC,HA,SR, and USECASE
57 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070058
Jon Hall6af749d2018-05-29 12:59:47 -070059 init( type )
60 SCPFfunc = null
61 table_name = "executed_test_tests"
62 result_name = "executed_test_results"
63 trend_generator_file = fileRelated.trendMultiple
64 build_stats_generator_file = fileRelated.histogramMultiple
65 isSCPF = false
Devin Lim61643762017-12-07 15:55:38 -080066}
Jon Hall6af749d2018-05-29 12:59:47 -070067
Devin Lim61643762017-12-07 15:55:38 -080068def init( type ){
Jon Hall6af749d2018-05-29 12:59:47 -070069 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070070
Jon Hall6af749d2018-05-29 12:59:47 -070071 machineType = [ "FUNC": "VM",
72 "HA": "VM",
73 "SR": "Fabric",
74 "SCPF": "BM",
75 "USECASE": "BM" ]
76 testType = type
77 testMachine = "TestStation-" + machineType[ type ] + "s"
78 isTrend = false
Devin Lim61643762017-12-07 15:55:38 -080079}
Jon Hall6af749d2018-05-29 12:59:47 -070080
Devin Lim86e40532018-04-06 12:44:06 -070081def additionalInitForSR( branch ){
Jon Hall6af749d2018-05-29 12:59:47 -070082 // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running.
83 // branch : branch of the onos. ( master, 1.12, 1.13... )
Devin Limf5175192018-05-14 19:13:22 -070084
Jon Hall6af749d2018-05-29 12:59:47 -070085 testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size() - 1, fabricOn( branch ) ) ).
86 toString()
87 if ( isTrend ){
88 machine += fabricOn( branch )
Devin Lim61643762017-12-07 15:55:38 -080089 }
Jon Hall6af749d2018-05-29 12:59:47 -070090 else {
91 machineType[ testType ] += fabricOn( branch )
92 }
93 print testMachine
Devin Lim61643762017-12-07 15:55:38 -080094}
Devin Limf5175192018-05-14 19:13:22 -070095
Jon Hall6af749d2018-05-29 12:59:47 -070096def fabricOn( branch ){
97 // gets the fabric machines with the branch of onos.
98 // branch : master, 1.12, 1.13...
99 // branch.reverse().take(4).reverse() will get last 4 characters of the string.
100 switch ( branch.reverse().take( 4 ).reverse() ){
101 case "ster": return "4"
102 case "1.13": return "2"
103 case "1.12": return "3"
104 default: return "4"
105 }
106}
107
108def printType(){
109 // print the test type and test machine that was initialized.
110
111 echo testType
112 echo testMachine
113}
114
115def getProperties(){
116 // get the properties of the test by reading the TestONOS.property
117
118 node( testMachine ) {
119 return readProperties( file: '/var/jenkins/TestONOS.property' )
120 }
121}
122
123def getTestsToRun( testList ){
124 // get test to run by tokenizing the list.
125
126 testList.tokenize( "\n;, " )
127}
128
129def getCurrentTime(){
130 // get time of the PST zone.
131
132 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
133 return new Date()
134}
135
136def getTotalTime( start, end ){
137 // get total time of the test using start and end time.
138
139 return TimeCategory.minus( end, start )
140}
141
142def printTestToRun( testList ){
143 // printout the list of the test in the list.
144
145 for ( String test : testList ){
146 println test
147 }
148}
149
150def sendResultToSlack( start, isManualRun, branch ){
151 // send the result of the test to the slack when it is not manually running.
152 // start : start time of the test
153 // isManualRun : string that is whether "false" or "true"
154 // branch : branch of the onos.
155
156 try {
157 if ( isManualRun == "false" ){
158 end = getCurrentTime()
159 TimeDuration duration = TimeCategory.minus( end, start )
160 slackSend( color: "#5816EE",
161 message: testType + "-" + branch + " tests ended at: " + end.toString() +
162 "\nTime took : " + duration )
163 }
164 }
165 catch ( all ){
166 }
167}
168
169def initAndRunTest( testName, testCategory ){
170 // Bash script that will
171 // Initialize the environment to the machine and run the test.
172 // testName : name of the test
173 // testCategory : (SR,FUNC ... )
174
175 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800176 set -i # interactive
177 set +e
178 shopt -s expand_aliases # expand alias in non-interactive mode
179 export PYTHONUNBUFFERED=1
180 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800181 echo "ONOS Branch is: $ONOSBranch"
182 echo "TestON Branch is: $TestONBranch"
183 echo "Test date: "
184 date
185 cd ~
186 export PATH=$PATH:onos/tools/test/bin
187 timeout 240 stc shutdown | head -100
188 timeout 240 stc teardown | head -100
189 timeout 240 stc shutdown | head -100
190 cd ~/OnosSystemTest/TestON/bin
191 git log |head
192 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700193 ''' + "./cli.py run " +
194 ( !isSCPF ? testName : testCategory[ testName ][ 'test' ] ) +
195 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800196 ./cleanup.sh -f
197 # cleanup config changes
198 cd ~/onos/tools/package/config
199 git clean -df'''
200}
Devin Limf5175192018-05-14 19:13:22 -0700201
Jon Hall6af749d2018-05-29 12:59:47 -0700202def copyLogs( testName ){
203 // bash script part for copy the logs and other neccessary element for SR tests.
204 // testName : name of the test.
205
206 result = ""
207 if ( testType == "SR" ){
208 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800209 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
210 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
211 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
212 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700213 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700214 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800215 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700216 }
217 return result
Devin Lim61643762017-12-07 15:55:38 -0800218}
Devin Limf5175192018-05-14 19:13:22 -0700219
Jon Hall6af749d2018-05-29 12:59:47 -0700220def cleanAndCopyFiles( testName ){
221 // clean up some files that were in the folder and copy the new files from the log
222 // testName : name of the test
223
224 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800225 set +e
226 echo "ONOS Branch is: ${ONOSBranch}"
227 echo "TestON Branch is: ${TestONBranch}"
228 echo "Job name is: "''' + testName + '''
229 echo "Workspace is: ${WORKSPACE}/"
230 echo "Wiki page to post is: ${WikiPrefix}-"
231 # remove any leftover files from previous tests
232 sudo rm ${WORKSPACE}/*Wiki.txt
233 sudo rm ${WORKSPACE}/*Summary.txt
234 sudo rm ${WORKSPACE}/*Result.txt
235 sudo rm ${WORKSPACE}/*.csv
236 #copy files to workspace
237 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
238 ''' + copyLogs( testName ) + '''
239 sudo cp *.txt ${WORKSPACE}/
240 sudo cp *.csv ${WORKSPACE}/
241 cd ${WORKSPACE}/
242 for i in *.csv
243 do mv "$i" "$WikiPrefix"-"$i"
244 done
245 ls -al
246 cd '''
247}
Devin Limf5175192018-05-14 19:13:22 -0700248
Jon Hall6af749d2018-05-29 12:59:47 -0700249def fetchLogs( testName ){
250 // fetch the logs of onos from onos nodes to onos System Test logs
251 // testName: name of the test
252
253 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800254 set +e
255 cd ~/OnosSystemTest/TestON/logs
256 echo "Job Name is: " + ''' + testName + '''
257 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
258 echo "########################################################################################"
259 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
260 echo "########################################################################################"
261 cd $TestONlogDir
262 if [ $? -eq 1 ]
263 then
264 echo "Job name does not match any test suite name to move log!"
265 else
266 pwd
267 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
268 fi
269 cd'''
270}
Jon Hall6af749d2018-05-29 12:59:47 -0700271
Devin Lim61643762017-12-07 15:55:38 -0800272def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700273 // check if it is posting the result.
274 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700275
Jon Hall6af749d2018-05-29 12:59:47 -0700276 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800277}
Jon Hall6af749d2018-05-29 12:59:47 -0700278
Devin Lim61643762017-12-07 15:55:38 -0800279def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700280 // post the result by triggering postjob.
281 // prop : property dictionary that was read from the machine.
282 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700283
Jon Hall6af749d2018-05-29 12:59:47 -0700284 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
285 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800286 }
Devin Lim61643762017-12-07 15:55:38 -0800287}
Jon Hall6af749d2018-05-29 12:59:47 -0700288
289def postLogs( testName, prefix ){
290 // posting logs of the onos jobs specifically SR tests
291 // testName : name of the test
292 // prefix : branch prefix ( master, 1.12, 1.13 ... )
293
294 resultURL = ""
295 if ( testType == "SR" ){
296 def post = build job: "SR-log-" + prefix, propagate: false
297 resultURL = post.getAbsoluteUrl()
298 }
299 return resultURL
300}
301
302def getSlackChannel(){
303 // get name of the slack channel.
304 // if the test is SR, it will return sr-failures
305
306 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
307}
308
309def analyzeResult( prop, workSpace, testName, otherTestName, resultURL, wikiLink, isSCPF ){
310 // analyzing the result of the test and send to slack if the test was failed.
311 // prop : property dictionary
312 // workSpace : workSpace where the result file is saved
313 // testName : real name of the test
314 // otherTestName : other name of the test for SCPF tests ( SCPFflowTPFobj )
315 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
316 // wikiLink : link of the wiki page where the result was posted
317 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
318
319 node( testMachine ) {
320 def resultContents = readFile( workSpace + "/" + testName + "Result.txt" )
321 resultContents = resultContents.split( "\n" )
322 if ( resultContents[ 0 ] == "1" ){
323 print "All passed"
324 }
325 else {
326 print "Failed"
327 if ( prop[ "manualRun" ] == "false" ){
328 slackSend( channel: getSlackChannel(),
329 color: "FF0000",
330 message: "[" + prop[ "ONOSBranch" ] + "]" + otherTestName + " : Failed!\n" +
331 resultContents[ 1 ] + "\n" +
332 "[TestON log] : \n" +
333 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
334 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
335 "https://wiki.onosproject.org/display/ONOS/" +
336 wikiLink.replaceAll( "\\s", "+" ) ) ) +
337 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
338 resultURL + "artifact/" ) : "" ),
339 teamDomain: 'onosproject' )
340 }
341 Failed
342 }
343 }
344}
345
Devin Lime89761a2018-03-16 17:52:57 -0700346def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700347 // publish HTML script to wiki confluence
348 // isManualRun : string "true" "false"
349 // isPostResult : string "true" "false"
350 // wikiLink : link of the wiki page to publish
351 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700352
Jon Hall6af749d2018-05-29 12:59:47 -0700353 if ( isPostingResult( isManualRun, isPostResult ) ){
354 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
355 attachArchivedArtifacts: true, buildIfUnstable: true,
356 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
357 }
Devin Lim61643762017-12-07 15:55:38 -0800358
359}
Devin Limf5175192018-05-14 19:13:22 -0700360
Jon Hall6af749d2018-05-29 12:59:47 -0700361def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
362 graph_saved_directory ){
363 // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
364 // testName : name of the test
365 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
366 // result on pipeline view
367 // prop : dictionary property on the machine
368 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
369 // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
370 // testCategory : category of the test ( SCPF, SR, FUNC ... )
371 // graph_generator_file : Rscript file with the full path.
372 // graph_saved_directory : where the generated graph will be saved to.
373
374 return {
375 catchError {
376 stage( testName ) {
377 if ( toBeRun ){
378 def workSpace = "/var/jenkins/workspace/" + testName
379 def fileContents = ""
380 node( testMachine ) {
381 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
382 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
383 'TestONBranch=' + prop[ "TestONBranch" ],
384 'ONOSTag=' + prop[ "ONOSTag" ],
385 'WikiPrefix=' + prop[ "WikiPrefix" ],
386 'WORKSPACE=' + workSpace ] ) {
387 if ( !graphOnly ){
388 sh initAndRunTest( testName, testCategory )
389 // For the Wiki page
390 sh cleanAndCopyFiles( pureTestName )
391 }
392 databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory )
393 if ( !graphOnly ){
394 sh fetchLogs( pureTestName )
395 if ( !isSCPF ){
396 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
397 testCategory[ testName ][ 'wiki_link' ],
398 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
399 }
400 }
Devin Lim61643762017-12-07 15:55:38 -0800401 }
Jon Hall6af749d2018-05-29 12:59:47 -0700402 }
Devin Lim61643762017-12-07 15:55:38 -0800403 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700404 if ( !graphOnly ){
405 resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
406 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
407 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
408 isSCPF )
409 }
410 }
411 }
412 }
413 }
Devin Lim61643762017-12-07 15:55:38 -0800414}
Devin Limf5175192018-05-14 19:13:22 -0700415
Jon Hall6af749d2018-05-29 12:59:47 -0700416def databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory ){
417 // part where it insert the data into the database.
418 // It will use the predefined encrypted variables from the Jenkins.
419 // prop : property dictionary that was read from the machine
420 // testName : name of the test
421 // graphOnly : boolean whether it is graph only or not
422 // graph_generator_file : Rscript file with the full path.
423 // graph_saved_directory : where the generated graph will be saved to.
424
425 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
426 // Post Results
427 withCredentials( [
428 string( credentialsId: 'db_pass', variable: 'pass' ),
429 string( credentialsId: 'db_user', variable: 'user' ),
430 string( credentialsId: 'db_host', variable: 'host' ),
431 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
432 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
433 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
434 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800435 export DATE=\$(date +%F_%T)
436 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700437 pwd ''' + ( graphOnly ? "" :
438 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], testName, database_command ) :
439 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
440 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
441 graph_generator_file ) :
442 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800443 }
Devin Lim61643762017-12-07 15:55:38 -0800444 }
445}
Jon Hall6af749d2018-05-29 12:59:47 -0700446
447def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
448 save_path, pieTestListPart ){
449 // function that will generate the category stat graphs for the overall test.
450 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
451 // manualRun : string of "true" or "false"
452 // postresult : string of "true" or "false"
453 // stat_file : file name with full path for Rscript for the stat graph
454 // pie_file : file name with full path for Rscript for the pie graph
455 // type : type of the test ( USECASE, FUNC, HA )
456 // branch : branch of the test ( master, onos-1.12, onos-1.13 )
457 // testListPart : list of the test to be included
458 // save_path : path that will save the graphs to
459 // pieTestListPart : list of the test for pie graph
460
461 if ( isPostingResult( manualRun, postresult ) ){
462 node( testMachineOn ) {
463
464 withCredentials( [
465 string( credentialsId: 'db_pass', variable: 'pass' ),
466 string( credentialsId: 'db_user', variable: 'user' ),
467 string( credentialsId: 'db_host', variable: 'host' ),
468 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
469 sh '''#!/bin/bash
470 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
471 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
472 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
473 save_path ) + '''
474 ''' +
475 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
476 }
477 }
478 postResult( [ ], true )
479 }
480}
481
Devin Lim61643762017-12-07 15:55:38 -0800482def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700483 // make the list of the test in to a string.
484 // list : list of the test
485 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700486
Jon Hall6af749d2018-05-29 12:59:47 -0700487 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800488}
Jon Hall6af749d2018-05-29 12:59:47 -0700489
Devin Lim61643762017-12-07 15:55:38 -0800490def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700491 // make the list for stats
492 // testCategory : category of the test
493 // list : list of the test
494 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700495
Jon Hall6af749d2018-05-29 12:59:47 -0700496 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800497}
Jon Hall6af749d2018-05-29 12:59:47 -0700498
Devin Lim61643762017-12-07 15:55:38 -0800499def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700500 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800501
Jon Hall6af749d2018-05-29 12:59:47 -0700502 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
503 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800504
Jon Hall6af749d2018-05-29 12:59:47 -0700505 withCredentials( [
506 string( credentialsId: 'db_pass', variable: 'pass' ),
507 string( credentialsId: 'db_user', variable: 'user' ),
508 string( credentialsId: 'db_host', variable: 'host' ),
509 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
510 testList = generalFuncs.getTestList( testCategory )
511 sh '''#!/bin/bash
512 ''' +
513 generalFuncs.basicGraphPart( trend_generator_file, host, port,
514 user, pass, testType,
515 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
516 }
Devin Lim61643762017-12-07 15:55:38 -0800517 }
Jon Hall6af749d2018-05-29 12:59:47 -0700518 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800519 }
520}
Jon Hall6af749d2018-05-29 12:59:47 -0700521
Devin Lim61643762017-12-07 15:55:38 -0800522def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700523 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700524
Jon Hall6af749d2018-05-29 12:59:47 -0700525 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
526 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800527}
Jon Hall6af749d2018-05-29 12:59:47 -0700528
Devin Lim61643762017-12-07 15:55:38 -0800529def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700530 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700531
Jon Hall6af749d2018-05-29 12:59:47 -0700532 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
533 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800534}
Jon Hall6af749d2018-05-29 12:59:47 -0700535
Devin Lim61643762017-12-07 15:55:38 -0800536def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700537 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700538
Jon Hall6af749d2018-05-29 12:59:47 -0700539 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
540 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800541}
Devin Limf5175192018-05-14 19:13:22 -0700542
Jon Hall6af749d2018-05-29 12:59:47 -0700543def databasePart( wikiPrefix, testName, database_command ){
544 // to read and insert the data from .csv to the database
545
546 return '''
Devin Lim61643762017-12-07 15:55:38 -0800547 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
548 do
549 echo \$line
550 echo ''' + database_command + '''
551 done '''
552}
Jon Hall6af749d2018-05-29 12:59:47 -0700553
554def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
555 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700556 // Will generate the stats graph.
557
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800558 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
559 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
560 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
561 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
562 makeTestList( AllTheTests[ "HA" ], true ) +
563 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700564 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
565 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800566}
Jon Hall6af749d2018-05-29 12:59:47 -0700567
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700568def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700569 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700570 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
571}
Jon Hall6af749d2018-05-29 12:59:47 -0700572
573return this