blob: d309f448565c17fff0080bc16bc6955eb1a3dc49 [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 Wangdba6c9f2018-12-21 11:58:55 -080086 // branch : branch of the onos. ( master, 2.0, 1.15... )
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 Wangdba6c9f2018-12-21 11:58:55 -0800101 // branch : master, 2.0, 1.15...
Jon Hall6af749d2018-05-29 12:59:47 -0700102 // branch.reverse().take(4).reverse() will get last 4 characters of the string.
You Wangdba6c9f2018-12-21 11:58:55 -0800103 switch ( branch.reverse().take( 3 ).reverse() ){
104 case "ter": return "4"
105 case "2.0": return "3"
106 case ".15": return "2"
107 case ".14": return "3"
108 case ".13": return "2"
109 case ".12": return "3"
Jon Hall6af749d2018-05-29 12:59:47 -0700110 default: return "4"
111 }
112}
113
114def printType(){
115 // print the test type and test machine that was initialized.
116
117 echo testType
118 echo testMachine
119}
120
121def getProperties(){
122 // get the properties of the test by reading the TestONOS.property
123
124 node( testMachine ) {
125 return readProperties( file: '/var/jenkins/TestONOS.property' )
126 }
127}
128
129def getTestsToRun( testList ){
130 // get test to run by tokenizing the list.
131
132 testList.tokenize( "\n;, " )
133}
134
135def getCurrentTime(){
136 // get time of the PST zone.
137
138 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
139 return new Date()
140}
141
142def getTotalTime( start, end ){
143 // get total time of the test using start and end time.
144
145 return TimeCategory.minus( end, start )
146}
147
148def printTestToRun( testList ){
149 // printout the list of the test in the list.
150
151 for ( String test : testList ){
152 println test
153 }
154}
155
156def sendResultToSlack( start, isManualRun, branch ){
157 // send the result of the test to the slack when it is not manually running.
158 // start : start time of the test
159 // isManualRun : string that is whether "false" or "true"
160 // branch : branch of the onos.
161
162 try {
163 if ( isManualRun == "false" ){
164 end = getCurrentTime()
165 TimeDuration duration = TimeCategory.minus( end, start )
166 slackSend( color: "#5816EE",
167 message: testType + "-" + branch + " tests ended at: " + end.toString() +
168 "\nTime took : " + duration )
169 }
170 }
171 catch ( all ){
172 }
173}
174
175def initAndRunTest( testName, testCategory ){
176 // Bash script that will
177 // Initialize the environment to the machine and run the test.
178 // testName : name of the test
179 // testCategory : (SR,FUNC ... )
180
181 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800182 set -i # interactive
183 set +e
184 shopt -s expand_aliases # expand alias in non-interactive mode
185 export PYTHONUNBUFFERED=1
186 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800187 echo "ONOS Branch is: $ONOSBranch"
188 echo "TestON Branch is: $TestONBranch"
189 echo "Test date: "
190 date
191 cd ~
192 export PATH=$PATH:onos/tools/test/bin
193 timeout 240 stc shutdown | head -100
194 timeout 240 stc teardown | head -100
195 timeout 240 stc shutdown | head -100
196 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700197 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800198 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700199 ''' + "./cli.py run " +
Jon Hall2ee92f82018-06-07 13:07:33 -0700200 ( !hasArgs ? testName : testCategory[ testName ][ 'test' ] ) +
Jon Hall6af749d2018-05-29 12:59:47 -0700201 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800202 ./cleanup.sh -f
203 # cleanup config changes
204 cd ~/onos/tools/package/config
205 git clean -df'''
206}
Devin Limf5175192018-05-14 19:13:22 -0700207
Jon Hall8b1e92c2018-06-13 14:07:22 -0700208def copyLogs(){
209 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700210
211 result = ""
212 if ( testType == "SR" ){
213 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800214 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
215 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
216 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
217 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700218 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700219 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800220 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700221 }
222 return result
Devin Lim61643762017-12-07 15:55:38 -0800223}
Devin Limf5175192018-05-14 19:13:22 -0700224
Jon Hall6af749d2018-05-29 12:59:47 -0700225def cleanAndCopyFiles( testName ){
226 // clean up some files that were in the folder and copy the new files from the log
227 // testName : name of the test
228
229 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800230 set +e
231 echo "ONOS Branch is: ${ONOSBranch}"
232 echo "TestON Branch is: ${TestONBranch}"
233 echo "Job name is: "''' + testName + '''
234 echo "Workspace is: ${WORKSPACE}/"
235 echo "Wiki page to post is: ${WikiPrefix}-"
236 # remove any leftover files from previous tests
237 sudo rm ${WORKSPACE}/*Wiki.txt
238 sudo rm ${WORKSPACE}/*Summary.txt
239 sudo rm ${WORKSPACE}/*Result.txt
240 sudo rm ${WORKSPACE}/*.csv
241 #copy files to workspace
242 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700243 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800244 sudo cp *.txt ${WORKSPACE}/
245 sudo cp *.csv ${WORKSPACE}/
246 cd ${WORKSPACE}/
247 for i in *.csv
248 do mv "$i" "$WikiPrefix"-"$i"
249 done
250 ls -al
251 cd '''
252}
Devin Limf5175192018-05-14 19:13:22 -0700253
Jon Hall6af749d2018-05-29 12:59:47 -0700254def fetchLogs( testName ){
255 // fetch the logs of onos from onos nodes to onos System Test logs
256 // testName: name of the test
257
258 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800259 set +e
260 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700261 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800262 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
263 echo "########################################################################################"
264 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
265 echo "########################################################################################"
266 cd $TestONlogDir
267 if [ $? -eq 1 ]
268 then
269 echo "Job name does not match any test suite name to move log!"
270 else
271 pwd
Jon Hall3e6edb32018-08-21 16:20:30 -0700272 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
273 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 -0800274 fi
275 cd'''
276}
Jon Hall6af749d2018-05-29 12:59:47 -0700277
Devin Lim61643762017-12-07 15:55:38 -0800278def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700279 // check if it is posting the result.
280 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700281
Jon Hall6af749d2018-05-29 12:59:47 -0700282 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800283}
Jon Hall6af749d2018-05-29 12:59:47 -0700284
Devin Lim61643762017-12-07 15:55:38 -0800285def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700286 // post the result by triggering postjob.
287 // prop : property dictionary that was read from the machine.
288 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700289
Jon Hall6af749d2018-05-29 12:59:47 -0700290 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
291 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800292 }
Devin Lim61643762017-12-07 15:55:38 -0800293}
Jon Hall6af749d2018-05-29 12:59:47 -0700294
295def postLogs( testName, prefix ){
296 // posting logs of the onos jobs specifically SR tests
297 // testName : name of the test
You Wangdba6c9f2018-12-21 11:58:55 -0800298 // prefix : branch prefix ( master, 2.0, 1.15 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700299
300 resultURL = ""
301 if ( testType == "SR" ){
302 def post = build job: "SR-log-" + prefix, propagate: false
303 resultURL = post.getAbsoluteUrl()
304 }
305 return resultURL
306}
307
308def getSlackChannel(){
309 // get name of the slack channel.
310 // if the test is SR, it will return sr-failures
311
312 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
313}
314
Jon Hall8b1e92c2018-06-13 14:07:22 -0700315def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
Jon Hall6af749d2018-05-29 12:59:47 -0700316 // analyzing the result of the test and send to slack if the test was failed.
317 // prop : property dictionary
318 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700319 // pureTestName : TestON name of the test
320 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700321 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
322 // wikiLink : link of the wiki page where the result was posted
323 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
324
325 node( testMachine ) {
Jon Hall8b1e92c2018-06-13 14:07:22 -0700326 def resultContents = readFile( workSpace + "/" + pureTestName + "Result.txt" )
Jon Hall6af749d2018-05-29 12:59:47 -0700327 resultContents = resultContents.split( "\n" )
328 if ( resultContents[ 0 ] == "1" ){
329 print "All passed"
330 }
331 else {
332 print "Failed"
333 if ( prop[ "manualRun" ] == "false" ){
334 slackSend( channel: getSlackChannel(),
335 color: "FF0000",
Jon Hall8b1e92c2018-06-13 14:07:22 -0700336 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : Failed!\n" +
Jon Hall6af749d2018-05-29 12:59:47 -0700337 resultContents[ 1 ] + "\n" +
338 "[TestON log] : \n" +
339 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
340 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
341 "https://wiki.onosproject.org/display/ONOS/" +
342 wikiLink.replaceAll( "\\s", "+" ) ) ) +
343 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
344 resultURL + "artifact/" ) : "" ),
345 teamDomain: 'onosproject' )
346 }
347 Failed
348 }
349 }
350}
351
Devin Lime89761a2018-03-16 17:52:57 -0700352def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700353 // publish HTML script to wiki confluence
354 // isManualRun : string "true" "false"
355 // isPostResult : string "true" "false"
356 // wikiLink : link of the wiki page to publish
357 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700358
Jon Hall6af749d2018-05-29 12:59:47 -0700359 if ( isPostingResult( isManualRun, isPostResult ) ){
360 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
361 attachArchivedArtifacts: true, buildIfUnstable: true,
362 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
363 }
Devin Lim61643762017-12-07 15:55:38 -0800364
365}
Devin Limf5175192018-05-14 19:13:22 -0700366
Jon Hall6af749d2018-05-29 12:59:47 -0700367def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
368 graph_saved_directory ){
369 // 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 -0700370 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700371 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
372 // result on pipeline view
373 // prop : dictionary property on the machine
374 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
375 // 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 -0700376 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700377 // graph_generator_file : Rscript file with the full path.
378 // graph_saved_directory : where the generated graph will be saved to.
379
380 return {
381 catchError {
382 stage( testName ) {
383 if ( toBeRun ){
384 def workSpace = "/var/jenkins/workspace/" + testName
385 def fileContents = ""
386 node( testMachine ) {
387 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
You Wang8e4f4c02019-01-03 10:49:46 -0800388 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
Jon Hall6af749d2018-05-29 12:59:47 -0700389 'TestONBranch=' + prop[ "TestONBranch" ],
390 'ONOSTag=' + prop[ "ONOSTag" ],
391 'WikiPrefix=' + prop[ "WikiPrefix" ],
392 'WORKSPACE=' + workSpace ] ) {
393 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700394 if ( isSCPF ){
395 // Remove the old database file
396 sh SCPFfunc.cleanupDatabaseFile( testName )
397 }
Jon Hall6af749d2018-05-29 12:59:47 -0700398 sh initAndRunTest( testName, testCategory )
399 // For the Wiki page
400 sh cleanAndCopyFiles( pureTestName )
401 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700402 databaseAndGraph( prop, testName, pureTestName, graphOnly,
403 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700404 if ( !graphOnly ){
405 sh fetchLogs( pureTestName )
406 if ( !isSCPF ){
407 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
408 testCategory[ testName ][ 'wiki_link' ],
409 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
410 }
411 }
Devin Lim61643762017-12-07 15:55:38 -0800412 }
Jon Hall6af749d2018-05-29 12:59:47 -0700413 }
Devin Lim61643762017-12-07 15:55:38 -0800414 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700415 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700416 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700417 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
418 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
419 isSCPF )
420 }
421 }
422 }
423 }
424 }
Devin Lim61643762017-12-07 15:55:38 -0800425}
Devin Limf5175192018-05-14 19:13:22 -0700426
Jon Hall8b1e92c2018-06-13 14:07:22 -0700427def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700428 // part where it insert the data into the database.
429 // It will use the predefined encrypted variables from the Jenkins.
430 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700431 // testName : Jenkins name for the test
432 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700433 // graphOnly : boolean whether it is graph only or not
434 // graph_generator_file : Rscript file with the full path.
435 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700436 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
437 // Post Results
438 withCredentials( [
439 string( credentialsId: 'db_pass', variable: 'pass' ),
440 string( credentialsId: 'db_user', variable: 'user' ),
441 string( credentialsId: 'db_host', variable: 'host' ),
442 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
443 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
444 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
445 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800446 export DATE=\$(date +%F_%T)
447 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700448 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700449 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700450 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
451 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
452 graph_generator_file ) :
453 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800454 }
Devin Lim61643762017-12-07 15:55:38 -0800455 }
456}
Jon Hall6af749d2018-05-29 12:59:47 -0700457
458def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
459 save_path, pieTestListPart ){
460 // function that will generate the category stat graphs for the overall test.
461 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
462 // manualRun : string of "true" or "false"
463 // postresult : string of "true" or "false"
464 // stat_file : file name with full path for Rscript for the stat graph
465 // pie_file : file name with full path for Rscript for the pie graph
466 // type : type of the test ( USECASE, FUNC, HA )
You Wangdba6c9f2018-12-21 11:58:55 -0800467 // branch : branch of the test ( master, onos-2.0, onos-1.15 )
Jon Hall6af749d2018-05-29 12:59:47 -0700468 // testListPart : list of the test to be included
469 // save_path : path that will save the graphs to
470 // pieTestListPart : list of the test for pie graph
471
472 if ( isPostingResult( manualRun, postresult ) ){
473 node( testMachineOn ) {
474
475 withCredentials( [
476 string( credentialsId: 'db_pass', variable: 'pass' ),
477 string( credentialsId: 'db_user', variable: 'user' ),
478 string( credentialsId: 'db_host', variable: 'host' ),
479 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
480 sh '''#!/bin/bash
481 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
482 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
483 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
484 save_path ) + '''
485 ''' +
486 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
487 }
488 }
489 postResult( [ ], true )
490 }
491}
492
Devin Lim61643762017-12-07 15:55:38 -0800493def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700494 // make the list of the test in to a string.
495 // list : list of the test
496 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700497
Jon Hall6af749d2018-05-29 12:59:47 -0700498 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800499}
Jon Hall6af749d2018-05-29 12:59:47 -0700500
Devin Lim61643762017-12-07 15:55:38 -0800501def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700502 // make the list for stats
503 // testCategory : category of the test
504 // list : list of the test
505 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700506
Jon Hall6af749d2018-05-29 12:59:47 -0700507 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800508}
Jon Hall6af749d2018-05-29 12:59:47 -0700509
Devin Lim61643762017-12-07 15:55:38 -0800510def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700511 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800512
Jon Hall6af749d2018-05-29 12:59:47 -0700513 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
514 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800515
Jon Hall6af749d2018-05-29 12:59:47 -0700516 withCredentials( [
517 string( credentialsId: 'db_pass', variable: 'pass' ),
518 string( credentialsId: 'db_user', variable: 'user' ),
519 string( credentialsId: 'db_host', variable: 'host' ),
520 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
521 testList = generalFuncs.getTestList( testCategory )
522 sh '''#!/bin/bash
523 ''' +
524 generalFuncs.basicGraphPart( trend_generator_file, host, port,
525 user, pass, testType,
526 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
527 }
Devin Lim61643762017-12-07 15:55:38 -0800528 }
Jon Hall6af749d2018-05-29 12:59:47 -0700529 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800530 }
531}
Jon Hall6af749d2018-05-29 12:59:47 -0700532
Devin Lim61643762017-12-07 15:55:38 -0800533def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700534 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700535
Jon Hall6af749d2018-05-29 12:59:47 -0700536 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
537 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800538}
Jon Hall6af749d2018-05-29 12:59:47 -0700539
Devin Lim61643762017-12-07 15:55:38 -0800540def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700541 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700542
Jon Hall6af749d2018-05-29 12:59:47 -0700543 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
544 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800545}
Jon Hall6af749d2018-05-29 12:59:47 -0700546
Devin Lim61643762017-12-07 15:55:38 -0800547def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700548 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700549
Jon Hall6af749d2018-05-29 12:59:47 -0700550 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
551 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800552}
Devin Limf5175192018-05-14 19:13:22 -0700553
Jon Hall6af749d2018-05-29 12:59:47 -0700554def databasePart( wikiPrefix, testName, database_command ){
555 // to read and insert the data from .csv to the database
556
557 return '''
Devin Lim61643762017-12-07 15:55:38 -0800558 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
559 do
560 echo \$line
561 echo ''' + database_command + '''
562 done '''
563}
Jon Hall6af749d2018-05-29 12:59:47 -0700564
565def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
566 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700567 // Will generate the stats graph.
568
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800569 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
570 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
571 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
572 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
573 makeTestList( AllTheTests[ "HA" ], true ) +
574 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700575 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
576 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800577}
Jon Hall6af749d2018-05-29 12:59:47 -0700578
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700579def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700580 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700581 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
582}
Jon Hall6af749d2018-05-29 12:59:47 -0700583
You Wangfe3877b2018-08-02 11:48:35 -0700584def testBranchWithPrefix( branch ){
585 // get TestON branch with the prefix ( "onos-" )
You Wang8f12d7d2018-11-09 13:47:23 -0800586 if ( branch == "1.12" )
You Wangfe3877b2018-08-02 11:48:35 -0700587 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800588 else if ( branch == "1.13" )
You Wangfe3877b2018-08-02 11:48:35 -0700589 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800590 else if ( branch == "1.14" )
You Wangda4b1442018-11-29 12:31:22 -0800591 return "onos-1.15"
You Wang8f12d7d2018-11-09 13:47:23 -0800592 else if ( branch == "1.15" )
You Wangda4b1442018-11-29 12:31:22 -0800593 return "onos-1.15"
You Wangdba6c9f2018-12-21 11:58:55 -0800594 else if ( branch == "2.0" )
595 return "master"
You Wangfe3877b2018-08-02 11:48:35 -0700596 else
597 return "master"
598}
599
Jon Hall6af749d2018-05-29 12:59:47 -0700600return this