blob: 944fd2b64d5af85a278aefa335d09fab96292dff [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.
You Wang8f12d7d2018-11-09 13:47:23 -080086 // branch : branch of the onos. ( master, 1.15, 1.14... )
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.
You Wang8f12d7d2018-11-09 13:47:23 -0800101 // branch : master, 1.15, 1.14...
Jon Hall6af749d2018-05-29 12:59:47 -0700102 // 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"
You Wang8f12d7d2018-11-09 13:47:23 -0800105 case "1.15": return "2"
You Wang5cf67da2018-08-20 15:06:46 -0700106 case "1.14": return "3"
You Wang8f12d7d2018-11-09 13:47:23 -0800107 case "1.13": return "2"
Jon Hall6af749d2018-05-29 12:59:47 -0700108 case "1.12": return "3"
109 default: return "4"
110 }
111}
112
113def printType(){
114 // print the test type and test machine that was initialized.
115
116 echo testType
117 echo testMachine
118}
119
120def getProperties(){
121 // get the properties of the test by reading the TestONOS.property
122
123 node( testMachine ) {
124 return readProperties( file: '/var/jenkins/TestONOS.property' )
125 }
126}
127
128def getTestsToRun( testList ){
129 // get test to run by tokenizing the list.
130
131 testList.tokenize( "\n;, " )
132}
133
134def getCurrentTime(){
135 // get time of the PST zone.
136
137 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
138 return new Date()
139}
140
141def getTotalTime( start, end ){
142 // get total time of the test using start and end time.
143
144 return TimeCategory.minus( end, start )
145}
146
147def printTestToRun( testList ){
148 // printout the list of the test in the list.
149
150 for ( String test : testList ){
151 println test
152 }
153}
154
155def sendResultToSlack( start, isManualRun, branch ){
156 // send the result of the test to the slack when it is not manually running.
157 // start : start time of the test
158 // isManualRun : string that is whether "false" or "true"
159 // branch : branch of the onos.
160
161 try {
162 if ( isManualRun == "false" ){
163 end = getCurrentTime()
164 TimeDuration duration = TimeCategory.minus( end, start )
165 slackSend( color: "#5816EE",
166 message: testType + "-" + branch + " tests ended at: " + end.toString() +
167 "\nTime took : " + duration )
168 }
169 }
170 catch ( all ){
171 }
172}
173
174def initAndRunTest( testName, testCategory ){
175 // Bash script that will
176 // Initialize the environment to the machine and run the test.
177 // testName : name of the test
178 // testCategory : (SR,FUNC ... )
179
180 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800181 set -i # interactive
182 set +e
183 shopt -s expand_aliases # expand alias in non-interactive mode
184 export PYTHONUNBUFFERED=1
185 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800186 echo "ONOS Branch is: $ONOSBranch"
187 echo "TestON Branch is: $TestONBranch"
188 echo "Test date: "
189 date
190 cd ~
191 export PATH=$PATH:onos/tools/test/bin
192 timeout 240 stc shutdown | head -100
193 timeout 240 stc teardown | head -100
194 timeout 240 stc shutdown | head -100
195 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700196 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800197 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700198 ''' + "./cli.py run " +
Jon Hall2ee92f82018-06-07 13:07:33 -0700199 ( !hasArgs ? testName : testCategory[ testName ][ 'test' ] ) +
Jon Hall6af749d2018-05-29 12:59:47 -0700200 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800201 ./cleanup.sh -f
202 # cleanup config changes
203 cd ~/onos/tools/package/config
204 git clean -df'''
205}
Devin Limf5175192018-05-14 19:13:22 -0700206
Jon Hall8b1e92c2018-06-13 14:07:22 -0700207def copyLogs(){
208 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700209
210 result = ""
211 if ( testType == "SR" ){
212 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800213 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
214 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
215 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
216 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700217 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700218 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800219 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700220 }
221 return result
Devin Lim61643762017-12-07 15:55:38 -0800222}
Devin Limf5175192018-05-14 19:13:22 -0700223
Jon Hall6af749d2018-05-29 12:59:47 -0700224def cleanAndCopyFiles( testName ){
225 // clean up some files that were in the folder and copy the new files from the log
226 // testName : name of the test
227
228 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800229 set +e
230 echo "ONOS Branch is: ${ONOSBranch}"
231 echo "TestON Branch is: ${TestONBranch}"
232 echo "Job name is: "''' + testName + '''
233 echo "Workspace is: ${WORKSPACE}/"
234 echo "Wiki page to post is: ${WikiPrefix}-"
235 # remove any leftover files from previous tests
236 sudo rm ${WORKSPACE}/*Wiki.txt
237 sudo rm ${WORKSPACE}/*Summary.txt
238 sudo rm ${WORKSPACE}/*Result.txt
239 sudo rm ${WORKSPACE}/*.csv
240 #copy files to workspace
241 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700242 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800243 sudo cp *.txt ${WORKSPACE}/
244 sudo cp *.csv ${WORKSPACE}/
245 cd ${WORKSPACE}/
246 for i in *.csv
247 do mv "$i" "$WikiPrefix"-"$i"
248 done
249 ls -al
250 cd '''
251}
Devin Limf5175192018-05-14 19:13:22 -0700252
Jon Hall6af749d2018-05-29 12:59:47 -0700253def fetchLogs( testName ){
254 // fetch the logs of onos from onos nodes to onos System Test logs
255 // testName: name of the test
256
257 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800258 set +e
259 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700260 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800261 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
262 echo "########################################################################################"
263 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
264 echo "########################################################################################"
265 cd $TestONlogDir
266 if [ $? -eq 1 ]
267 then
268 echo "Job name does not match any test suite name to move log!"
269 else
270 pwd
Jon Hall3e6edb32018-08-21 16:20:30 -0700271 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
272 for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done
Devin Lim61643762017-12-07 15:55:38 -0800273 fi
274 cd'''
275}
Jon Hall6af749d2018-05-29 12:59:47 -0700276
Devin Lim61643762017-12-07 15:55:38 -0800277def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700278 // check if it is posting the result.
279 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700280
Jon Hall6af749d2018-05-29 12:59:47 -0700281 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800282}
Jon Hall6af749d2018-05-29 12:59:47 -0700283
Devin Lim61643762017-12-07 15:55:38 -0800284def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700285 // post the result by triggering postjob.
286 // prop : property dictionary that was read from the machine.
287 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700288
Jon Hall6af749d2018-05-29 12:59:47 -0700289 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
290 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800291 }
Devin Lim61643762017-12-07 15:55:38 -0800292}
Jon Hall6af749d2018-05-29 12:59:47 -0700293
294def postLogs( testName, prefix ){
295 // posting logs of the onos jobs specifically SR tests
296 // testName : name of the test
You Wang8f12d7d2018-11-09 13:47:23 -0800297 // prefix : branch prefix ( master, 1.15, 1.14 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700298
299 resultURL = ""
300 if ( testType == "SR" ){
301 def post = build job: "SR-log-" + prefix, propagate: false
302 resultURL = post.getAbsoluteUrl()
303 }
304 return resultURL
305}
306
307def getSlackChannel(){
308 // get name of the slack channel.
309 // if the test is SR, it will return sr-failures
310
311 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
312}
313
Jon Hall8b1e92c2018-06-13 14:07:22 -0700314def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
Jon Hall6af749d2018-05-29 12:59:47 -0700315 // analyzing the result of the test and send to slack if the test was failed.
316 // prop : property dictionary
317 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700318 // pureTestName : TestON name of the test
319 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700320 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
321 // wikiLink : link of the wiki page where the result was posted
322 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
323
324 node( testMachine ) {
Jon Hall8b1e92c2018-06-13 14:07:22 -0700325 def resultContents = readFile( workSpace + "/" + pureTestName + "Result.txt" )
Jon Hall6af749d2018-05-29 12:59:47 -0700326 resultContents = resultContents.split( "\n" )
327 if ( resultContents[ 0 ] == "1" ){
328 print "All passed"
329 }
330 else {
331 print "Failed"
332 if ( prop[ "manualRun" ] == "false" ){
333 slackSend( channel: getSlackChannel(),
334 color: "FF0000",
Jon Hall8b1e92c2018-06-13 14:07:22 -0700335 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : Failed!\n" +
Jon Hall6af749d2018-05-29 12:59:47 -0700336 resultContents[ 1 ] + "\n" +
337 "[TestON log] : \n" +
338 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
339 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
340 "https://wiki.onosproject.org/display/ONOS/" +
341 wikiLink.replaceAll( "\\s", "+" ) ) ) +
342 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
343 resultURL + "artifact/" ) : "" ),
344 teamDomain: 'onosproject' )
345 }
346 Failed
347 }
348 }
349}
350
Devin Lime89761a2018-03-16 17:52:57 -0700351def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700352 // publish HTML script to wiki confluence
353 // isManualRun : string "true" "false"
354 // isPostResult : string "true" "false"
355 // wikiLink : link of the wiki page to publish
356 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700357
Jon Hall6af749d2018-05-29 12:59:47 -0700358 if ( isPostingResult( isManualRun, isPostResult ) ){
359 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
360 attachArchivedArtifacts: true, buildIfUnstable: true,
361 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
362 }
Devin Lim61643762017-12-07 15:55:38 -0800363
364}
Devin Limf5175192018-05-14 19:13:22 -0700365
Jon Hall6af749d2018-05-29 12:59:47 -0700366def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
367 graph_saved_directory ){
368 // 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 -0700369 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700370 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
371 // result on pipeline view
372 // prop : dictionary property on the machine
373 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
374 // 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 -0700375 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700376 // graph_generator_file : Rscript file with the full path.
377 // graph_saved_directory : where the generated graph will be saved to.
378
379 return {
380 catchError {
381 stage( testName ) {
382 if ( toBeRun ){
383 def workSpace = "/var/jenkins/workspace/" + testName
384 def fileContents = ""
385 node( testMachine ) {
386 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
387 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
388 'TestONBranch=' + prop[ "TestONBranch" ],
389 'ONOSTag=' + prop[ "ONOSTag" ],
390 'WikiPrefix=' + prop[ "WikiPrefix" ],
391 'WORKSPACE=' + workSpace ] ) {
392 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700393 if ( isSCPF ){
394 // Remove the old database file
395 sh SCPFfunc.cleanupDatabaseFile( testName )
396 }
Jon Hall6af749d2018-05-29 12:59:47 -0700397 sh initAndRunTest( testName, testCategory )
398 // For the Wiki page
399 sh cleanAndCopyFiles( pureTestName )
400 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700401 databaseAndGraph( prop, testName, pureTestName, graphOnly,
402 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700403 if ( !graphOnly ){
404 sh fetchLogs( pureTestName )
405 if ( !isSCPF ){
406 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
407 testCategory[ testName ][ 'wiki_link' ],
408 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
409 }
410 }
Devin Lim61643762017-12-07 15:55:38 -0800411 }
Jon Hall6af749d2018-05-29 12:59:47 -0700412 }
Devin Lim61643762017-12-07 15:55:38 -0800413 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700414 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700415 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700416 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
417 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
418 isSCPF )
419 }
420 }
421 }
422 }
423 }
Devin Lim61643762017-12-07 15:55:38 -0800424}
Devin Limf5175192018-05-14 19:13:22 -0700425
Jon Hall8b1e92c2018-06-13 14:07:22 -0700426def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700427 // part where it insert the data into the database.
428 // It will use the predefined encrypted variables from the Jenkins.
429 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700430 // testName : Jenkins name for the test
431 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700432 // graphOnly : boolean whether it is graph only or not
433 // graph_generator_file : Rscript file with the full path.
434 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700435 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
436 // Post Results
437 withCredentials( [
438 string( credentialsId: 'db_pass', variable: 'pass' ),
439 string( credentialsId: 'db_user', variable: 'user' ),
440 string( credentialsId: 'db_host', variable: 'host' ),
441 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
442 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
443 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
444 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800445 export DATE=\$(date +%F_%T)
446 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700447 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700448 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700449 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
450 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
451 graph_generator_file ) :
452 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800453 }
Devin Lim61643762017-12-07 15:55:38 -0800454 }
455}
Jon Hall6af749d2018-05-29 12:59:47 -0700456
457def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
458 save_path, pieTestListPart ){
459 // function that will generate the category stat graphs for the overall test.
460 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
461 // manualRun : string of "true" or "false"
462 // postresult : string of "true" or "false"
463 // stat_file : file name with full path for Rscript for the stat graph
464 // pie_file : file name with full path for Rscript for the pie graph
465 // type : type of the test ( USECASE, FUNC, HA )
You Wang8f12d7d2018-11-09 13:47:23 -0800466 // branch : branch of the test ( master, onos-1.15, onos-1.14 )
Jon Hall6af749d2018-05-29 12:59:47 -0700467 // testListPart : list of the test to be included
468 // save_path : path that will save the graphs to
469 // pieTestListPart : list of the test for pie graph
470
471 if ( isPostingResult( manualRun, postresult ) ){
472 node( testMachineOn ) {
473
474 withCredentials( [
475 string( credentialsId: 'db_pass', variable: 'pass' ),
476 string( credentialsId: 'db_user', variable: 'user' ),
477 string( credentialsId: 'db_host', variable: 'host' ),
478 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
479 sh '''#!/bin/bash
480 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
481 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
482 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
483 save_path ) + '''
484 ''' +
485 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
486 }
487 }
488 postResult( [ ], true )
489 }
490}
491
Devin Lim61643762017-12-07 15:55:38 -0800492def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700493 // make the list of the test in to a string.
494 // list : list of the test
495 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700496
Jon Hall6af749d2018-05-29 12:59:47 -0700497 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800498}
Jon Hall6af749d2018-05-29 12:59:47 -0700499
Devin Lim61643762017-12-07 15:55:38 -0800500def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700501 // make the list for stats
502 // testCategory : category of the test
503 // list : list of the test
504 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700505
Jon Hall6af749d2018-05-29 12:59:47 -0700506 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800507}
Jon Hall6af749d2018-05-29 12:59:47 -0700508
Devin Lim61643762017-12-07 15:55:38 -0800509def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700510 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800511
Jon Hall6af749d2018-05-29 12:59:47 -0700512 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
513 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800514
Jon Hall6af749d2018-05-29 12:59:47 -0700515 withCredentials( [
516 string( credentialsId: 'db_pass', variable: 'pass' ),
517 string( credentialsId: 'db_user', variable: 'user' ),
518 string( credentialsId: 'db_host', variable: 'host' ),
519 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
520 testList = generalFuncs.getTestList( testCategory )
521 sh '''#!/bin/bash
522 ''' +
523 generalFuncs.basicGraphPart( trend_generator_file, host, port,
524 user, pass, testType,
525 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
526 }
Devin Lim61643762017-12-07 15:55:38 -0800527 }
Jon Hall6af749d2018-05-29 12:59:47 -0700528 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800529 }
530}
Jon Hall6af749d2018-05-29 12:59:47 -0700531
Devin Lim61643762017-12-07 15:55:38 -0800532def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700533 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700534
Jon Hall6af749d2018-05-29 12:59:47 -0700535 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
536 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800537}
Jon Hall6af749d2018-05-29 12:59:47 -0700538
Devin Lim61643762017-12-07 15:55:38 -0800539def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700540 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700541
Jon Hall6af749d2018-05-29 12:59:47 -0700542 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
543 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800544}
Jon Hall6af749d2018-05-29 12:59:47 -0700545
Devin Lim61643762017-12-07 15:55:38 -0800546def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700547 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700548
Jon Hall6af749d2018-05-29 12:59:47 -0700549 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
550 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800551}
Devin Limf5175192018-05-14 19:13:22 -0700552
Jon Hall6af749d2018-05-29 12:59:47 -0700553def databasePart( wikiPrefix, testName, database_command ){
554 // to read and insert the data from .csv to the database
555
556 return '''
Devin Lim61643762017-12-07 15:55:38 -0800557 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
558 do
559 echo \$line
560 echo ''' + database_command + '''
561 done '''
562}
Jon Hall6af749d2018-05-29 12:59:47 -0700563
564def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
565 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700566 // Will generate the stats graph.
567
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800568 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
569 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
570 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
571 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
572 makeTestList( AllTheTests[ "HA" ], true ) +
573 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700574 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
575 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800576}
Jon Hall6af749d2018-05-29 12:59:47 -0700577
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700578def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700579 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700580 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
581}
Jon Hall6af749d2018-05-29 12:59:47 -0700582
You Wangfe3877b2018-08-02 11:48:35 -0700583def testBranchWithPrefix( branch ){
584 // get TestON branch with the prefix ( "onos-" )
You Wang8f12d7d2018-11-09 13:47:23 -0800585 if ( branch == "1.12" )
You Wangfe3877b2018-08-02 11:48:35 -0700586 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800587 else if ( branch == "1.13" )
You Wangfe3877b2018-08-02 11:48:35 -0700588 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800589 else if ( branch == "1.14" )
You Wangda4b1442018-11-29 12:31:22 -0800590 return "onos-1.15"
You Wang8f12d7d2018-11-09 13:47:23 -0800591 else if ( branch == "1.15" )
You Wangda4b1442018-11-29 12:31:22 -0800592 return "onos-1.15"
You Wangfe3877b2018-08-02 11:48:35 -0700593 else
594 return "master"
595}
596
Jon Hall6af749d2018-05-29 12:59:47 -0700597return this