blob: 94d2dbdd22e1d658627f0bf34770bbbe00257cf2 [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' )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070029test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
Devin Limfe9a4cb2018-05-11 17:06:21 -070030
31fileRelated.init()
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070032test_list.init()
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -080033
Devin Lim61643762017-12-07 15:55:38 -080034def initializeTrend( machine ){
Jon Hall6af749d2018-05-29 12:59:47 -070035 // For initializing any trend graph jobs
36 // machine : Either VM,BM, or Fabric#
Devin Limf5175192018-05-14 19:13:22 -070037
Jon Hall6af749d2018-05-29 12:59:47 -070038 table_name = "executed_test_tests"
39 result_name = "executed_test_results"
40 testMachine = "TestStation-" + machine + "s"
41 this.machine = machine
42 isSCPF = false
Jon Hall2ee92f82018-06-07 13:07:33 -070043 hasArgs = false
Jon Hall6af749d2018-05-29 12:59:47 -070044 isTrend = true
Devin Lim61643762017-12-07 15:55:38 -080045}
Jon Hall6af749d2018-05-29 12:59:47 -070046
Devin Lim61643762017-12-07 15:55:38 -080047def initialize( type, SCPFfuncs ){
Jon Hall6af749d2018-05-29 12:59:47 -070048 // Initializing for SCPF tests
49 // type : type of the test ( SR,FUNC,SCPF... )
50 // Passing the SCPFfunction which will be PerformanceFuncs.groovy
Devin Limf5175192018-05-14 19:13:22 -070051
Jon Hall6af749d2018-05-29 12:59:47 -070052 init( type )
53 SCPFfunc = SCPFfuncs
54 isSCPF = true
Jon Hall2ee92f82018-06-07 13:07:33 -070055 hasArgs = true // Has TestON cli arguments to be added when running the test
Jon Hall6af749d2018-05-29 12:59:47 -070056 machine = machineType[ type ]
Devin Lim61643762017-12-07 15:55:38 -080057}
Jon Hall6af749d2018-05-29 12:59:47 -070058
Devin Lim61643762017-12-07 15:55:38 -080059def initialize( type ){
Jon Hall6af749d2018-05-29 12:59:47 -070060 // initializing for FUNC,HA,SR, and USECASE
61 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070062
Jon Hall6af749d2018-05-29 12:59:47 -070063 init( type )
64 SCPFfunc = null
65 table_name = "executed_test_tests"
66 result_name = "executed_test_results"
67 trend_generator_file = fileRelated.trendMultiple
68 build_stats_generator_file = fileRelated.histogramMultiple
69 isSCPF = false
Jon Hall2ee92f82018-06-07 13:07:33 -070070 hasArgs = false
Devin Lim61643762017-12-07 15:55:38 -080071}
Jon Hall6af749d2018-05-29 12:59:47 -070072
Devin Lim61643762017-12-07 15:55:38 -080073def init( type ){
Jon Hall6af749d2018-05-29 12:59:47 -070074 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070075
Jon Hall6af749d2018-05-29 12:59:47 -070076 machineType = [ "FUNC": "VM",
77 "HA": "VM",
78 "SR": "Fabric",
79 "SCPF": "BM",
80 "USECASE": "BM" ]
81 testType = type
82 testMachine = "TestStation-" + machineType[ type ] + "s"
83 isTrend = false
Devin Lim61643762017-12-07 15:55:38 -080084}
Jon Hall6af749d2018-05-29 12:59:47 -070085
Devin Lim86e40532018-04-06 12:44:06 -070086def additionalInitForSR( branch ){
Jon Hall6af749d2018-05-29 12:59:47 -070087 // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running.
You Wangf043d0a2019-04-22 16:30:40 -070088 // branch : branch of the onos. ( master, 2.1, 1.15... )
Devin Limf5175192018-05-14 19:13:22 -070089
Jon Hall6af749d2018-05-29 12:59:47 -070090 testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size() - 1, fabricOn( branch ) ) ).
91 toString()
92 if ( isTrend ){
93 machine += fabricOn( branch )
Devin Lim61643762017-12-07 15:55:38 -080094 }
Jon Hall6af749d2018-05-29 12:59:47 -070095 else {
96 machineType[ testType ] += fabricOn( branch )
97 }
98 print testMachine
Devin Lim61643762017-12-07 15:55:38 -080099}
Devin Limf5175192018-05-14 19:13:22 -0700100
Jon Hall6af749d2018-05-29 12:59:47 -0700101def fabricOn( branch ){
102 // gets the fabric machines with the branch of onos.
You Wangf043d0a2019-04-22 16:30:40 -0700103 // branch : master, 2.1, 1.15...
Jon Hall6af749d2018-05-29 12:59:47 -0700104 // branch.reverse().take(4).reverse() will get last 4 characters of the string.
You Wangdba6c9f2018-12-21 11:58:55 -0800105 switch ( branch.reverse().take( 3 ).reverse() ){
106 case "ter": return "4"
You Wangf043d0a2019-04-22 16:30:40 -0700107 case "2.1": return "3"
You Wangdba6c9f2018-12-21 11:58:55 -0800108 case "2.0": return "3"
109 case ".15": return "2"
110 case ".14": return "3"
111 case ".13": return "2"
112 case ".12": return "3"
Jon Hall6af749d2018-05-29 12:59:47 -0700113 default: return "4"
114 }
115}
116
117def printType(){
118 // print the test type and test machine that was initialized.
119
120 echo testType
121 echo testMachine
122}
123
Jeremy Ronquillo259d71f2019-06-07 14:38:46 -0700124def getProperties( category ){
Jon Hall6af749d2018-05-29 12:59:47 -0700125 // get the properties of the test by reading the TestONOS.property
126
127 node( testMachine ) {
Jeremy Ronquillo259d71f2019-06-07 14:38:46 -0700128 return readProperties( file: '/var/jenkins/TestONOS-' + category + '.property' )
Jon Hall6af749d2018-05-29 12:59:47 -0700129 }
130}
131
132def getTestsToRun( testList ){
133 // get test to run by tokenizing the list.
134
135 testList.tokenize( "\n;, " )
136}
137
138def getCurrentTime(){
139 // get time of the PST zone.
140
141 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
142 return new Date()
143}
144
145def getTotalTime( start, end ){
146 // get total time of the test using start and end time.
147
148 return TimeCategory.minus( end, start )
149}
150
151def printTestToRun( testList ){
152 // printout the list of the test in the list.
153
154 for ( String test : testList ){
155 println test
156 }
157}
158
159def sendResultToSlack( start, isManualRun, branch ){
160 // send the result of the test to the slack when it is not manually running.
161 // start : start time of the test
162 // isManualRun : string that is whether "false" or "true"
163 // branch : branch of the onos.
164
165 try {
166 if ( isManualRun == "false" ){
167 end = getCurrentTime()
168 TimeDuration duration = TimeCategory.minus( end, start )
You Wang28cb8552019-02-19 16:11:52 -0800169 // FIXME: for now we disable notifications of normal test results
170 /*
Jon Hall6af749d2018-05-29 12:59:47 -0700171 slackSend( color: "#5816EE",
172 message: testType + "-" + branch + " tests ended at: " + end.toString() +
173 "\nTime took : " + duration )
You Wang28cb8552019-02-19 16:11:52 -0800174 */
Jon Hall6af749d2018-05-29 12:59:47 -0700175 }
176 }
177 catch ( all ){
178 }
179}
180
181def initAndRunTest( testName, testCategory ){
182 // Bash script that will
183 // Initialize the environment to the machine and run the test.
184 // testName : name of the test
185 // testCategory : (SR,FUNC ... )
186
187 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800188 set -i # interactive
189 set +e
190 shopt -s expand_aliases # expand alias in non-interactive mode
191 export PYTHONUNBUFFERED=1
192 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800193 echo "ONOS Branch is: $ONOSBranch"
194 echo "TestON Branch is: $TestONBranch"
195 echo "Test date: "
196 date
197 cd ~
198 export PATH=$PATH:onos/tools/test/bin
199 timeout 240 stc shutdown | head -100
200 timeout 240 stc teardown | head -100
201 timeout 240 stc shutdown | head -100
202 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700203 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800204 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700205 ''' + "./cli.py run " +
Jon Hall2ee92f82018-06-07 13:07:33 -0700206 ( !hasArgs ? testName : testCategory[ testName ][ 'test' ] ) +
Jon Hall6af749d2018-05-29 12:59:47 -0700207 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800208 ./cleanup.sh -f
209 # cleanup config changes
210 cd ~/onos/tools/package/config
211 git clean -df'''
212}
Devin Limf5175192018-05-14 19:13:22 -0700213
Jon Hall8b1e92c2018-06-13 14:07:22 -0700214def copyLogs(){
215 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700216
217 result = ""
218 if ( testType == "SR" ){
219 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800220 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
221 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
222 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
223 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700224 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700225 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800226 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700227 }
228 return result
Devin Lim61643762017-12-07 15:55:38 -0800229}
Devin Limf5175192018-05-14 19:13:22 -0700230
Jon Hall6af749d2018-05-29 12:59:47 -0700231def cleanAndCopyFiles( testName ){
232 // clean up some files that were in the folder and copy the new files from the log
233 // testName : name of the test
234
235 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800236 set +e
237 echo "ONOS Branch is: ${ONOSBranch}"
238 echo "TestON Branch is: ${TestONBranch}"
239 echo "Job name is: "''' + testName + '''
240 echo "Workspace is: ${WORKSPACE}/"
241 echo "Wiki page to post is: ${WikiPrefix}-"
242 # remove any leftover files from previous tests
243 sudo rm ${WORKSPACE}/*Wiki.txt
244 sudo rm ${WORKSPACE}/*Summary.txt
245 sudo rm ${WORKSPACE}/*Result.txt
You Wangaa7bc722019-02-21 17:55:39 -0800246 sudo rm ${WORKSPACE}/*Alarm.txt || true
Devin Lim61643762017-12-07 15:55:38 -0800247 sudo rm ${WORKSPACE}/*.csv
248 #copy files to workspace
249 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700250 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800251 sudo cp *.txt ${WORKSPACE}/
252 sudo cp *.csv ${WORKSPACE}/
253 cd ${WORKSPACE}/
254 for i in *.csv
255 do mv "$i" "$WikiPrefix"-"$i"
256 done
257 ls -al
258 cd '''
259}
Devin Limf5175192018-05-14 19:13:22 -0700260
Jon Hall6af749d2018-05-29 12:59:47 -0700261def fetchLogs( testName ){
262 // fetch the logs of onos from onos nodes to onos System Test logs
263 // testName: name of the test
264
265 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800266 set +e
267 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700268 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800269 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
270 echo "########################################################################################"
271 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
272 echo "########################################################################################"
273 cd $TestONlogDir
274 if [ $? -eq 1 ]
275 then
276 echo "Job name does not match any test suite name to move log!"
277 else
278 pwd
Jon Hall3e6edb32018-08-21 16:20:30 -0700279 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
280 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 -0800281 fi
282 cd'''
283}
Jon Hall6af749d2018-05-29 12:59:47 -0700284
Devin Lim61643762017-12-07 15:55:38 -0800285def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700286 // check if it is posting the result.
287 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700288
Jon Hall6af749d2018-05-29 12:59:47 -0700289 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800290}
Jon Hall6af749d2018-05-29 12:59:47 -0700291
Devin Lim61643762017-12-07 15:55:38 -0800292def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700293 // post the result by triggering postjob.
294 // prop : property dictionary that was read from the machine.
295 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700296
Jon Hall6af749d2018-05-29 12:59:47 -0700297 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
298 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800299 }
Devin Lim61643762017-12-07 15:55:38 -0800300}
Jon Hall6af749d2018-05-29 12:59:47 -0700301
302def postLogs( testName, prefix ){
303 // posting logs of the onos jobs specifically SR tests
304 // testName : name of the test
You Wangf043d0a2019-04-22 16:30:40 -0700305 // prefix : branch prefix ( master, 2.1, 1.15 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700306
307 resultURL = ""
308 if ( testType == "SR" ){
309 def post = build job: "SR-log-" + prefix, propagate: false
310 resultURL = post.getAbsoluteUrl()
311 }
312 return resultURL
313}
314
315def getSlackChannel(){
316 // get name of the slack channel.
317 // if the test is SR, it will return sr-failures
318
You Wang28cb8552019-02-19 16:11:52 -0800319 // FIXME: For now we move all notifications to #jenkins-related
320 // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
321 return "#jenkins-related"
Jon Hall6af749d2018-05-29 12:59:47 -0700322}
323
Jon Hall8b1e92c2018-06-13 14:07:22 -0700324def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
You Wang28cb8552019-02-19 16:11:52 -0800325 // analyzing the result of the test and send to slack if any abnormal result is logged.
Jon Hall6af749d2018-05-29 12:59:47 -0700326 // prop : property dictionary
327 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700328 // pureTestName : TestON name of the test
329 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700330 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
331 // wikiLink : link of the wiki page where the result was posted
332 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
333
334 node( testMachine ) {
You Wang28cb8552019-02-19 16:11:52 -0800335 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
336 if ( fileExists( alarmFile ) ) {
337 print "Abnormal test result logged"
338 def alarmContents = readFile( alarmFile )
You Wang2dcde682019-02-21 12:18:15 -0800339 slackSend( channel: getSlackChannel(),
340 color: "FF0000",
341 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
342 alarmContents + "\n" +
343 "[TestON log] : \n" +
344 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
345 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
346 "https://wiki.onosproject.org/display/ONOS/" +
347 wikiLink.replaceAll( "\\s", "+" ) ) ) +
348 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
349 resultURL + "artifact/" ) : "" ),
350 teamDomain: 'onosproject' )
Jon Hall6af749d2018-05-29 12:59:47 -0700351 Failed
352 }
You Wang28cb8552019-02-19 16:11:52 -0800353 else {
354 print "Test results are normal"
355 }
Jon Hall6af749d2018-05-29 12:59:47 -0700356 }
357}
358
Devin Lime89761a2018-03-16 17:52:57 -0700359def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700360 // publish HTML script to wiki confluence
361 // isManualRun : string "true" "false"
362 // isPostResult : string "true" "false"
363 // wikiLink : link of the wiki page to publish
364 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700365
Jon Hall6af749d2018-05-29 12:59:47 -0700366 if ( isPostingResult( isManualRun, isPostResult ) ){
367 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
368 attachArchivedArtifacts: true, buildIfUnstable: true,
369 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
370 }
Devin Lim61643762017-12-07 15:55:38 -0800371
372}
Devin Limf5175192018-05-14 19:13:22 -0700373
Jon Hall6af749d2018-05-29 12:59:47 -0700374def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
375 graph_saved_directory ){
376 // 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 -0700377 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700378 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
379 // result on pipeline view
380 // prop : dictionary property on the machine
381 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
382 // 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 -0700383 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700384 // graph_generator_file : Rscript file with the full path.
385 // graph_saved_directory : where the generated graph will be saved to.
386
387 return {
388 catchError {
389 stage( testName ) {
390 if ( toBeRun ){
391 def workSpace = "/var/jenkins/workspace/" + testName
392 def fileContents = ""
393 node( testMachine ) {
394 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
You Wang8e4f4c02019-01-03 10:49:46 -0800395 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
Jon Hall6af749d2018-05-29 12:59:47 -0700396 'TestONBranch=' + prop[ "TestONBranch" ],
397 'ONOSTag=' + prop[ "ONOSTag" ],
398 'WikiPrefix=' + prop[ "WikiPrefix" ],
399 'WORKSPACE=' + workSpace ] ) {
400 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700401 if ( isSCPF ){
402 // Remove the old database file
403 sh SCPFfunc.cleanupDatabaseFile( testName )
404 }
Jon Hall6af749d2018-05-29 12:59:47 -0700405 sh initAndRunTest( testName, testCategory )
406 // For the Wiki page
407 sh cleanAndCopyFiles( pureTestName )
408 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700409 databaseAndGraph( prop, testName, pureTestName, graphOnly,
410 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700411 if ( !graphOnly ){
412 sh fetchLogs( pureTestName )
413 if ( !isSCPF ){
414 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
415 testCategory[ testName ][ 'wiki_link' ],
416 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
417 }
418 }
Devin Lim61643762017-12-07 15:55:38 -0800419 }
Jon Hall6af749d2018-05-29 12:59:47 -0700420 }
Devin Lim61643762017-12-07 15:55:38 -0800421 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700422 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700423 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700424 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
425 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
426 isSCPF )
427 }
428 }
429 }
430 }
431 }
Devin Lim61643762017-12-07 15:55:38 -0800432}
Devin Limf5175192018-05-14 19:13:22 -0700433
Jon Hall8b1e92c2018-06-13 14:07:22 -0700434def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700435 // part where it insert the data into the database.
436 // It will use the predefined encrypted variables from the Jenkins.
437 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700438 // testName : Jenkins name for the test
439 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700440 // graphOnly : boolean whether it is graph only or not
441 // graph_generator_file : Rscript file with the full path.
442 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700443 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
444 // Post Results
445 withCredentials( [
446 string( credentialsId: 'db_pass', variable: 'pass' ),
447 string( credentialsId: 'db_user', variable: 'user' ),
448 string( credentialsId: 'db_host', variable: 'host' ),
449 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
450 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
451 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
452 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800453 export DATE=\$(date +%F_%T)
454 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700455 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700456 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700457 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
458 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
459 graph_generator_file ) :
460 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800461 }
Devin Lim61643762017-12-07 15:55:38 -0800462 }
463}
Jon Hall6af749d2018-05-29 12:59:47 -0700464
465def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
466 save_path, pieTestListPart ){
467 // function that will generate the category stat graphs for the overall test.
468 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
469 // manualRun : string of "true" or "false"
470 // postresult : string of "true" or "false"
471 // stat_file : file name with full path for Rscript for the stat graph
472 // pie_file : file name with full path for Rscript for the pie graph
473 // type : type of the test ( USECASE, FUNC, HA )
You Wangf043d0a2019-04-22 16:30:40 -0700474 // branch : branch of the test ( master, onos-2.1, onos-1.15 )
Jon Hall6af749d2018-05-29 12:59:47 -0700475 // testListPart : list of the test to be included
476 // save_path : path that will save the graphs to
477 // pieTestListPart : list of the test for pie graph
478
479 if ( isPostingResult( manualRun, postresult ) ){
480 node( testMachineOn ) {
481
482 withCredentials( [
483 string( credentialsId: 'db_pass', variable: 'pass' ),
484 string( credentialsId: 'db_user', variable: 'user' ),
485 string( credentialsId: 'db_host', variable: 'host' ),
486 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
487 sh '''#!/bin/bash
488 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
489 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
490 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
491 save_path ) + '''
492 ''' +
493 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
494 }
495 }
496 postResult( [ ], true )
497 }
498}
499
Jon Hall6af749d2018-05-29 12:59:47 -0700500
Devin Lim61643762017-12-07 15:55:38 -0800501def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700502 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800503
Jon Hall6af749d2018-05-29 12:59:47 -0700504 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
505 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800506
Jon Hall6af749d2018-05-29 12:59:47 -0700507 withCredentials( [
508 string( credentialsId: 'db_pass', variable: 'pass' ),
509 string( credentialsId: 'db_user', variable: 'user' ),
510 string( credentialsId: 'db_host', variable: 'host' ),
511 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
512 testList = generalFuncs.getTestList( testCategory )
513 sh '''#!/bin/bash
514 ''' +
515 generalFuncs.basicGraphPart( trend_generator_file, host, port,
516 user, pass, testType,
517 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
518 }
Devin Lim61643762017-12-07 15:55:38 -0800519 }
Jon Hall6af749d2018-05-29 12:59:47 -0700520 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800521 }
522}
Jon Hall6af749d2018-05-29 12:59:47 -0700523
Devin Lim61643762017-12-07 15:55:38 -0800524def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700525 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700526
Jon Hall6af749d2018-05-29 12:59:47 -0700527 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
528 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800529}
Jon Hall6af749d2018-05-29 12:59:47 -0700530
Devin Lim61643762017-12-07 15:55:38 -0800531def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700532 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700533
Jon Hall6af749d2018-05-29 12:59:47 -0700534 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
535 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800536}
Jon Hall6af749d2018-05-29 12:59:47 -0700537
Devin Lim61643762017-12-07 15:55:38 -0800538def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700539 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700540
Jon Hall6af749d2018-05-29 12:59:47 -0700541 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
542 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800543}
Devin Limf5175192018-05-14 19:13:22 -0700544
Jon Hall6af749d2018-05-29 12:59:47 -0700545def databasePart( wikiPrefix, testName, database_command ){
546 // to read and insert the data from .csv to the database
547
548 return '''
Devin Lim61643762017-12-07 15:55:38 -0800549 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
550 do
551 echo \$line
552 echo ''' + database_command + '''
553 done '''
554}
Jon Hall6af749d2018-05-29 12:59:47 -0700555
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700556def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
Jon Hall6af749d2018-05-29 12:59:47 -0700557 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700558
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700559 // Will generate the stats graph.
560 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
561 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
562 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
563
564 testListParam = "FUNC-" + FUNCtestsStr + ";" +
565 "HA-" + HAtestsStr + ";" +
566 "USECASE-" + USECASEtestsStr
567
568 pieTestListParam = FUNCtestsStr + "," +
569 HAtestsStr + "," +
570 USECASEtestsStr
571
Jon Hall6af749d2018-05-29 12:59:47 -0700572 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700573 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800574}
Jon Hall6af749d2018-05-29 12:59:47 -0700575
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700576def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700577 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700578 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
579}
Jon Hall6af749d2018-05-29 12:59:47 -0700580
You Wangfe3877b2018-08-02 11:48:35 -0700581def testBranchWithPrefix( branch ){
582 // get TestON branch with the prefix ( "onos-" )
You Wang8f12d7d2018-11-09 13:47:23 -0800583 if ( branch == "1.12" )
You Wangfe3877b2018-08-02 11:48:35 -0700584 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800585 else if ( branch == "1.13" )
You Wangfe3877b2018-08-02 11:48:35 -0700586 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800587 else if ( branch == "1.14" )
You Wangda4b1442018-11-29 12:31:22 -0800588 return "onos-1.15"
You Wang8f12d7d2018-11-09 13:47:23 -0800589 else if ( branch == "1.15" )
You Wangda4b1442018-11-29 12:31:22 -0800590 return "onos-1.15"
You Wangdba6c9f2018-12-21 11:58:55 -0800591 else if ( branch == "2.0" )
You Wanga4062a32019-03-21 15:25:13 -0700592 return "onos-2.0"
You Wangf043d0a2019-04-22 16:30:40 -0700593 else if ( branch == "2.1" )
594 return "onos-2.1"
You Wangfe3877b2018-08-02 11:48:35 -0700595 else
596 return "master"
597}
598
Jon Hall6af749d2018-05-29 12:59:47 -0700599return this