blob: c2057782b68207a7eff55d459c852d84ea81ccb1 [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"
You Wang5cf67da2018-08-20 15:06:46 -0700106 case "1.14": return "3"
Jon Hall6af749d2018-05-29 12:59:47 -0700107 case "1.12": return "3"
108 default: return "4"
109 }
110}
111
112def printType(){
113 // print the test type and test machine that was initialized.
114
115 echo testType
116 echo testMachine
117}
118
119def getProperties(){
120 // get the properties of the test by reading the TestONOS.property
121
122 node( testMachine ) {
123 return readProperties( file: '/var/jenkins/TestONOS.property' )
124 }
125}
126
127def getTestsToRun( testList ){
128 // get test to run by tokenizing the list.
129
130 testList.tokenize( "\n;, " )
131}
132
133def getCurrentTime(){
134 // get time of the PST zone.
135
136 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
137 return new Date()
138}
139
140def getTotalTime( start, end ){
141 // get total time of the test using start and end time.
142
143 return TimeCategory.minus( end, start )
144}
145
146def printTestToRun( testList ){
147 // printout the list of the test in the list.
148
149 for ( String test : testList ){
150 println test
151 }
152}
153
154def sendResultToSlack( start, isManualRun, branch ){
155 // send the result of the test to the slack when it is not manually running.
156 // start : start time of the test
157 // isManualRun : string that is whether "false" or "true"
158 // branch : branch of the onos.
159
160 try {
161 if ( isManualRun == "false" ){
162 end = getCurrentTime()
163 TimeDuration duration = TimeCategory.minus( end, start )
164 slackSend( color: "#5816EE",
165 message: testType + "-" + branch + " tests ended at: " + end.toString() +
166 "\nTime took : " + duration )
167 }
168 }
169 catch ( all ){
170 }
171}
172
173def initAndRunTest( testName, testCategory ){
174 // Bash script that will
175 // Initialize the environment to the machine and run the test.
176 // testName : name of the test
177 // testCategory : (SR,FUNC ... )
178
179 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800180 set -i # interactive
181 set +e
182 shopt -s expand_aliases # expand alias in non-interactive mode
183 export PYTHONUNBUFFERED=1
184 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800185 echo "ONOS Branch is: $ONOSBranch"
186 echo "TestON Branch is: $TestONBranch"
187 echo "Test date: "
188 date
189 cd ~
190 export PATH=$PATH:onos/tools/test/bin
191 timeout 240 stc shutdown | head -100
192 timeout 240 stc teardown | head -100
193 timeout 240 stc shutdown | head -100
194 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700195 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800196 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700197 ''' + "./cli.py run " +
Jon Hall2ee92f82018-06-07 13:07:33 -0700198 ( !hasArgs ? testName : testCategory[ testName ][ 'test' ] ) +
Jon Hall6af749d2018-05-29 12:59:47 -0700199 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800200 ./cleanup.sh -f
201 # cleanup config changes
202 cd ~/onos/tools/package/config
203 git clean -df'''
204}
Devin Limf5175192018-05-14 19:13:22 -0700205
Jon Hall8b1e92c2018-06-13 14:07:22 -0700206def copyLogs(){
207 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700208
209 result = ""
210 if ( testType == "SR" ){
211 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800212 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
213 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
214 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
215 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700216 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700217 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800218 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700219 }
220 return result
Devin Lim61643762017-12-07 15:55:38 -0800221}
Devin Limf5175192018-05-14 19:13:22 -0700222
Jon Hall6af749d2018-05-29 12:59:47 -0700223def cleanAndCopyFiles( testName ){
224 // clean up some files that were in the folder and copy the new files from the log
225 // testName : name of the test
226
227 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800228 set +e
229 echo "ONOS Branch is: ${ONOSBranch}"
230 echo "TestON Branch is: ${TestONBranch}"
231 echo "Job name is: "''' + testName + '''
232 echo "Workspace is: ${WORKSPACE}/"
233 echo "Wiki page to post is: ${WikiPrefix}-"
234 # remove any leftover files from previous tests
235 sudo rm ${WORKSPACE}/*Wiki.txt
236 sudo rm ${WORKSPACE}/*Summary.txt
237 sudo rm ${WORKSPACE}/*Result.txt
238 sudo rm ${WORKSPACE}/*.csv
239 #copy files to workspace
240 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700241 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800242 sudo cp *.txt ${WORKSPACE}/
243 sudo cp *.csv ${WORKSPACE}/
244 cd ${WORKSPACE}/
245 for i in *.csv
246 do mv "$i" "$WikiPrefix"-"$i"
247 done
248 ls -al
249 cd '''
250}
Devin Limf5175192018-05-14 19:13:22 -0700251
Jon Hall6af749d2018-05-29 12:59:47 -0700252def fetchLogs( testName ){
253 // fetch the logs of onos from onos nodes to onos System Test logs
254 // testName: name of the test
255
256 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800257 set +e
258 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700259 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800260 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
261 echo "########################################################################################"
262 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
263 echo "########################################################################################"
264 cd $TestONlogDir
265 if [ $? -eq 1 ]
266 then
267 echo "Job name does not match any test suite name to move log!"
268 else
269 pwd
Jon Hall3e6edb32018-08-21 16:20:30 -0700270 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
271 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 -0800272 fi
273 cd'''
274}
Jon Hall6af749d2018-05-29 12:59:47 -0700275
Devin Lim61643762017-12-07 15:55:38 -0800276def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700277 // check if it is posting the result.
278 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700279
Jon Hall6af749d2018-05-29 12:59:47 -0700280 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800281}
Jon Hall6af749d2018-05-29 12:59:47 -0700282
Devin Lim61643762017-12-07 15:55:38 -0800283def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700284 // post the result by triggering postjob.
285 // prop : property dictionary that was read from the machine.
286 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700287
Jon Hall6af749d2018-05-29 12:59:47 -0700288 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
289 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800290 }
Devin Lim61643762017-12-07 15:55:38 -0800291}
Jon Hall6af749d2018-05-29 12:59:47 -0700292
293def postLogs( testName, prefix ){
294 // posting logs of the onos jobs specifically SR tests
295 // testName : name of the test
296 // prefix : branch prefix ( master, 1.12, 1.13 ... )
297
298 resultURL = ""
299 if ( testType == "SR" ){
300 def post = build job: "SR-log-" + prefix, propagate: false
301 resultURL = post.getAbsoluteUrl()
302 }
303 return resultURL
304}
305
306def getSlackChannel(){
307 // get name of the slack channel.
308 // if the test is SR, it will return sr-failures
309
310 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
311}
312
Jon Hall8b1e92c2018-06-13 14:07:22 -0700313def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
Jon Hall6af749d2018-05-29 12:59:47 -0700314 // analyzing the result of the test and send to slack if the test was failed.
315 // prop : property dictionary
316 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700317 // pureTestName : TestON name of the test
318 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700319 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
320 // wikiLink : link of the wiki page where the result was posted
321 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
322
323 node( testMachine ) {
Jon Hall8b1e92c2018-06-13 14:07:22 -0700324 def resultContents = readFile( workSpace + "/" + pureTestName + "Result.txt" )
Jon Hall6af749d2018-05-29 12:59:47 -0700325 resultContents = resultContents.split( "\n" )
326 if ( resultContents[ 0 ] == "1" ){
327 print "All passed"
328 }
329 else {
330 print "Failed"
331 if ( prop[ "manualRun" ] == "false" ){
332 slackSend( channel: getSlackChannel(),
333 color: "FF0000",
Jon Hall8b1e92c2018-06-13 14:07:22 -0700334 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : Failed!\n" +
Jon Hall6af749d2018-05-29 12:59:47 -0700335 resultContents[ 1 ] + "\n" +
336 "[TestON log] : \n" +
337 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
338 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
339 "https://wiki.onosproject.org/display/ONOS/" +
340 wikiLink.replaceAll( "\\s", "+" ) ) ) +
341 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
342 resultURL + "artifact/" ) : "" ),
343 teamDomain: 'onosproject' )
344 }
345 Failed
346 }
347 }
348}
349
Devin Lime89761a2018-03-16 17:52:57 -0700350def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700351 // publish HTML script to wiki confluence
352 // isManualRun : string "true" "false"
353 // isPostResult : string "true" "false"
354 // wikiLink : link of the wiki page to publish
355 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700356
Jon Hall6af749d2018-05-29 12:59:47 -0700357 if ( isPostingResult( isManualRun, isPostResult ) ){
358 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
359 attachArchivedArtifacts: true, buildIfUnstable: true,
360 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
361 }
Devin Lim61643762017-12-07 15:55:38 -0800362
363}
Devin Limf5175192018-05-14 19:13:22 -0700364
Jon Hall6af749d2018-05-29 12:59:47 -0700365def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
366 graph_saved_directory ){
367 // 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 -0700368 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700369 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
370 // result on pipeline view
371 // prop : dictionary property on the machine
372 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
373 // 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 -0700374 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700375 // graph_generator_file : Rscript file with the full path.
376 // graph_saved_directory : where the generated graph will be saved to.
377
378 return {
379 catchError {
380 stage( testName ) {
381 if ( toBeRun ){
382 def workSpace = "/var/jenkins/workspace/" + testName
383 def fileContents = ""
384 node( testMachine ) {
385 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
386 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
387 'TestONBranch=' + prop[ "TestONBranch" ],
388 'ONOSTag=' + prop[ "ONOSTag" ],
389 'WikiPrefix=' + prop[ "WikiPrefix" ],
390 'WORKSPACE=' + workSpace ] ) {
391 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700392 if ( isSCPF ){
393 // Remove the old database file
394 sh SCPFfunc.cleanupDatabaseFile( testName )
395 }
Jon Hall6af749d2018-05-29 12:59:47 -0700396 sh initAndRunTest( testName, testCategory )
397 // For the Wiki page
398 sh cleanAndCopyFiles( pureTestName )
399 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700400 databaseAndGraph( prop, testName, pureTestName, graphOnly,
401 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700402 if ( !graphOnly ){
403 sh fetchLogs( pureTestName )
404 if ( !isSCPF ){
405 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
406 testCategory[ testName ][ 'wiki_link' ],
407 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
408 }
409 }
Devin Lim61643762017-12-07 15:55:38 -0800410 }
Jon Hall6af749d2018-05-29 12:59:47 -0700411 }
Devin Lim61643762017-12-07 15:55:38 -0800412 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700413 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700414 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700415 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
416 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
417 isSCPF )
418 }
419 }
420 }
421 }
422 }
Devin Lim61643762017-12-07 15:55:38 -0800423}
Devin Limf5175192018-05-14 19:13:22 -0700424
Jon Hall8b1e92c2018-06-13 14:07:22 -0700425def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700426 // part where it insert the data into the database.
427 // It will use the predefined encrypted variables from the Jenkins.
428 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700429 // testName : Jenkins name for the test
430 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700431 // graphOnly : boolean whether it is graph only or not
432 // graph_generator_file : Rscript file with the full path.
433 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700434 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
435 // Post Results
436 withCredentials( [
437 string( credentialsId: 'db_pass', variable: 'pass' ),
438 string( credentialsId: 'db_user', variable: 'user' ),
439 string( credentialsId: 'db_host', variable: 'host' ),
440 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
441 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
442 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
443 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800444 export DATE=\$(date +%F_%T)
445 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700446 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700447 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700448 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
449 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
450 graph_generator_file ) :
451 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800452 }
Devin Lim61643762017-12-07 15:55:38 -0800453 }
454}
Jon Hall6af749d2018-05-29 12:59:47 -0700455
456def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
457 save_path, pieTestListPart ){
458 // function that will generate the category stat graphs for the overall test.
459 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
460 // manualRun : string of "true" or "false"
461 // postresult : string of "true" or "false"
462 // stat_file : file name with full path for Rscript for the stat graph
463 // pie_file : file name with full path for Rscript for the pie graph
464 // type : type of the test ( USECASE, FUNC, HA )
465 // branch : branch of the test ( master, onos-1.12, onos-1.13 )
466 // testListPart : list of the test to be included
467 // save_path : path that will save the graphs to
468 // pieTestListPart : list of the test for pie graph
469
470 if ( isPostingResult( manualRun, postresult ) ){
471 node( testMachineOn ) {
472
473 withCredentials( [
474 string( credentialsId: 'db_pass', variable: 'pass' ),
475 string( credentialsId: 'db_user', variable: 'user' ),
476 string( credentialsId: 'db_host', variable: 'host' ),
477 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
478 sh '''#!/bin/bash
479 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
480 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
481 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
482 save_path ) + '''
483 ''' +
484 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
485 }
486 }
487 postResult( [ ], true )
488 }
489}
490
Devin Lim61643762017-12-07 15:55:38 -0800491def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700492 // make the list of the test in to a string.
493 // list : list of the test
494 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700495
Jon Hall6af749d2018-05-29 12:59:47 -0700496 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800497}
Jon Hall6af749d2018-05-29 12:59:47 -0700498
Devin Lim61643762017-12-07 15:55:38 -0800499def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700500 // make the list for stats
501 // testCategory : category of the test
502 // list : list of the test
503 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700504
Jon Hall6af749d2018-05-29 12:59:47 -0700505 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800506}
Jon Hall6af749d2018-05-29 12:59:47 -0700507
Devin Lim61643762017-12-07 15:55:38 -0800508def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700509 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800510
Jon Hall6af749d2018-05-29 12:59:47 -0700511 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
512 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800513
Jon Hall6af749d2018-05-29 12:59:47 -0700514 withCredentials( [
515 string( credentialsId: 'db_pass', variable: 'pass' ),
516 string( credentialsId: 'db_user', variable: 'user' ),
517 string( credentialsId: 'db_host', variable: 'host' ),
518 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
519 testList = generalFuncs.getTestList( testCategory )
520 sh '''#!/bin/bash
521 ''' +
522 generalFuncs.basicGraphPart( trend_generator_file, host, port,
523 user, pass, testType,
524 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
525 }
Devin Lim61643762017-12-07 15:55:38 -0800526 }
Jon Hall6af749d2018-05-29 12:59:47 -0700527 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800528 }
529}
Jon Hall6af749d2018-05-29 12:59:47 -0700530
Devin Lim61643762017-12-07 15:55:38 -0800531def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700532 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700533
Jon Hall6af749d2018-05-29 12:59:47 -0700534 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
535 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800536}
Jon Hall6af749d2018-05-29 12:59:47 -0700537
Devin Lim61643762017-12-07 15:55:38 -0800538def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700539 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700540
Jon Hall6af749d2018-05-29 12:59:47 -0700541 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
542 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800543}
Jon Hall6af749d2018-05-29 12:59:47 -0700544
Devin Lim61643762017-12-07 15:55:38 -0800545def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700546 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700547
Jon Hall6af749d2018-05-29 12:59:47 -0700548 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
549 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800550}
Devin Limf5175192018-05-14 19:13:22 -0700551
Jon Hall6af749d2018-05-29 12:59:47 -0700552def databasePart( wikiPrefix, testName, database_command ){
553 // to read and insert the data from .csv to the database
554
555 return '''
Devin Lim61643762017-12-07 15:55:38 -0800556 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
557 do
558 echo \$line
559 echo ''' + database_command + '''
560 done '''
561}
Jon Hall6af749d2018-05-29 12:59:47 -0700562
563def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
564 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700565 // Will generate the stats graph.
566
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800567 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
568 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
569 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
570 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
571 makeTestList( AllTheTests[ "HA" ], true ) +
572 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700573 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
574 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800575}
Jon Hall6af749d2018-05-29 12:59:47 -0700576
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700577def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700578 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700579 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
580}
Jon Hall6af749d2018-05-29 12:59:47 -0700581
You Wangfe3877b2018-08-02 11:48:35 -0700582def testBranchWithPrefix( branch ){
583 // get TestON branch with the prefix ( "onos-" )
584 if ( branch == "1.13" )
585 return "onos-1.13"
586 else if ( branch == "1.12" )
587 return "onos-1.13"
588 else
589 return "master"
590}
591
Jon Hall6af749d2018-05-29 12:59:47 -0700592return this