blob: affba09581fdf1fc2b9c7f40619f7fa1caec7c00 [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
Jon Hall2ee92f82018-06-07 13:07:33 -070041 hasArgs = false
Jon Hall6af749d2018-05-29 12:59:47 -070042 isTrend = true
Devin Lim61643762017-12-07 15:55:38 -080043}
Jon Hall6af749d2018-05-29 12:59:47 -070044
Devin Lim61643762017-12-07 15:55:38 -080045def initialize( type, SCPFfuncs ){
Jon Hall6af749d2018-05-29 12:59:47 -070046 // Initializing for SCPF tests
47 // type : type of the test ( SR,FUNC,SCPF... )
48 // Passing the SCPFfunction which will be PerformanceFuncs.groovy
Devin Limf5175192018-05-14 19:13:22 -070049
Jon Hall6af749d2018-05-29 12:59:47 -070050 init( type )
51 SCPFfunc = SCPFfuncs
52 isSCPF = true
Jon Hall2ee92f82018-06-07 13:07:33 -070053 hasArgs = true // Has TestON cli arguments to be added when running the test
Jon Hall6af749d2018-05-29 12:59:47 -070054 machine = machineType[ type ]
Devin Lim61643762017-12-07 15:55:38 -080055}
Jon Hall6af749d2018-05-29 12:59:47 -070056
Devin Lim61643762017-12-07 15:55:38 -080057def initialize( type ){
Jon Hall6af749d2018-05-29 12:59:47 -070058 // initializing for FUNC,HA,SR, and USECASE
59 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070060
Jon Hall6af749d2018-05-29 12:59:47 -070061 init( type )
62 SCPFfunc = null
63 table_name = "executed_test_tests"
64 result_name = "executed_test_results"
65 trend_generator_file = fileRelated.trendMultiple
66 build_stats_generator_file = fileRelated.histogramMultiple
67 isSCPF = false
Jon Hall2ee92f82018-06-07 13:07:33 -070068 hasArgs = false
Devin Lim61643762017-12-07 15:55:38 -080069}
Jon Hall6af749d2018-05-29 12:59:47 -070070
Devin Lim61643762017-12-07 15:55:38 -080071def init( type ){
Jon Hall6af749d2018-05-29 12:59:47 -070072 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070073
Jon Hall6af749d2018-05-29 12:59:47 -070074 machineType = [ "FUNC": "VM",
75 "HA": "VM",
76 "SR": "Fabric",
77 "SCPF": "BM",
78 "USECASE": "BM" ]
79 testType = type
80 testMachine = "TestStation-" + machineType[ type ] + "s"
81 isTrend = false
Devin Lim61643762017-12-07 15:55:38 -080082}
Jon Hall6af749d2018-05-29 12:59:47 -070083
Devin Lim86e40532018-04-06 12:44:06 -070084def additionalInitForSR( branch ){
Jon Hall6af749d2018-05-29 12:59:47 -070085 // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running.
86 // branch : branch of the onos. ( master, 1.12, 1.13... )
Devin Limf5175192018-05-14 19:13:22 -070087
Jon Hall6af749d2018-05-29 12:59:47 -070088 testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size() - 1, fabricOn( branch ) ) ).
89 toString()
90 if ( isTrend ){
91 machine += fabricOn( branch )
Devin Lim61643762017-12-07 15:55:38 -080092 }
Jon Hall6af749d2018-05-29 12:59:47 -070093 else {
94 machineType[ testType ] += fabricOn( branch )
95 }
96 print testMachine
Devin Lim61643762017-12-07 15:55:38 -080097}
Devin Limf5175192018-05-14 19:13:22 -070098
Jon Hall6af749d2018-05-29 12:59:47 -070099def fabricOn( branch ){
100 // gets the fabric machines with the branch of onos.
101 // branch : master, 1.12, 1.13...
102 // branch.reverse().take(4).reverse() will get last 4 characters of the string.
103 switch ( branch.reverse().take( 4 ).reverse() ){
104 case "ster": return "4"
105 case "1.13": return "2"
106 case "1.12": return "3"
107 default: return "4"
108 }
109}
110
111def printType(){
112 // print the test type and test machine that was initialized.
113
114 echo testType
115 echo testMachine
116}
117
118def getProperties(){
119 // get the properties of the test by reading the TestONOS.property
120
121 node( testMachine ) {
122 return readProperties( file: '/var/jenkins/TestONOS.property' )
123 }
124}
125
126def getTestsToRun( testList ){
127 // get test to run by tokenizing the list.
128
129 testList.tokenize( "\n;, " )
130}
131
132def getCurrentTime(){
133 // get time of the PST zone.
134
135 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
136 return new Date()
137}
138
139def getTotalTime( start, end ){
140 // get total time of the test using start and end time.
141
142 return TimeCategory.minus( end, start )
143}
144
145def printTestToRun( testList ){
146 // printout the list of the test in the list.
147
148 for ( String test : testList ){
149 println test
150 }
151}
152
153def sendResultToSlack( start, isManualRun, branch ){
154 // send the result of the test to the slack when it is not manually running.
155 // start : start time of the test
156 // isManualRun : string that is whether "false" or "true"
157 // branch : branch of the onos.
158
159 try {
160 if ( isManualRun == "false" ){
161 end = getCurrentTime()
162 TimeDuration duration = TimeCategory.minus( end, start )
163 slackSend( color: "#5816EE",
164 message: testType + "-" + branch + " tests ended at: " + end.toString() +
165 "\nTime took : " + duration )
166 }
167 }
168 catch ( all ){
169 }
170}
171
172def initAndRunTest( testName, testCategory ){
173 // Bash script that will
174 // Initialize the environment to the machine and run the test.
175 // testName : name of the test
176 // testCategory : (SR,FUNC ... )
177
178 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800179 set -i # interactive
180 set +e
181 shopt -s expand_aliases # expand alias in non-interactive mode
182 export PYTHONUNBUFFERED=1
183 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800184 echo "ONOS Branch is: $ONOSBranch"
185 echo "TestON Branch is: $TestONBranch"
186 echo "Test date: "
187 date
188 cd ~
189 export PATH=$PATH:onos/tools/test/bin
190 timeout 240 stc shutdown | head -100
191 timeout 240 stc teardown | head -100
192 timeout 240 stc shutdown | head -100
193 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700194 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800195 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700196 ''' + "./cli.py run " +
Jon Hall2ee92f82018-06-07 13:07:33 -0700197 ( !hasArgs ? testName : testCategory[ testName ][ 'test' ] ) +
Jon Hall6af749d2018-05-29 12:59:47 -0700198 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800199 ./cleanup.sh -f
200 # cleanup config changes
201 cd ~/onos/tools/package/config
202 git clean -df'''
203}
Devin Limf5175192018-05-14 19:13:22 -0700204
Jon Hall8b1e92c2018-06-13 14:07:22 -0700205def copyLogs(){
206 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700207
208 result = ""
209 if ( testType == "SR" ){
210 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800211 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
212 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
213 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
214 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700215 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700216 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800217 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700218 }
219 return result
Devin Lim61643762017-12-07 15:55:38 -0800220}
Devin Limf5175192018-05-14 19:13:22 -0700221
Jon Hall6af749d2018-05-29 12:59:47 -0700222def cleanAndCopyFiles( testName ){
223 // clean up some files that were in the folder and copy the new files from the log
224 // testName : name of the test
225
226 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800227 set +e
228 echo "ONOS Branch is: ${ONOSBranch}"
229 echo "TestON Branch is: ${TestONBranch}"
230 echo "Job name is: "''' + testName + '''
231 echo "Workspace is: ${WORKSPACE}/"
232 echo "Wiki page to post is: ${WikiPrefix}-"
233 # remove any leftover files from previous tests
234 sudo rm ${WORKSPACE}/*Wiki.txt
235 sudo rm ${WORKSPACE}/*Summary.txt
236 sudo rm ${WORKSPACE}/*Result.txt
237 sudo rm ${WORKSPACE}/*.csv
238 #copy files to workspace
239 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700240 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800241 sudo cp *.txt ${WORKSPACE}/
242 sudo cp *.csv ${WORKSPACE}/
243 cd ${WORKSPACE}/
244 for i in *.csv
245 do mv "$i" "$WikiPrefix"-"$i"
246 done
247 ls -al
248 cd '''
249}
Devin Limf5175192018-05-14 19:13:22 -0700250
Jon Hall6af749d2018-05-29 12:59:47 -0700251def fetchLogs( testName ){
252 // fetch the logs of onos from onos nodes to onos System Test logs
253 // testName: name of the test
254
255 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800256 set +e
257 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700258 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800259 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
260 echo "########################################################################################"
261 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
262 echo "########################################################################################"
263 cd $TestONlogDir
264 if [ $? -eq 1 ]
265 then
266 echo "Job name does not match any test suite name to move log!"
267 else
268 pwd
269 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
270 fi
271 cd'''
272}
Jon Hall6af749d2018-05-29 12:59:47 -0700273
Devin Lim61643762017-12-07 15:55:38 -0800274def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700275 // check if it is posting the result.
276 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700277
Jon Hall6af749d2018-05-29 12:59:47 -0700278 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800279}
Jon Hall6af749d2018-05-29 12:59:47 -0700280
Devin Lim61643762017-12-07 15:55:38 -0800281def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700282 // post the result by triggering postjob.
283 // prop : property dictionary that was read from the machine.
284 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700285
Jon Hall6af749d2018-05-29 12:59:47 -0700286 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
287 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800288 }
Devin Lim61643762017-12-07 15:55:38 -0800289}
Jon Hall6af749d2018-05-29 12:59:47 -0700290
291def postLogs( testName, prefix ){
292 // posting logs of the onos jobs specifically SR tests
293 // testName : name of the test
294 // prefix : branch prefix ( master, 1.12, 1.13 ... )
295
296 resultURL = ""
297 if ( testType == "SR" ){
298 def post = build job: "SR-log-" + prefix, propagate: false
299 resultURL = post.getAbsoluteUrl()
300 }
301 return resultURL
302}
303
304def getSlackChannel(){
305 // get name of the slack channel.
306 // if the test is SR, it will return sr-failures
307
308 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
309}
310
Jon Hall8b1e92c2018-06-13 14:07:22 -0700311def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
Jon Hall6af749d2018-05-29 12:59:47 -0700312 // analyzing the result of the test and send to slack if the test was failed.
313 // prop : property dictionary
314 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700315 // pureTestName : TestON name of the test
316 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700317 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
318 // wikiLink : link of the wiki page where the result was posted
319 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
320
321 node( testMachine ) {
Jon Hall8b1e92c2018-06-13 14:07:22 -0700322 def resultContents = readFile( workSpace + "/" + pureTestName + "Result.txt" )
Jon Hall6af749d2018-05-29 12:59:47 -0700323 resultContents = resultContents.split( "\n" )
324 if ( resultContents[ 0 ] == "1" ){
325 print "All passed"
326 }
327 else {
328 print "Failed"
329 if ( prop[ "manualRun" ] == "false" ){
330 slackSend( channel: getSlackChannel(),
331 color: "FF0000",
Jon Hall8b1e92c2018-06-13 14:07:22 -0700332 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : Failed!\n" +
Jon Hall6af749d2018-05-29 12:59:47 -0700333 resultContents[ 1 ] + "\n" +
334 "[TestON log] : \n" +
335 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
336 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
337 "https://wiki.onosproject.org/display/ONOS/" +
338 wikiLink.replaceAll( "\\s", "+" ) ) ) +
339 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
340 resultURL + "artifact/" ) : "" ),
341 teamDomain: 'onosproject' )
342 }
343 Failed
344 }
345 }
346}
347
Devin Lime89761a2018-03-16 17:52:57 -0700348def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700349 // publish HTML script to wiki confluence
350 // isManualRun : string "true" "false"
351 // isPostResult : string "true" "false"
352 // wikiLink : link of the wiki page to publish
353 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700354
Jon Hall6af749d2018-05-29 12:59:47 -0700355 if ( isPostingResult( isManualRun, isPostResult ) ){
356 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
357 attachArchivedArtifacts: true, buildIfUnstable: true,
358 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
359 }
Devin Lim61643762017-12-07 15:55:38 -0800360
361}
Devin Limf5175192018-05-14 19:13:22 -0700362
Jon Hall6af749d2018-05-29 12:59:47 -0700363def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
364 graph_saved_directory ){
365 // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
Jon Hall8b1e92c2018-06-13 14:07:22 -0700366 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700367 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
368 // result on pipeline view
369 // prop : dictionary property on the machine
370 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
371 // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
Jon Hall2ee92f82018-06-07 13:07:33 -0700372 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700373 // graph_generator_file : Rscript file with the full path.
374 // graph_saved_directory : where the generated graph will be saved to.
375
376 return {
377 catchError {
378 stage( testName ) {
379 if ( toBeRun ){
380 def workSpace = "/var/jenkins/workspace/" + testName
381 def fileContents = ""
382 node( testMachine ) {
383 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
384 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
385 'TestONBranch=' + prop[ "TestONBranch" ],
386 'ONOSTag=' + prop[ "ONOSTag" ],
387 'WikiPrefix=' + prop[ "WikiPrefix" ],
388 'WORKSPACE=' + workSpace ] ) {
389 if ( !graphOnly ){
390 sh initAndRunTest( testName, testCategory )
391 // For the Wiki page
392 sh cleanAndCopyFiles( pureTestName )
393 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700394 databaseAndGraph( prop, testName, pureTestName, graphOnly,
395 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700396 if ( !graphOnly ){
397 sh fetchLogs( pureTestName )
398 if ( !isSCPF ){
399 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
400 testCategory[ testName ][ 'wiki_link' ],
401 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
402 }
403 }
Devin Lim61643762017-12-07 15:55:38 -0800404 }
Jon Hall6af749d2018-05-29 12:59:47 -0700405 }
Devin Lim61643762017-12-07 15:55:38 -0800406 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700407 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700408 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700409 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
410 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
411 isSCPF )
412 }
413 }
414 }
415 }
416 }
Devin Lim61643762017-12-07 15:55:38 -0800417}
Devin Limf5175192018-05-14 19:13:22 -0700418
Jon Hall8b1e92c2018-06-13 14:07:22 -0700419def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700420 // part where it insert the data into the database.
421 // It will use the predefined encrypted variables from the Jenkins.
422 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700423 // testName : Jenkins name for the test
424 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700425 // graphOnly : boolean whether it is graph only or not
426 // graph_generator_file : Rscript file with the full path.
427 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700428 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
429 // Post Results
430 withCredentials( [
431 string( credentialsId: 'db_pass', variable: 'pass' ),
432 string( credentialsId: 'db_user', variable: 'user' ),
433 string( credentialsId: 'db_host', variable: 'host' ),
434 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
435 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
436 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
437 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800438 export DATE=\$(date +%F_%T)
439 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700440 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700441 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700442 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
443 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
444 graph_generator_file ) :
445 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800446 }
Devin Lim61643762017-12-07 15:55:38 -0800447 }
448}
Jon Hall6af749d2018-05-29 12:59:47 -0700449
450def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
451 save_path, pieTestListPart ){
452 // function that will generate the category stat graphs for the overall test.
453 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
454 // manualRun : string of "true" or "false"
455 // postresult : string of "true" or "false"
456 // stat_file : file name with full path for Rscript for the stat graph
457 // pie_file : file name with full path for Rscript for the pie graph
458 // type : type of the test ( USECASE, FUNC, HA )
459 // branch : branch of the test ( master, onos-1.12, onos-1.13 )
460 // testListPart : list of the test to be included
461 // save_path : path that will save the graphs to
462 // pieTestListPart : list of the test for pie graph
463
464 if ( isPostingResult( manualRun, postresult ) ){
465 node( testMachineOn ) {
466
467 withCredentials( [
468 string( credentialsId: 'db_pass', variable: 'pass' ),
469 string( credentialsId: 'db_user', variable: 'user' ),
470 string( credentialsId: 'db_host', variable: 'host' ),
471 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
472 sh '''#!/bin/bash
473 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
474 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
475 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
476 save_path ) + '''
477 ''' +
478 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
479 }
480 }
481 postResult( [ ], true )
482 }
483}
484
Devin Lim61643762017-12-07 15:55:38 -0800485def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700486 // make the list of the test in to a string.
487 // list : list of the test
488 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700489
Jon Hall6af749d2018-05-29 12:59:47 -0700490 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800491}
Jon Hall6af749d2018-05-29 12:59:47 -0700492
Devin Lim61643762017-12-07 15:55:38 -0800493def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700494 // make the list for stats
495 // testCategory : category of the test
496 // list : list of the test
497 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700498
Jon Hall6af749d2018-05-29 12:59:47 -0700499 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800500}
Jon Hall6af749d2018-05-29 12:59:47 -0700501
Devin Lim61643762017-12-07 15:55:38 -0800502def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700503 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800504
Jon Hall6af749d2018-05-29 12:59:47 -0700505 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
506 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800507
Jon Hall6af749d2018-05-29 12:59:47 -0700508 withCredentials( [
509 string( credentialsId: 'db_pass', variable: 'pass' ),
510 string( credentialsId: 'db_user', variable: 'user' ),
511 string( credentialsId: 'db_host', variable: 'host' ),
512 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
513 testList = generalFuncs.getTestList( testCategory )
514 sh '''#!/bin/bash
515 ''' +
516 generalFuncs.basicGraphPart( trend_generator_file, host, port,
517 user, pass, testType,
518 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
519 }
Devin Lim61643762017-12-07 15:55:38 -0800520 }
Jon Hall6af749d2018-05-29 12:59:47 -0700521 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800522 }
523}
Jon Hall6af749d2018-05-29 12:59:47 -0700524
Devin Lim61643762017-12-07 15:55:38 -0800525def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700526 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700527
Jon Hall6af749d2018-05-29 12:59:47 -0700528 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
529 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800530}
Jon Hall6af749d2018-05-29 12:59:47 -0700531
Devin Lim61643762017-12-07 15:55:38 -0800532def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700533 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700534
Jon Hall6af749d2018-05-29 12:59:47 -0700535 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
536 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800537}
Jon Hall6af749d2018-05-29 12:59:47 -0700538
Devin Lim61643762017-12-07 15:55:38 -0800539def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700540 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700541
Jon Hall6af749d2018-05-29 12:59:47 -0700542 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
543 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800544}
Devin Limf5175192018-05-14 19:13:22 -0700545
Jon Hall6af749d2018-05-29 12:59:47 -0700546def databasePart( wikiPrefix, testName, database_command ){
547 // to read and insert the data from .csv to the database
548
549 return '''
Devin Lim61643762017-12-07 15:55:38 -0800550 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
551 do
552 echo \$line
553 echo ''' + database_command + '''
554 done '''
555}
Jon Hall6af749d2018-05-29 12:59:47 -0700556
557def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
558 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700559 // Will generate the stats graph.
560
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800561 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
562 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
563 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
564 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
565 makeTestList( AllTheTests[ "HA" ], true ) +
566 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700567 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
568 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800569}
Jon Hall6af749d2018-05-29 12:59:47 -0700570
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700571def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700572 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700573 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
574}
Jon Hall6af749d2018-05-29 12:59:47 -0700575
You Wangfe3877b2018-08-02 11:48:35 -0700576def testBranchWithPrefix( branch ){
577 // get TestON branch with the prefix ( "onos-" )
578 if ( branch == "1.13" )
579 return "onos-1.13"
580 else if ( branch == "1.12" )
581 return "onos-1.13"
582 else
583 return "master"
584}
585
Jon Hall6af749d2018-05-29 12:59:47 -0700586return this