blob: 0b03c6953ccfee3a9a17d20d0789c6caa36631ba [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...
89
Devin Lim36fc1e32018-05-10 15:58:01 -070090 return branch.reverse().take(4).reverse() == "1.12" ? '3' : '2'
Devin Lim86e40532018-04-06 12:44:06 -070091}
Devin Lim61643762017-12-07 15:55:38 -080092def printType(){
Devin Limf5175192018-05-14 19:13:22 -070093 // print the test type and test machine that was initialized.
94
Devin Lim61643762017-12-07 15:55:38 -080095 echo testType;
96 echo testMachine;
97}
98def getProperties(){
Devin Limf5175192018-05-14 19:13:22 -070099 // get the properties of the test by reading the TestONOS.property
100
Devin Lim61643762017-12-07 15:55:38 -0800101 node( testMachine ){
102 return readProperties( file:'/var/jenkins/TestONOS.property' );
103 }
104}
105def getTestsToRun( testList ){
Devin Limf5175192018-05-14 19:13:22 -0700106 // get test to run by tokenizing the list.
107
Devin Lim61643762017-12-07 15:55:38 -0800108 testList.tokenize("\n;, ")
109}
110def getCurrentTime(){
Devin Limf5175192018-05-14 19:13:22 -0700111 // get time of the PST zone.
112
Devin Limd1fb8e92018-02-28 16:29:33 -0800113 TimeZone.setDefault( TimeZone.getTimeZone('PST') )
Devin Lim61643762017-12-07 15:55:38 -0800114 return new Date();
115}
116def getTotalTime( start, end ){
Devin Limf5175192018-05-14 19:13:22 -0700117 // get total time of the test using start and end time.
118
Devin Lim61643762017-12-07 15:55:38 -0800119 return TimeCategory.minus( end, start );
120}
121def printTestToRun( testList ){
Devin Limf5175192018-05-14 19:13:22 -0700122 // printout the list of the test in the list.
123
Devin Lim61643762017-12-07 15:55:38 -0800124 for ( String test : testList ) {
125 println test;
126 }
127}
128def sendResultToSlack( start, isManualRun, branch ){
Devin Limf5175192018-05-14 19:13:22 -0700129 // send the result of the test to the slack when it is not manually running.
130 // start : start time of the test
131 // isManualRun : string that is whether "false" or "true"
132 // branch : branch of the onos.
133
Devin Lim61643762017-12-07 15:55:38 -0800134 try{
135 if( isManualRun == "false" ){
136 end = getCurrentTime();
137 TimeDuration duration = TimeCategory.minus( end , start );
138 slackSend( color:"#5816EE",
139 message: testType + "-" + branch + " tests ended at: " + end.toString() + "\nTime took : " + duration )
140 }
141 }
142 catch( all ){}
143}
144def initAndRunTest( testName, testCategory ){
Devin Limf5175192018-05-14 19:13:22 -0700145 // Bash script that will
146 // Initialize the environment to the machine and run the test.
147 // testName : name of the test
148 // testCategory : (SR,FUNC ... )
149
Devin Lim61643762017-12-07 15:55:38 -0800150 return '''#!/bin/bash -l
151 set -i # interactive
152 set +e
153 shopt -s expand_aliases # expand alias in non-interactive mode
154 export PYTHONUNBUFFERED=1
155 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800156 echo "ONOS Branch is: $ONOSBranch"
157 echo "TestON Branch is: $TestONBranch"
158 echo "Test date: "
159 date
160 cd ~
161 export PATH=$PATH:onos/tools/test/bin
162 timeout 240 stc shutdown | head -100
163 timeout 240 stc teardown | head -100
164 timeout 240 stc shutdown | head -100
165 cd ~/OnosSystemTest/TestON/bin
166 git log |head
167 ./cleanup.sh -f
Devin Lima7b97a42018-04-09 14:26:38 -0700168 ''' + "./cli.py run " + ( !isSCPF ? testName : testCategory[ testName ][ 'test' ] ) + " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800169 ./cleanup.sh -f
170 # cleanup config changes
171 cd ~/onos/tools/package/config
172 git clean -df'''
173}
174def copyLogs( testName ){
Devin Limf5175192018-05-14 19:13:22 -0700175 // bash script part for copy the logs and other neccessary element for SR tests.
176 // testName : name of the test.
177
Devin Lim61643762017-12-07 15:55:38 -0800178 result = ""
179 if( testType == "SR" ){
180 result = '''
181 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
182 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
183 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
184 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700185 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700186 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800187 '''
188 }
189 return result
190}
191def cleanAndCopyFiles( testName ){
Devin Limf5175192018-05-14 19:13:22 -0700192 // clean up some files that were in the folder and copy the new files from the log
193 // testName : name of the test
194
Devin Lim61643762017-12-07 15:55:38 -0800195 return '''#!/bin/bash -i
196 set +e
197 echo "ONOS Branch is: ${ONOSBranch}"
198 echo "TestON Branch is: ${TestONBranch}"
199 echo "Job name is: "''' + testName + '''
200 echo "Workspace is: ${WORKSPACE}/"
201 echo "Wiki page to post is: ${WikiPrefix}-"
202 # remove any leftover files from previous tests
203 sudo rm ${WORKSPACE}/*Wiki.txt
204 sudo rm ${WORKSPACE}/*Summary.txt
205 sudo rm ${WORKSPACE}/*Result.txt
206 sudo rm ${WORKSPACE}/*.csv
207 #copy files to workspace
208 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
209 ''' + copyLogs( testName ) + '''
210 sudo cp *.txt ${WORKSPACE}/
211 sudo cp *.csv ${WORKSPACE}/
212 cd ${WORKSPACE}/
213 for i in *.csv
214 do mv "$i" "$WikiPrefix"-"$i"
215 done
216 ls -al
217 cd '''
218}
219def fetchLogs( testName ){
Devin Limf5175192018-05-14 19:13:22 -0700220 // fetch the logs of onos from onos nodes to onos System Test logs
221 // testName: name of the test
222
Devin Lim61643762017-12-07 15:55:38 -0800223 return '''#!/bin/bash
224 set +e
225 cd ~/OnosSystemTest/TestON/logs
226 echo "Job Name is: " + ''' + testName + '''
227 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
228 echo "########################################################################################"
229 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
230 echo "########################################################################################"
231 cd $TestONlogDir
232 if [ $? -eq 1 ]
233 then
234 echo "Job name does not match any test suite name to move log!"
235 else
236 pwd
237 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
238 fi
239 cd'''
240}
241def isPostingResult( manual, postresult ){
Devin Limf5175192018-05-14 19:13:22 -0700242 // check if it is posting the result.
243 // posting when it is automatically running or has postResult condition from the manual run
244
Devin Lim61643762017-12-07 15:55:38 -0800245 return manual == "false" || postresult == "true"
246}
247def postResult( prop, graphOnly ){
Devin Limf5175192018-05-14 19:13:22 -0700248 // post the result by triggering postjob.
249 // prop : property dictionary that was read from the machine.
250 // graphOnly : if it is graph generating job
251
Devin Lim61643762017-12-07 15:55:38 -0800252 if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
253 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
254 }
255}
256def postLogs( testName, prefix ){
Devin Limf5175192018-05-14 19:13:22 -0700257 // posting logs of the onos jobs specifically SR tests
258 // testName : name of the test
259 // prefix : branch prefix ( master, 1.12, 1.13 ... )
260
Devin Lim61643762017-12-07 15:55:38 -0800261 resultURL = ""
262 if( testType == "SR" ){
263 def post = build job: "SR-log-" + prefix, propagate: false
264 resultURL = post.getAbsoluteUrl()
265 }
266 return resultURL
267}
268def getSlackChannel(){
Devin Limf5175192018-05-14 19:13:22 -0700269 // get name of the slack channel.
270 // if the test is SR, it will return sr-failures
271
Devin Lim61643762017-12-07 15:55:38 -0800272 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
273}
274def analyzeResult( prop, workSpace, testName, otherTestName, resultURL, wikiLink, isSCPF ){
Devin Limf5175192018-05-14 19:13:22 -0700275 // analyzing the result of the test and send to slack if the test was failed.
276 // prop : property dictionary
277 // workSpace : workSpace where the result file is saved
278 // testName : real name of the test
279 // otherTestName : other name of the test for SCPF tests ( SCPFflowTPFobj )
280 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
281 // wikiLink : link of the wiki page where the result was posted
282 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
283
Devin Lim61643762017-12-07 15:55:38 -0800284 node( testMachine ){
285 resultContents = readFile workSpace + "/" + testName + "Result.txt"
286 resultContents = resultContents.split("\n")
287 if( resultContents[ 0 ] == "1" ){
288 print "All passed"
289 }else{
290 print "Failed"
291 if( prop[ "manualRun" ] == "false" ){
292 slackSend( channel:getSlackChannel(), color:"FF0000", message: "[" + prop[ "ONOSBranch" ] + "]"
293 + otherTestName + " : Failed!\n" + resultContents[ 1 ] + "\n"
294 + "[TestON log] : \n"
Devin Limd1fb8e92018-02-28 16:29:33 -0800295 + "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 -0800296 + ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" + "https://wiki.onosproject.org/display/ONOS/" + wikiLink.replaceAll( "\\s","+" ) ) )
297 + ( resultURL != "" ? ( "\n[Karaf log] : \n" + resultURL + "artifact/" ) : "" ),
298 teamDomain: 'onosproject' )
299 }
300 Failed
301 }
302 }
303}
Devin Lime89761a2018-03-16 17:52:57 -0700304def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Devin Limf5175192018-05-14 19:13:22 -0700305 // publish HTML script to wiki confluence
306 // isManualRun : string "true" "false"
307 // isPostResult : string "true" "false"
308 // wikiLink : link of the wiki page to publish
309 // file : name of the file to be published
310
Devin Lime89761a2018-03-16 17:52:57 -0700311 if( isPostingResult( isManualRun, isPostResult ) ){
Devin Lim61643762017-12-07 15:55:38 -0800312 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
Devin Lim1253ae82018-02-26 11:13:36 -0800313 attachArchivedArtifacts: true, buildIfUnstable: true,
Devin Lim61643762017-12-07 15:55:38 -0800314 editorList: [
315 confluenceWritePage( confluenceFile( file ) )
316 ]
317 }
318
319}
320def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file, graph_saved_directory ) {
Devin Limf5175192018-05-14 19:13:22 -0700321 // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
322 // testName : name of the test
323 // 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
324 // prop : dictionary property on the machine
325 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
326 // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
327 // testCategory : category of the test ( SCPF, SR, FUNC ... )
328 // graph_generator_file : Rscript file with the full path.
329 // graph_saved_directory : where the generated graph will be saved to.
330
Devin Lim61643762017-12-07 15:55:38 -0800331 return {
332 catchError{
333 stage( testName ) {
334 if ( toBeRun ){
335 workSpace = "/var/jenkins/workspace/" + testName
336 def fileContents = ""
337 node( testMachine ){
338 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
339 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
340 'TestONBranch=' + prop[ "TestONBranch" ],
341 'ONOSTag=' + prop[ "ONOSTag" ],
342 'WikiPrefix=' + prop[ "WikiPrefix" ],
343 'WORKSPACE=' + workSpace ] ){
344 if( ! graphOnly ){
345 sh initAndRunTest( testName, testCategory )
346 // For the Wiki page
347 sh cleanAndCopyFiles( pureTestName )
348 }
349 databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory )
350 if( ! graphOnly ){
351 sh fetchLogs( pureTestName )
352 if( !isSCPF )
Devin Lime89761a2018-03-16 17:52:57 -0700353 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
354 testCategory[ testName ][ 'wiki_link' ],
355 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
Devin Lim61643762017-12-07 15:55:38 -0800356 }
357 }
358
359
360 }
361 postResult( prop, graphOnly )
362 if( ! graphOnly ){
363 resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
364 analyzeResult( prop, workSpace, pureTestName, testName, resultURL, isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ], isSCPF )
365 }
366 }
367 }
368 }
369 }
370}
Devin Lim61643762017-12-07 15:55:38 -0800371def databaseAndGraph( prop, testName, graphOnly, graph_generator_file, graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700372 // part where it insert the data into the database.
373 // It will use the predefined encrypted variables from the Jenkins.
374 // prop : property dictionary that was read from the machine
375 // testName : name of the test
376 // graphOnly : boolean whether it is graph only or not
377 // graph_generator_file : Rscript file with the full path.
378 // graph_saved_directory : where the generated graph will be saved to.
379
Devin Lim61643762017-12-07 15:55:38 -0800380 if( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
381 // Post Results
382 withCredentials( [
383 string( credentialsId: 'db_pass', variable: 'pass' ),
384 string( credentialsId: 'db_user', variable: 'user' ),
385 string( credentialsId: 'db_host', variable: 'host' ),
386 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
387 def database_command = generalFuncs.database_command_create( pass, host, port, user ) + ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
388 sh '''#!/bin/bash
389 export DATE=\$(date +%F_%T)
390 cd ~
391 pwd ''' + ( graphOnly ? "" : ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], testName, database_command ) :
392 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
393 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ) : SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
394 }
395 }
396}
Devin Lim86e40532018-04-06 12:44:06 -0700397def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart, save_path, pieTestListPart ){
Devin Limf5175192018-05-14 19:13:22 -0700398 // function that will generate the category stat graphs for the overall test.
399 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
400 // manualRun : string of "true" or "false"
401 // postresult : string of "true" or "false"
402 // stat_file : file name with full path for Rscript for the stat graph
403 // pie_file : file name with full path for Rscript for the pie graph
404 // type : type of the test ( USECASE, FUNC, HA )
405 // branch : branch of the test ( master, onos-1.12, onos-1.13 )
406 // testListPart : list of the test to be included
407 // save_path : path that will save the graphs to
408 // pieTestListPart : list of the test for pie graph
Devin Lim61643762017-12-07 15:55:38 -0800409
410 if( isPostingResult( manualRun, postresult ) ){
Devin Lim86e40532018-04-06 12:44:06 -0700411 node( testMachineOn ){
Devin Lim61643762017-12-07 15:55:38 -0800412
413 withCredentials( [
414 string( credentialsId: 'db_pass', variable: 'pass' ),
415 string( credentialsId: 'db_user', variable: 'user' ),
416 string( credentialsId: 'db_host', variable: 'host' ),
417 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
418 sh '''#!/bin/bash
Devin Limfe9a4cb2018-05-11 17:06:21 -0700419 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type, branch ) + " \"" + testListPart + "\" latest " + save_path + '''
420 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y', save_path ) + '''
421 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
Devin Lim61643762017-12-07 15:55:38 -0800422 }
423 }
424 postResult( [], true )
425 }
426}
427def makeTestList( list, commaNeeded ){
Devin Limf5175192018-05-14 19:13:22 -0700428 // make the list of the test in to a string.
429 // list : list of the test
430 // commaNeeded : if comma is needed for the string
431
Devin Lim61643762017-12-07 15:55:38 -0800432 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
433}
434def createStatsList( testCategory, list, semiNeeded ){
Devin Limf5175192018-05-14 19:13:22 -0700435 // make the list for stats
436 // testCategory : category of the test
437 // list : list of the test
438 // semiNeeded: if semi colon is needed
439
Devin Lim61643762017-12-07 15:55:38 -0800440 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
441}
442def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700443 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800444
445 if( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
446 node( testMachine ){
447
448 withCredentials( [
449 string( credentialsId: 'db_pass', variable: 'pass' ),
450 string( credentialsId: 'db_user', variable: 'user' ),
451 string( credentialsId: 'db_host', variable: 'host' ),
452 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
453 testList = generalFuncs.getTestList( testCategory )
454 sh '''#!/bin/bash
455 ''' + generalFuncs.basicGraphPart( trend_generator_file, host, port, user, pass, testType, prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
456 }
457 }
458 postResult( prop, false )
459 }
460}
461def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Devin Limf5175192018-05-14 19:13:22 -0700462 // Rcommand for the pie graph
463
Devin Lim61643762017-12-07 15:55:38 -0800464 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) + " \"" + testList + "\" latest " + yOrN + " " + path
465}
466def sqlCommand( testName ){
Devin Limf5175192018-05-14 19:13:22 -0700467 // get the inserting sqlCommand for non-SCPF tests.
468
Devin Lim61643762017-12-07 15:55:38 -0800469 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" + testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
470}
471def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Devin Limf5175192018-05-14 19:13:22 -0700472 // get the graphGenerating R command for non-SCPF tests
473
Devin Lim61643762017-12-07 15:55:38 -0800474 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName, prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
475}
476def databasePart( wikiPrefix, testName, database_command ){
Devin Limf5175192018-05-14 19:13:22 -0700477 // to read and insert the data from .csv to the database
478
Devin Lim61643762017-12-07 15:55:38 -0800479 return '''
480 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
481 do
482 echo \$line
483 echo ''' + database_command + '''
484 done '''
485}
Devin Lim86e40532018-04-06 12:44:06 -0700486def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file, graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700487 // Will generate the stats graph.
488
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800489 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
490 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
491 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
492 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
493 makeTestList( AllTheTests[ "HA" ], true ) +
494 makeTestList( AllTheTests[ "USECASE" ], false )
Devin Lim86e40532018-04-06 12:44:06 -0700495 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 -0800496}
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700497def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700498 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700499 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
500}
Devin Lim1253ae82018-02-26 11:13:36 -0800501return this;