blob: a0905a3e2c2fb129c29219230dc790401a2d6e90 [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
270 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist; done
271 fi
272 cd'''
273}
Jon Hall6af749d2018-05-29 12:59:47 -0700274
Devin Lim61643762017-12-07 15:55:38 -0800275def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700276 // check if it is posting the result.
277 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700278
Jon Hall6af749d2018-05-29 12:59:47 -0700279 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800280}
Jon Hall6af749d2018-05-29 12:59:47 -0700281
Devin Lim61643762017-12-07 15:55:38 -0800282def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700283 // post the result by triggering postjob.
284 // prop : property dictionary that was read from the machine.
285 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700286
Jon Hall6af749d2018-05-29 12:59:47 -0700287 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
288 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800289 }
Devin Lim61643762017-12-07 15:55:38 -0800290}
Jon Hall6af749d2018-05-29 12:59:47 -0700291
292def postLogs( testName, prefix ){
293 // posting logs of the onos jobs specifically SR tests
294 // testName : name of the test
295 // prefix : branch prefix ( master, 1.12, 1.13 ... )
296
297 resultURL = ""
298 if ( testType == "SR" ){
299 def post = build job: "SR-log-" + prefix, propagate: false
300 resultURL = post.getAbsoluteUrl()
301 }
302 return resultURL
303}
304
305def getSlackChannel(){
306 // get name of the slack channel.
307 // if the test is SR, it will return sr-failures
308
309 return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
310}
311
Jon Hall8b1e92c2018-06-13 14:07:22 -0700312def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
Jon Hall6af749d2018-05-29 12:59:47 -0700313 // analyzing the result of the test and send to slack if the test was failed.
314 // prop : property dictionary
315 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700316 // pureTestName : TestON name of the test
317 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700318 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
319 // wikiLink : link of the wiki page where the result was posted
320 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
321
322 node( testMachine ) {
Jon Hall8b1e92c2018-06-13 14:07:22 -0700323 def resultContents = readFile( workSpace + "/" + pureTestName + "Result.txt" )
Jon Hall6af749d2018-05-29 12:59:47 -0700324 resultContents = resultContents.split( "\n" )
325 if ( resultContents[ 0 ] == "1" ){
326 print "All passed"
327 }
328 else {
329 print "Failed"
330 if ( prop[ "manualRun" ] == "false" ){
331 slackSend( channel: getSlackChannel(),
332 color: "FF0000",
Jon Hall8b1e92c2018-06-13 14:07:22 -0700333 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : Failed!\n" +
Jon Hall6af749d2018-05-29 12:59:47 -0700334 resultContents[ 1 ] + "\n" +
335 "[TestON log] : \n" +
336 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
337 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
338 "https://wiki.onosproject.org/display/ONOS/" +
339 wikiLink.replaceAll( "\\s", "+" ) ) ) +
340 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
341 resultURL + "artifact/" ) : "" ),
342 teamDomain: 'onosproject' )
343 }
344 Failed
345 }
346 }
347}
348
Devin Lime89761a2018-03-16 17:52:57 -0700349def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700350 // publish HTML script to wiki confluence
351 // isManualRun : string "true" "false"
352 // isPostResult : string "true" "false"
353 // wikiLink : link of the wiki page to publish
354 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700355
Jon Hall6af749d2018-05-29 12:59:47 -0700356 if ( isPostingResult( isManualRun, isPostResult ) ){
357 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
358 attachArchivedArtifacts: true, buildIfUnstable: true,
359 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
360 }
Devin Lim61643762017-12-07 15:55:38 -0800361
362}
Devin Limf5175192018-05-14 19:13:22 -0700363
Jon Hall6af749d2018-05-29 12:59:47 -0700364def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
365 graph_saved_directory ){
366 // 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 -0700367 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700368 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
369 // result on pipeline view
370 // prop : dictionary property on the machine
371 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
372 // 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 -0700373 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700374 // graph_generator_file : Rscript file with the full path.
375 // graph_saved_directory : where the generated graph will be saved to.
376
377 return {
378 catchError {
379 stage( testName ) {
380 if ( toBeRun ){
381 def workSpace = "/var/jenkins/workspace/" + testName
382 def fileContents = ""
383 node( testMachine ) {
384 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
385 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
386 'TestONBranch=' + prop[ "TestONBranch" ],
387 'ONOSTag=' + prop[ "ONOSTag" ],
388 'WikiPrefix=' + prop[ "WikiPrefix" ],
389 'WORKSPACE=' + workSpace ] ) {
390 if ( !graphOnly ){
391 sh initAndRunTest( testName, testCategory )
392 // For the Wiki page
393 sh cleanAndCopyFiles( pureTestName )
394 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700395 databaseAndGraph( prop, testName, pureTestName, graphOnly,
396 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700397 if ( !graphOnly ){
398 sh fetchLogs( pureTestName )
399 if ( !isSCPF ){
400 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
401 testCategory[ testName ][ 'wiki_link' ],
402 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
403 }
404 }
Devin Lim61643762017-12-07 15:55:38 -0800405 }
Jon Hall6af749d2018-05-29 12:59:47 -0700406 }
Devin Lim61643762017-12-07 15:55:38 -0800407 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700408 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700409 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700410 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
411 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
412 isSCPF )
413 }
414 }
415 }
416 }
417 }
Devin Lim61643762017-12-07 15:55:38 -0800418}
Devin Limf5175192018-05-14 19:13:22 -0700419
Jon Hall8b1e92c2018-06-13 14:07:22 -0700420def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700421 // part where it insert the data into the database.
422 // It will use the predefined encrypted variables from the Jenkins.
423 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700424 // testName : Jenkins name for the test
425 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700426 // graphOnly : boolean whether it is graph only or not
427 // graph_generator_file : Rscript file with the full path.
428 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700429 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
430 // Post Results
431 withCredentials( [
432 string( credentialsId: 'db_pass', variable: 'pass' ),
433 string( credentialsId: 'db_user', variable: 'user' ),
434 string( credentialsId: 'db_host', variable: 'host' ),
435 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
436 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
437 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
438 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800439 export DATE=\$(date +%F_%T)
440 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700441 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700442 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700443 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
444 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
445 graph_generator_file ) :
446 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800447 }
Devin Lim61643762017-12-07 15:55:38 -0800448 }
449}
Jon Hall6af749d2018-05-29 12:59:47 -0700450
451def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
452 save_path, pieTestListPart ){
453 // function that will generate the category stat graphs for the overall test.
454 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
455 // manualRun : string of "true" or "false"
456 // postresult : string of "true" or "false"
457 // stat_file : file name with full path for Rscript for the stat graph
458 // pie_file : file name with full path for Rscript for the pie graph
459 // type : type of the test ( USECASE, FUNC, HA )
460 // branch : branch of the test ( master, onos-1.12, onos-1.13 )
461 // testListPart : list of the test to be included
462 // save_path : path that will save the graphs to
463 // pieTestListPart : list of the test for pie graph
464
465 if ( isPostingResult( manualRun, postresult ) ){
466 node( testMachineOn ) {
467
468 withCredentials( [
469 string( credentialsId: 'db_pass', variable: 'pass' ),
470 string( credentialsId: 'db_user', variable: 'user' ),
471 string( credentialsId: 'db_host', variable: 'host' ),
472 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
473 sh '''#!/bin/bash
474 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
475 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
476 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
477 save_path ) + '''
478 ''' +
479 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
480 }
481 }
482 postResult( [ ], true )
483 }
484}
485
Devin Lim61643762017-12-07 15:55:38 -0800486def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700487 // make the list of the test in to a string.
488 // list : list of the test
489 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700490
Jon Hall6af749d2018-05-29 12:59:47 -0700491 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800492}
Jon Hall6af749d2018-05-29 12:59:47 -0700493
Devin Lim61643762017-12-07 15:55:38 -0800494def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700495 // make the list for stats
496 // testCategory : category of the test
497 // list : list of the test
498 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700499
Jon Hall6af749d2018-05-29 12:59:47 -0700500 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800501}
Jon Hall6af749d2018-05-29 12:59:47 -0700502
Devin Lim61643762017-12-07 15:55:38 -0800503def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700504 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800505
Jon Hall6af749d2018-05-29 12:59:47 -0700506 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
507 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800508
Jon Hall6af749d2018-05-29 12:59:47 -0700509 withCredentials( [
510 string( credentialsId: 'db_pass', variable: 'pass' ),
511 string( credentialsId: 'db_user', variable: 'user' ),
512 string( credentialsId: 'db_host', variable: 'host' ),
513 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
514 testList = generalFuncs.getTestList( testCategory )
515 sh '''#!/bin/bash
516 ''' +
517 generalFuncs.basicGraphPart( trend_generator_file, host, port,
518 user, pass, testType,
519 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
520 }
Devin Lim61643762017-12-07 15:55:38 -0800521 }
Jon Hall6af749d2018-05-29 12:59:47 -0700522 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800523 }
524}
Jon Hall6af749d2018-05-29 12:59:47 -0700525
Devin Lim61643762017-12-07 15:55:38 -0800526def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700527 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700528
Jon Hall6af749d2018-05-29 12:59:47 -0700529 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
530 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800531}
Jon Hall6af749d2018-05-29 12:59:47 -0700532
Devin Lim61643762017-12-07 15:55:38 -0800533def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700534 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700535
Jon Hall6af749d2018-05-29 12:59:47 -0700536 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
537 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800538}
Jon Hall6af749d2018-05-29 12:59:47 -0700539
Devin Lim61643762017-12-07 15:55:38 -0800540def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700541 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700542
Jon Hall6af749d2018-05-29 12:59:47 -0700543 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
544 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800545}
Devin Limf5175192018-05-14 19:13:22 -0700546
Jon Hall6af749d2018-05-29 12:59:47 -0700547def databasePart( wikiPrefix, testName, database_command ){
548 // to read and insert the data from .csv to the database
549
550 return '''
Devin Lim61643762017-12-07 15:55:38 -0800551 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
552 do
553 echo \$line
554 echo ''' + database_command + '''
555 done '''
556}
Jon Hall6af749d2018-05-29 12:59:47 -0700557
558def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
559 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700560 // Will generate the stats graph.
561
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800562 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
563 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
564 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
565 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
566 makeTestList( AllTheTests[ "HA" ], true ) +
567 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700568 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
569 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800570}
Jon Hall6af749d2018-05-29 12:59:47 -0700571
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700572def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700573 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700574 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
575}
Jon Hall6af749d2018-05-29 12:59:47 -0700576
You Wangfe3877b2018-08-02 11:48:35 -0700577def testBranchWithPrefix( branch ){
578 // get TestON branch with the prefix ( "onos-" )
579 if ( branch == "1.13" )
580 return "onos-1.13"
581 else if ( branch == "1.12" )
582 return "onos-1.13"
583 else
584 return "master"
585}
586
Jon Hall6af749d2018-05-29 12:59:47 -0700587return this