blob: ef20820c7d7c61ed9f7f1552affad68a77a705a9 [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 ){
392 sh initAndRunTest( testName, testCategory )
393 // For the Wiki page
394 sh cleanAndCopyFiles( pureTestName )
395 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700396 databaseAndGraph( prop, testName, pureTestName, graphOnly,
397 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700398 if ( !graphOnly ){
399 sh fetchLogs( pureTestName )
400 if ( !isSCPF ){
401 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
402 testCategory[ testName ][ 'wiki_link' ],
403 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
404 }
405 }
Devin Lim61643762017-12-07 15:55:38 -0800406 }
Jon Hall6af749d2018-05-29 12:59:47 -0700407 }
Devin Lim61643762017-12-07 15:55:38 -0800408 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700409 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700410 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700411 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
412 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
413 isSCPF )
414 }
415 }
416 }
417 }
418 }
Devin Lim61643762017-12-07 15:55:38 -0800419}
Devin Limf5175192018-05-14 19:13:22 -0700420
Jon Hall8b1e92c2018-06-13 14:07:22 -0700421def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700422 // part where it insert the data into the database.
423 // It will use the predefined encrypted variables from the Jenkins.
424 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700425 // testName : Jenkins name for the test
426 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700427 // graphOnly : boolean whether it is graph only or not
428 // graph_generator_file : Rscript file with the full path.
429 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700430 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
431 // Post Results
432 withCredentials( [
433 string( credentialsId: 'db_pass', variable: 'pass' ),
434 string( credentialsId: 'db_user', variable: 'user' ),
435 string( credentialsId: 'db_host', variable: 'host' ),
436 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
437 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
438 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
439 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800440 export DATE=\$(date +%F_%T)
441 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700442 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700443 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700444 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
445 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
446 graph_generator_file ) :
447 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800448 }
Devin Lim61643762017-12-07 15:55:38 -0800449 }
450}
Jon Hall6af749d2018-05-29 12:59:47 -0700451
452def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
453 save_path, pieTestListPart ){
454 // function that will generate the category stat graphs for the overall test.
455 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
456 // manualRun : string of "true" or "false"
457 // postresult : string of "true" or "false"
458 // stat_file : file name with full path for Rscript for the stat graph
459 // pie_file : file name with full path for Rscript for the pie graph
460 // type : type of the test ( USECASE, FUNC, HA )
461 // branch : branch of the test ( master, onos-1.12, onos-1.13 )
462 // testListPart : list of the test to be included
463 // save_path : path that will save the graphs to
464 // pieTestListPart : list of the test for pie graph
465
466 if ( isPostingResult( manualRun, postresult ) ){
467 node( testMachineOn ) {
468
469 withCredentials( [
470 string( credentialsId: 'db_pass', variable: 'pass' ),
471 string( credentialsId: 'db_user', variable: 'user' ),
472 string( credentialsId: 'db_host', variable: 'host' ),
473 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
474 sh '''#!/bin/bash
475 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
476 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
477 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
478 save_path ) + '''
479 ''' +
480 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
481 }
482 }
483 postResult( [ ], true )
484 }
485}
486
Devin Lim61643762017-12-07 15:55:38 -0800487def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700488 // make the list of the test in to a string.
489 // list : list of the test
490 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700491
Jon Hall6af749d2018-05-29 12:59:47 -0700492 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800493}
Jon Hall6af749d2018-05-29 12:59:47 -0700494
Devin Lim61643762017-12-07 15:55:38 -0800495def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700496 // make the list for stats
497 // testCategory : category of the test
498 // list : list of the test
499 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700500
Jon Hall6af749d2018-05-29 12:59:47 -0700501 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800502}
Jon Hall6af749d2018-05-29 12:59:47 -0700503
Devin Lim61643762017-12-07 15:55:38 -0800504def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700505 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800506
Jon Hall6af749d2018-05-29 12:59:47 -0700507 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
508 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800509
Jon Hall6af749d2018-05-29 12:59:47 -0700510 withCredentials( [
511 string( credentialsId: 'db_pass', variable: 'pass' ),
512 string( credentialsId: 'db_user', variable: 'user' ),
513 string( credentialsId: 'db_host', variable: 'host' ),
514 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
515 testList = generalFuncs.getTestList( testCategory )
516 sh '''#!/bin/bash
517 ''' +
518 generalFuncs.basicGraphPart( trend_generator_file, host, port,
519 user, pass, testType,
520 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
521 }
Devin Lim61643762017-12-07 15:55:38 -0800522 }
Jon Hall6af749d2018-05-29 12:59:47 -0700523 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800524 }
525}
Jon Hall6af749d2018-05-29 12:59:47 -0700526
Devin Lim61643762017-12-07 15:55:38 -0800527def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700528 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700529
Jon Hall6af749d2018-05-29 12:59:47 -0700530 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
531 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800532}
Jon Hall6af749d2018-05-29 12:59:47 -0700533
Devin Lim61643762017-12-07 15:55:38 -0800534def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700535 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700536
Jon Hall6af749d2018-05-29 12:59:47 -0700537 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
538 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800539}
Jon Hall6af749d2018-05-29 12:59:47 -0700540
Devin Lim61643762017-12-07 15:55:38 -0800541def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700542 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700543
Jon Hall6af749d2018-05-29 12:59:47 -0700544 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
545 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800546}
Devin Limf5175192018-05-14 19:13:22 -0700547
Jon Hall6af749d2018-05-29 12:59:47 -0700548def databasePart( wikiPrefix, testName, database_command ){
549 // to read and insert the data from .csv to the database
550
551 return '''
Devin Lim61643762017-12-07 15:55:38 -0800552 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
553 do
554 echo \$line
555 echo ''' + database_command + '''
556 done '''
557}
Jon Hall6af749d2018-05-29 12:59:47 -0700558
559def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
560 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700561 // Will generate the stats graph.
562
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800563 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
564 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
565 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
566 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
567 makeTestList( AllTheTests[ "HA" ], true ) +
568 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700569 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
570 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800571}
Jon Hall6af749d2018-05-29 12:59:47 -0700572
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700573def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700574 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700575 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
576}
Jon Hall6af749d2018-05-29 12:59:47 -0700577
You Wangfe3877b2018-08-02 11:48:35 -0700578def testBranchWithPrefix( branch ){
579 // get TestON branch with the prefix ( "onos-" )
580 if ( branch == "1.13" )
581 return "onos-1.13"
582 else if ( branch == "1.12" )
583 return "onos-1.13"
584 else
585 return "master"
586}
587
Jon Hall6af749d2018-05-29 12:59:47 -0700588return this