blob: b7c9c2e687eae43a02ebe291b28085325398df6a [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
Devin Lim61643762017-12-07 15:55:38 -080024import groovy.time.*
Devin Limb734ea52018-05-14 14:13:05 -070025generalFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/GeneralFuncs.groovy' )
26fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
Devin Limfe9a4cb2018-05-11 17:06:21 -070027
28fileRelated.init()
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -080029
Devin Lim61643762017-12-07 15:55:38 -080030def initializeTrend( machine ){
Devin Limf5175192018-05-14 19:13:22 -070031 // For initializing any trend graph jobs
32 // machine : Either VM,BM, or Fabric#
33
Devin Lim61643762017-12-07 15:55:38 -080034 table_name = "executed_test_tests"
35 result_name = "executed_test_results"
36 testMachine = "TestStation-" + machine + "s";
37 this.machine = machine
38 isSCPF = false
Devin Lim981f80b2018-04-09 11:25:59 -070039 isTrend = true
Devin Lim61643762017-12-07 15:55:38 -080040}
41def initialize( type, SCPFfuncs ){
Devin Limf5175192018-05-14 19:13:22 -070042 // Initializing for SCPF tests
43 // type : type of the test ( SR,FUNC,SCPF... )
44 // Passing the SCPFfunction which will be PerformanceFuncs.groovy
45
Devin Lim61643762017-12-07 15:55:38 -080046 init( type )
47 SCPFfunc = SCPFfuncs
48 isSCPF = true
49 machine = machineType[ type ]
50}
51def initialize( type ){
Devin Limf5175192018-05-14 19:13:22 -070052 // initializing for FUNC,HA,SR, and USECASE
53 // type : type of the test ( SR,FUNC,SCPF... )
54
Devin Lim61643762017-12-07 15:55:38 -080055 init( type )
56 SCPFfunc = null
57 table_name = "executed_test_tests"
58 result_name = "executed_test_results"
Devin Limfe9a4cb2018-05-11 17:06:21 -070059 trend_generator_file = fileRelated.trendMultiple
60 build_stats_generator_file = fileRelated.histogramMultiple
Devin Lim61643762017-12-07 15:55:38 -080061 isSCPF = false
62}
63def init( type ){
Devin Limf5175192018-05-14 19:13:22 -070064 // type : type of the test ( SR,FUNC,SCPF... )
65
Devin Lim61643762017-12-07 15:55:38 -080066 machineType = [ "FUNC" : "VM",
67 "HA" : "VM",
Devin Lim431408d2018-03-23 17:51:31 -070068 "SR" : "Fabric",
Devin Lim61643762017-12-07 15:55:38 -080069 "SCPF" : "BM",
70 "USECASE" : "BM" ]
71 testType = type;
72 testMachine = "TestStation-" + machineType[ type ] + "s";
Devin Lim981f80b2018-04-09 11:25:59 -070073 isTrend = false
Devin Lim61643762017-12-07 15:55:38 -080074}
Devin Lim86e40532018-04-06 12:44:06 -070075def additionalInitForSR( branch ){
Devin Limf5175192018-05-14 19:13:22 -070076 // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running.
77 // branch : branch of the onos. ( master, 1.12, 1.13... )
78
Devin Limc38e6932018-04-06 18:04:33 -070079 testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size()-1, fabricOn( branch ) ) ).toString()
Devin Lim6cccad52018-04-09 11:32:19 -070080 if( isTrend )
81 machine += fabricOn( branch )
82 else
83 machineType[ testType ] += fabricOn( branch )
Devin Lim86e40532018-04-06 12:44:06 -070084 print testMachine
85}
86def fabricOn( branch ){
Devin Limf5175192018-05-14 19:13:22 -070087 // gets the fabric machines with the branch of onos.
88 // branch : master, 1.12, 1.13...
Devin Limc8ecd6c2018-05-25 13:27:22 -070089 // branch.reverse().take(4).reverse() will get last 4 characters of the string.
You Wang96b98ad2018-05-25 12:14:45 -070090 switch( branch.reverse().take(4).reverse() ) {
Devin Limc8ecd6c2018-05-25 13:27:22 -070091 case "ster": return "4"
You Wang96b98ad2018-05-25 12:14:45 -070092 case "1.13": return "2"
93 case "1.12": return "3"
Devin Limc8ecd6c2018-05-25 13:27:22 -070094 default: return "4"
You Wang96b98ad2018-05-25 12:14:45 -070095 }
Devin Lim86e40532018-04-06 12:44:06 -070096}
Devin Lim61643762017-12-07 15:55:38 -080097def printType(){
Devin Limf5175192018-05-14 19:13:22 -070098 // print the test type and test machine that was initialized.
99
Devin Lim61643762017-12-07 15:55:38 -0800100 echo testType;
101 echo testMachine;
102}
103def getProperties(){
Devin Limf5175192018-05-14 19:13:22 -0700104 // get the properties of the test by reading the TestONOS.property
105
Devin Lim61643762017-12-07 15:55:38 -0800106 node( testMachine ){
107 return readProperties( file:'/var/jenkins/TestONOS.property' );
108 }
109}
110def getTestsToRun( testList ){
Devin Limf5175192018-05-14 19:13:22 -0700111 // get test to run by tokenizing the list.
112
Devin Lim61643762017-12-07 15:55:38 -0800113 testList.tokenize("\n;, ")
114}
115def getCurrentTime(){
Devin Limf5175192018-05-14 19:13:22 -0700116 // get time of the PST zone.
117
Devin Limd1fb8e92018-02-28 16:29:33 -0800118 TimeZone.setDefault( TimeZone.getTimeZone('PST') )
Devin Lim61643762017-12-07 15:55:38 -0800119 return new Date();
120}
121def getTotalTime( start, end ){
Devin Limf5175192018-05-14 19:13:22 -0700122 // get total time of the test using start and end time.
123
Devin Lim61643762017-12-07 15:55:38 -0800124 return TimeCategory.minus( end, start );
125}
126def printTestToRun( testList ){
Devin Limf5175192018-05-14 19:13:22 -0700127 // printout the list of the test in the list.
128
Devin Lim61643762017-12-07 15:55:38 -0800129 for ( String test : testList ) {
130 println test;
131 }
132}
133def sendResultToSlack( start, isManualRun, branch ){
Devin Limf5175192018-05-14 19:13:22 -0700134 // send the result of the test to the slack when it is not manually running.
135 // start : start time of the test
136 // isManualRun : string that is whether "false" or "true"
137 // branch : branch of the onos.
138
Devin Lim61643762017-12-07 15:55:38 -0800139 try{
140 if( isManualRun == "false" ){
141 end = getCurrentTime();
142 TimeDuration duration = TimeCategory.minus( end , start );
143 slackSend( color:"#5816EE",
144 message: testType + "-" + branch + " tests ended at: " + end.toString() + "\nTime took : " + duration )
145 }
146 }
147 catch( all ){}
148}
149def initAndRunTest( testName, testCategory ){
Devin Limf5175192018-05-14 19:13:22 -0700150 // Bash script that will
151 // Initialize the environment to the machine and run the test.
152 // testName : name of the test
153 // testCategory : (SR,FUNC ... )
154
Devin Lim61643762017-12-07 15:55:38 -0800155 return '''#!/bin/bash -l
156 set -i # interactive
157 set +e
158 shopt -s expand_aliases # expand alias in non-interactive mode
159 export PYTHONUNBUFFERED=1
160 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800161 echo "ONOS Branch is: $ONOSBranch"
162 echo "TestON Branch is: $TestONBranch"
163 echo "Test date: "
164 date
165 cd ~
166 export PATH=$PATH:onos/tools/test/bin
167 timeout 240 stc shutdown | head -100
168 timeout 240 stc teardown | head -100
169 timeout 240 stc shutdown | head -100
170 cd ~/OnosSystemTest/TestON/bin
171 git log |head
172 ./cleanup.sh -f
Devin Lima7b97a42018-04-09 14:26:38 -0700173 ''' + "./cli.py run " + ( !isSCPF ? testName : testCategory[ testName ][ 'test' ] ) + " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800174 ./cleanup.sh -f
175 # cleanup config changes
176 cd ~/onos/tools/package/config
177 git clean -df'''
178}
179def copyLogs( testName ){
Devin Limf5175192018-05-14 19:13:22 -0700180 // bash script part for copy the logs and other neccessary element for SR tests.
181 // testName : name of the test.
182
Devin Lim61643762017-12-07 15:55:38 -0800183 result = ""
184 if( testType == "SR" ){
185 result = '''
186 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
187 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
188 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
189 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700190 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700191 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800192 '''
193 }
194 return result
195}
196def cleanAndCopyFiles( testName ){
Devin Limf5175192018-05-14 19:13:22 -0700197 // clean up some files that were in the folder and copy the new files from the log
198 // testName : name of the test
199
Devin Lim61643762017-12-07 15:55:38 -0800200 return '''#!/bin/bash -i
201 set +e
202 echo "ONOS Branch is: ${ONOSBranch}"
203 echo "TestON Branch is: ${TestONBranch}"
204 echo "Job name is: "''' + testName + '''
205 echo "Workspace is: ${WORKSPACE}/"
206 echo "Wiki page to post is: ${WikiPrefix}-"
207 # remove any leftover files from previous tests
208 sudo rm ${WORKSPACE}/*Wiki.txt
209 sudo rm ${WORKSPACE}/*Summary.txt
210 sudo rm ${WORKSPACE}/*Result.txt
211 sudo rm ${WORKSPACE}/*.csv
212 #copy files to workspace
213 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
214 ''' + copyLogs( testName ) + '''
215 sudo cp *.txt ${WORKSPACE}/
216 sudo cp *.csv ${WORKSPACE}/
217 cd ${WORKSPACE}/
218 for i in *.csv
219 do mv "$i" "$WikiPrefix"-"$i"
220 done
221 ls -al
222 cd '''
223}
224def fetchLogs( testName ){
Devin Limf5175192018-05-14 19:13:22 -0700225 // fetch the logs of onos from onos nodes to onos System Test logs
226 // testName: name of the test
227
Devin Lim61643762017-12-07 15:55:38 -0800228 return '''#!/bin/bash
229 set +e
230 cd ~/OnosSystemTest/TestON/logs
231 echo "Job Name is: " + ''' + testName + '''
232 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
233 echo "########################################################################################"
234 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
235 echo "########################################################################################"
236 cd $TestONlogDir
237 if [ $? -eq 1 ]
238 then
239 echo "Job name does not match any test suite name to move log!"
240 else
241 pwd
242 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
243 fi
244 cd'''
245}
246def isPostingResult( manual, postresult ){
Devin Limf5175192018-05-14 19:13:22 -0700247 // check if it is posting the result.
248 // posting when it is automatically running or has postResult condition from the manual run
249
Devin Lim61643762017-12-07 15:55:38 -0800250 return manual == "false" || postresult == "true"
251}
252def postResult( prop, graphOnly ){
Devin Limf5175192018-05-14 19:13:22 -0700253 // post the result by triggering postjob.
254 // prop : property dictionary that was read from the machine.
255 // graphOnly : if it is graph generating job
256
Devin Lim61643762017-12-07 15:55:38 -0800257 if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
258 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
259 }
260}
261def postLogs( testName, prefix ){
Devin Limf5175192018-05-14 19:13:22 -0700262 // posting logs of the onos jobs specifically SR tests
263 // testName : name of the test
264 // prefix : branch prefix ( master, 1.12, 1.13 ... )
265
Devin Lim61643762017-12-07 15:55:38 -0800266 resultURL = ""
267 if( testType == "SR" ){
268 def post = build job: "SR-log-" + prefix, propagate: false
269 resultURL = post.getAbsoluteUrl()
270 }
271 return resultURL
272}
273def getSlackChannel(){
Devin Limf5175192018-05-14 19:13:22 -0700274 // get name of the slack channel.
275 // if the test is SR, it will return sr-failures
276
Devin Lim61643762017-12-07 15:55:38 -0800277 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
278}
279def analyzeResult( prop, workSpace, testName, otherTestName, resultURL, wikiLink, isSCPF ){
Devin Limf5175192018-05-14 19:13:22 -0700280 // analyzing the result of the test and send to slack if the test was failed.
281 // prop : property dictionary
282 // workSpace : workSpace where the result file is saved
283 // testName : real name of the test
284 // otherTestName : other name of the test for SCPF tests ( SCPFflowTPFobj )
285 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
286 // wikiLink : link of the wiki page where the result was posted
287 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
288
Devin Lim61643762017-12-07 15:55:38 -0800289 node( testMachine ){
290 resultContents = readFile workSpace + "/" + testName + "Result.txt"
291 resultContents = resultContents.split("\n")
292 if( resultContents[ 0 ] == "1" ){
293 print "All passed"
294 }else{
295 print "Failed"
296 if( prop[ "manualRun" ] == "false" ){
297 slackSend( channel:getSlackChannel(), color:"FF0000", message: "[" + prop[ "ONOSBranch" ] + "]"
298 + otherTestName + " : Failed!\n" + resultContents[ 1 ] + "\n"
299 + "[TestON log] : \n"
Devin Limd1fb8e92018-02-28 16:29:33 -0800300 + "https://jenkins.onosproject.org/blue/organizations/jenkins/${env.JOB_NAME}/detail/${env.JOB_NAME}/${env.BUILD_NUMBER}/pipeline"
Devin Lim61643762017-12-07 15:55:38 -0800301 + ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" + "https://wiki.onosproject.org/display/ONOS/" + wikiLink.replaceAll( "\\s","+" ) ) )
302 + ( resultURL != "" ? ( "\n[Karaf log] : \n" + resultURL + "artifact/" ) : "" ),
303 teamDomain: 'onosproject' )
304 }
305 Failed
306 }
307 }
308}
Devin Lime89761a2018-03-16 17:52:57 -0700309def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Devin Limf5175192018-05-14 19:13:22 -0700310 // publish HTML script to wiki confluence
311 // isManualRun : string "true" "false"
312 // isPostResult : string "true" "false"
313 // wikiLink : link of the wiki page to publish
314 // file : name of the file to be published
315
Devin Lime89761a2018-03-16 17:52:57 -0700316 if( isPostingResult( isManualRun, isPostResult ) ){
Devin Lim61643762017-12-07 15:55:38 -0800317 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
Devin Lim1253ae82018-02-26 11:13:36 -0800318 attachArchivedArtifacts: true, buildIfUnstable: true,
Devin Lim61643762017-12-07 15:55:38 -0800319 editorList: [
320 confluenceWritePage( confluenceFile( file ) )
321 ]
322 }
323
324}
325def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file, graph_saved_directory ) {
Devin Limf5175192018-05-14 19:13:22 -0700326 // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
327 // testName : name of the test
328 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty result on pipeline view
329 // prop : dictionary property on the machine
330 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
331 // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
332 // testCategory : category of the test ( SCPF, SR, FUNC ... )
333 // graph_generator_file : Rscript file with the full path.
334 // graph_saved_directory : where the generated graph will be saved to.
335
Devin Lim61643762017-12-07 15:55:38 -0800336 return {
337 catchError{
338 stage( testName ) {
339 if ( toBeRun ){
340 workSpace = "/var/jenkins/workspace/" + testName
341 def fileContents = ""
342 node( testMachine ){
343 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
344 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
345 'TestONBranch=' + prop[ "TestONBranch" ],
346 'ONOSTag=' + prop[ "ONOSTag" ],
347 'WikiPrefix=' + prop[ "WikiPrefix" ],
348 'WORKSPACE=' + workSpace ] ){
349 if( ! graphOnly ){
350 sh initAndRunTest( testName, testCategory )
351 // For the Wiki page
352 sh cleanAndCopyFiles( pureTestName )
353 }
354 databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory )
355 if( ! graphOnly ){
356 sh fetchLogs( pureTestName )
357 if( !isSCPF )
Devin Lime89761a2018-03-16 17:52:57 -0700358 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
359 testCategory[ testName ][ 'wiki_link' ],
360 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
Devin Lim61643762017-12-07 15:55:38 -0800361 }
362 }
363
364
365 }
366 postResult( prop, graphOnly )
367 if( ! graphOnly ){
368 resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
369 analyzeResult( prop, workSpace, pureTestName, testName, resultURL, isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ], isSCPF )
370 }
371 }
372 }
373 }
374 }
375}
Devin Lim61643762017-12-07 15:55:38 -0800376def databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700377 // part where it insert the data into the database.
378 // It will use the predefined encrypted variables from the Jenkins.
379 // prop : property dictionary that was read from the machine
380 // testName : name of the test
381 // graphOnly : boolean whether it is graph only or not
382 // graph_generator_file : Rscript file with the full path.
383 // graph_saved_directory : where the generated graph will be saved to.
384
Devin Lim61643762017-12-07 15:55:38 -0800385 if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
386 // Post Results
387 withCredentials( [
388 string( credentialsId: 'db_pass', variable: 'pass' ),
389 string( credentialsId: 'db_user', variable: 'user' ),
390 string( credentialsId: 'db_host', variable: 'host' ),
391 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
392 def database_command = generalFuncs.database_command_create( pass, host, port, user ) + ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
393 sh '''#!/bin/bash
394 export DATE=\$(date +%F_%T)
395 cd ~
396 pwd ''' + ( graphOnly ? "" : ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], testName, database_command ) :
397 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
398 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ) : SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
399 }
400 }
401}
Devin Lim86e40532018-04-06 12:44:06 -0700402def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart, save_path, pieTestListPart ){
Devin Limf5175192018-05-14 19:13:22 -0700403 // function that will generate the category stat graphs for the overall test.
404 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
405 // manualRun : string of "true" or "false"
406 // postresult : string of "true" or "false"
407 // stat_file : file name with full path for Rscript for the stat graph
408 // pie_file : file name with full path for Rscript for the pie graph
409 // type : type of the test ( USECASE, FUNC, HA )
410 // branch : branch of the test ( master, onos-1.12, onos-1.13 )
411 // testListPart : list of the test to be included
412 // save_path : path that will save the graphs to
413 // pieTestListPart : list of the test for pie graph
Devin Lim61643762017-12-07 15:55:38 -0800414
415 if( isPostingResult( manualRun, postresult ) ){
Devin Lim86e40532018-04-06 12:44:06 -0700416 node( testMachineOn ){
Devin Lim61643762017-12-07 15:55:38 -0800417
418 withCredentials( [
419 string( credentialsId: 'db_pass', variable: 'pass' ),
420 string( credentialsId: 'db_user', variable: 'user' ),
421 string( credentialsId: 'db_host', variable: 'host' ),
422 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
423 sh '''#!/bin/bash
Devin Limfe9a4cb2018-05-11 17:06:21 -0700424 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type, branch ) + " \"" + testListPart + "\" latest " + save_path + '''
425 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y', save_path ) + '''
426 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
Devin Lim61643762017-12-07 15:55:38 -0800427 }
428 }
429 postResult( [], true )
430 }
431}
432def makeTestList( list, commaNeeded ){
Devin Limf5175192018-05-14 19:13:22 -0700433 // make the list of the test in to a string.
434 // list : list of the test
435 // commaNeeded : if comma is needed for the string
436
Devin Lim61643762017-12-07 15:55:38 -0800437 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
438}
439def createStatsList( testCategory, list, semiNeeded ){
Devin Limf5175192018-05-14 19:13:22 -0700440 // make the list for stats
441 // testCategory : category of the test
442 // list : list of the test
443 // semiNeeded: if semi colon is needed
444
Devin Lim61643762017-12-07 15:55:38 -0800445 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
446}
447def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700448 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800449
450 if( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
451 node( testMachine ){
452
453 withCredentials( [
454 string( credentialsId: 'db_pass', variable: 'pass' ),
455 string( credentialsId: 'db_user', variable: 'user' ),
456 string( credentialsId: 'db_host', variable: 'host' ),
457 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
458 testList = generalFuncs.getTestList( testCategory )
459 sh '''#!/bin/bash
460 ''' + generalFuncs.basicGraphPart( trend_generator_file, host, port, user, pass, testType, prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
461 }
462 }
463 postResult( prop, false )
464 }
465}
466def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Devin Limf5175192018-05-14 19:13:22 -0700467 // Rcommand for the pie graph
468
Devin Lim61643762017-12-07 15:55:38 -0800469 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) + " \"" + testList + "\" latest " + yOrN + " " + path
470}
471def sqlCommand( testName ){
Devin Limf5175192018-05-14 19:13:22 -0700472 // get the inserting sqlCommand for non-SCPF tests.
473
Devin Lim61643762017-12-07 15:55:38 -0800474 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
475}
476def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Devin Limf5175192018-05-14 19:13:22 -0700477 // get the graphGenerating R command for non-SCPF tests
478
Devin Lim61643762017-12-07 15:55:38 -0800479 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName, prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
480}
481def databasePart( wikiPrefix, testName, database_command ){
Devin Limf5175192018-05-14 19:13:22 -0700482 // to read and insert the data from .csv to the database
483
Devin Lim61643762017-12-07 15:55:38 -0800484 return '''
485 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
486 do
487 echo \$line
488 echo ''' + database_command + '''
489 done '''
490}
Devin Lim86e40532018-04-06 12:44:06 -0700491def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file, graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700492 // Will generate the stats graph.
493
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800494 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
495 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
496 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
497 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
498 makeTestList( AllTheTests[ "HA" ], true ) +
499 makeTestList( AllTheTests[ "USECASE" ], false )
Devin Lim86e40532018-04-06 12:44:06 -0700500 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file, "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800501}
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700502def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700503 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700504 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
505}
Devin Lim1253ae82018-02-26 11:13:36 -0800506return this;