blob: 823a07e35661ecf15b130861d9fcec4443b7360d [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
43 isTrend = true
Devin Lim61643762017-12-07 15:55:38 -080044}
Jon Hall6af749d2018-05-29 12:59:47 -070045
Jeremy Ronquillo62199e72019-07-02 14:24:31 -070046def initialize( type, SCPFfuncs=null ){
Jon Hall6af749d2018-05-29 12:59:47 -070047 // initializing for FUNC,HA,SR, and USECASE
48 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070049
Jon Hall6af749d2018-05-29 12:59:47 -070050 init( type )
Jeremy Ronquilloc6a862f2019-07-02 15:53:44 -070051 isSCPF = ( type == "SCPF" )
Jeremy Ronquillo62199e72019-07-02 14:24:31 -070052 SCPFfunc = SCPFfuncs
53
Jon Hall6af749d2018-05-29 12:59:47 -070054 table_name = "executed_test_tests"
55 result_name = "executed_test_results"
56 trend_generator_file = fileRelated.trendMultiple
57 build_stats_generator_file = fileRelated.histogramMultiple
Devin Lim61643762017-12-07 15:55:38 -080058}
Jon Hall6af749d2018-05-29 12:59:47 -070059
Devin Lim61643762017-12-07 15:55:38 -080060def init( type ){
Jon Hall6af749d2018-05-29 12:59:47 -070061 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070062
Jon Hall6af749d2018-05-29 12:59:47 -070063 machineType = [ "FUNC": "VM",
64 "HA": "VM",
65 "SR": "Fabric",
66 "SCPF": "BM",
67 "USECASE": "BM" ]
68 testType = type
69 testMachine = "TestStation-" + machineType[ type ] + "s"
70 isTrend = false
Devin Lim61643762017-12-07 15:55:38 -080071}
Jon Hall6af749d2018-05-29 12:59:47 -070072
Devin Lim86e40532018-04-06 12:44:06 -070073def additionalInitForSR( branch ){
Jon Hall6af749d2018-05-29 12:59:47 -070074 // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running.
You Wangf043d0a2019-04-22 16:30:40 -070075 // branch : branch of the onos. ( master, 2.1, 1.15... )
Devin Limf5175192018-05-14 19:13:22 -070076
Jon Hall6af749d2018-05-29 12:59:47 -070077 testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size() - 1, fabricOn( branch ) ) ).
78 toString()
79 if ( isTrend ){
80 machine += fabricOn( branch )
Devin Lim61643762017-12-07 15:55:38 -080081 }
Jon Hall6af749d2018-05-29 12:59:47 -070082 else {
83 machineType[ testType ] += fabricOn( branch )
84 }
85 print testMachine
Devin Lim61643762017-12-07 15:55:38 -080086}
Devin Limf5175192018-05-14 19:13:22 -070087
Jon Hall6af749d2018-05-29 12:59:47 -070088def fabricOn( branch ){
89 // gets the fabric machines with the branch of onos.
You Wangf043d0a2019-04-22 16:30:40 -070090 // branch : master, 2.1, 1.15...
Jon Hall6af749d2018-05-29 12:59:47 -070091 // branch.reverse().take(4).reverse() will get last 4 characters of the string.
You Wangdba6c9f2018-12-21 11:58:55 -080092 switch ( branch.reverse().take( 3 ).reverse() ){
93 case "ter": return "4"
You Wangf043d0a2019-04-22 16:30:40 -070094 case "2.1": return "3"
You Wangdba6c9f2018-12-21 11:58:55 -080095 case "2.0": return "3"
96 case ".15": return "2"
97 case ".14": return "3"
98 case ".13": return "2"
99 case ".12": return "3"
Jon Hall6af749d2018-05-29 12:59:47 -0700100 default: return "4"
101 }
102}
103
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700104def getProperties( category, branchWithPrefix ){
Jon Hall6af749d2018-05-29 12:59:47 -0700105 // get the properties of the test by reading the TestONOS.property
106
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700107 filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property'''
108
Jon Hall6af749d2018-05-29 12:59:47 -0700109 node( testMachine ) {
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700110 return readProperties( file: filePath )
Jon Hall6af749d2018-05-29 12:59:47 -0700111 }
112}
113
114def getTestsToRun( testList ){
115 // get test to run by tokenizing the list.
116
117 testList.tokenize( "\n;, " )
118}
119
120def getCurrentTime(){
121 // get time of the PST zone.
122
123 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
124 return new Date()
125}
126
Jon Hall6af749d2018-05-29 12:59:47 -0700127def sendResultToSlack( start, isManualRun, branch ){
128 // send the result of the test to the slack when it is not manually running.
129 // start : start time of the test
130 // isManualRun : string that is whether "false" or "true"
131 // branch : branch of the onos.
132
133 try {
134 if ( isManualRun == "false" ){
135 end = getCurrentTime()
136 TimeDuration duration = TimeCategory.minus( end, start )
You Wang28cb8552019-02-19 16:11:52 -0800137 // FIXME: for now we disable notifications of normal test results
138 /*
Jon Hall6af749d2018-05-29 12:59:47 -0700139 slackSend( color: "#5816EE",
140 message: testType + "-" + branch + " tests ended at: " + end.toString() +
141 "\nTime took : " + duration )
You Wang28cb8552019-02-19 16:11:52 -0800142 */
Jon Hall6af749d2018-05-29 12:59:47 -0700143 }
144 }
145 catch ( all ){
146 }
147}
148
149def initAndRunTest( testName, testCategory ){
150 // Bash script that will
151 // Initialize the environment to the machine and run the test.
152 // testName : name of the test
153 // testCategory : (SR,FUNC ... )
154
155 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800156 set -i # interactive
157 set +e
158 shopt -s expand_aliases # expand alias in non-interactive mode
159 export PYTHONUNBUFFERED=1
160 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800161 echo "ONOS Branch is: $ONOSBranch"
162 echo "TestON Branch is: $TestONBranch"
163 echo "Test date: "
164 date
165 cd ~
166 export PATH=$PATH:onos/tools/test/bin
167 timeout 240 stc shutdown | head -100
168 timeout 240 stc teardown | head -100
169 timeout 240 stc shutdown | head -100
170 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700171 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800172 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700173 ''' + "./cli.py run " +
Jeremy Ronquillo62199e72019-07-02 14:24:31 -0700174 testName +
Jon Hall6af749d2018-05-29 12:59:47 -0700175 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800176 ./cleanup.sh -f
177 # cleanup config changes
178 cd ~/onos/tools/package/config
179 git clean -df'''
180}
Devin Limf5175192018-05-14 19:13:22 -0700181
Jon Hall8b1e92c2018-06-13 14:07:22 -0700182def copyLogs(){
183 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700184
185 result = ""
186 if ( testType == "SR" ){
187 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800188 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
189 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
190 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
191 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700192 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700193 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800194 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700195 }
196 return result
Devin Lim61643762017-12-07 15:55:38 -0800197}
Devin Limf5175192018-05-14 19:13:22 -0700198
Jon Hall6af749d2018-05-29 12:59:47 -0700199def cleanAndCopyFiles( testName ){
200 // clean up some files that were in the folder and copy the new files from the log
201 // testName : name of the test
202
203 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800204 set +e
205 echo "ONOS Branch is: ${ONOSBranch}"
206 echo "TestON Branch is: ${TestONBranch}"
207 echo "Job name is: "''' + testName + '''
208 echo "Workspace is: ${WORKSPACE}/"
209 echo "Wiki page to post is: ${WikiPrefix}-"
210 # remove any leftover files from previous tests
211 sudo rm ${WORKSPACE}/*Wiki.txt
212 sudo rm ${WORKSPACE}/*Summary.txt
213 sudo rm ${WORKSPACE}/*Result.txt
You Wangaa7bc722019-02-21 17:55:39 -0800214 sudo rm ${WORKSPACE}/*Alarm.txt || true
Devin Lim61643762017-12-07 15:55:38 -0800215 sudo rm ${WORKSPACE}/*.csv
216 #copy files to workspace
217 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700218 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800219 sudo cp *.txt ${WORKSPACE}/
220 sudo cp *.csv ${WORKSPACE}/
221 cd ${WORKSPACE}/
222 for i in *.csv
223 do mv "$i" "$WikiPrefix"-"$i"
224 done
225 ls -al
226 cd '''
227}
Devin Limf5175192018-05-14 19:13:22 -0700228
Jon Hall6af749d2018-05-29 12:59:47 -0700229def fetchLogs( testName ){
230 // fetch the logs of onos from onos nodes to onos System Test logs
231 // testName: name of the test
232
233 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800234 set +e
235 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700236 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800237 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
238 echo "########################################################################################"
239 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
240 echo "########################################################################################"
241 cd $TestONlogDir
242 if [ $? -eq 1 ]
243 then
244 echo "Job name does not match any test suite name to move log!"
245 else
246 pwd
Jon Hall3e6edb32018-08-21 16:20:30 -0700247 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
248 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 -0800249 fi
250 cd'''
251}
Jon Hall6af749d2018-05-29 12:59:47 -0700252
Devin Lim61643762017-12-07 15:55:38 -0800253def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700254 // check if it is posting the result.
255 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700256
Jon Hall6af749d2018-05-29 12:59:47 -0700257 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800258}
Jon Hall6af749d2018-05-29 12:59:47 -0700259
Devin Lim61643762017-12-07 15:55:38 -0800260def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700261 // post the result by triggering postjob.
262 // prop : property dictionary that was read from the machine.
263 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700264
Jon Hall6af749d2018-05-29 12:59:47 -0700265 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
Jeremy Ronquilloafca6702019-07-02 16:05:36 -0700266 def post = build job: "postjob-" + machineType[ testType ], propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800267 }
Devin Lim61643762017-12-07 15:55:38 -0800268}
Jon Hall6af749d2018-05-29 12:59:47 -0700269
270def postLogs( testName, prefix ){
271 // posting logs of the onos jobs specifically SR tests
272 // testName : name of the test
You Wangf043d0a2019-04-22 16:30:40 -0700273 // prefix : branch prefix ( master, 2.1, 1.15 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700274
275 resultURL = ""
276 if ( testType == "SR" ){
277 def post = build job: "SR-log-" + prefix, propagate: false
278 resultURL = post.getAbsoluteUrl()
279 }
280 return resultURL
281}
282
283def getSlackChannel(){
284 // get name of the slack channel.
285 // if the test is SR, it will return sr-failures
286
You Wang28cb8552019-02-19 16:11:52 -0800287 // FIXME: For now we move all notifications to #jenkins-related
288 // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
289 return "#jenkins-related"
Jon Hall6af749d2018-05-29 12:59:47 -0700290}
291
Jon Hall8b1e92c2018-06-13 14:07:22 -0700292def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
You Wang28cb8552019-02-19 16:11:52 -0800293 // analyzing the result of the test and send to slack if any abnormal result is logged.
Jon Hall6af749d2018-05-29 12:59:47 -0700294 // prop : property dictionary
295 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700296 // pureTestName : TestON name of the test
297 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700298 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
299 // wikiLink : link of the wiki page where the result was posted
300 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
301
302 node( testMachine ) {
You Wang28cb8552019-02-19 16:11:52 -0800303 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
304 if ( fileExists( alarmFile ) ) {
You Wang28cb8552019-02-19 16:11:52 -0800305 def alarmContents = readFile( alarmFile )
You Wang2dcde682019-02-21 12:18:15 -0800306 slackSend( channel: getSlackChannel(),
307 color: "FF0000",
308 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
309 alarmContents + "\n" +
310 "[TestON log] : \n" +
311 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
312 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
313 "https://wiki.onosproject.org/display/ONOS/" +
314 wikiLink.replaceAll( "\\s", "+" ) ) ) +
315 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
316 resultURL + "artifact/" ) : "" ),
317 teamDomain: 'onosproject' )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700318 throw new Exception( "Abnormal test result." )
Jon Hall6af749d2018-05-29 12:59:47 -0700319 }
You Wang28cb8552019-02-19 16:11:52 -0800320 else {
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700321 print "Test results are normal."
You Wang28cb8552019-02-19 16:11:52 -0800322 }
Jon Hall6af749d2018-05-29 12:59:47 -0700323 }
324}
325
Devin Lime89761a2018-03-16 17:52:57 -0700326def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700327 // publish HTML script to wiki confluence
328 // isManualRun : string "true" "false"
329 // isPostResult : string "true" "false"
330 // wikiLink : link of the wiki page to publish
331 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700332
Jon Hall6af749d2018-05-29 12:59:47 -0700333 if ( isPostingResult( isManualRun, isPostResult ) ){
334 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
335 attachArchivedArtifacts: true, buildIfUnstable: true,
336 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
337 }
Devin Lim61643762017-12-07 15:55:38 -0800338
339}
Devin Limf5175192018-05-14 19:13:22 -0700340
Jon Hall6af749d2018-05-29 12:59:47 -0700341def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
342 graph_saved_directory ){
343 // 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 -0700344 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700345 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
346 // result on pipeline view
347 // prop : dictionary property on the machine
348 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
349 // 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 -0700350 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700351 // graph_generator_file : Rscript file with the full path.
352 // graph_saved_directory : where the generated graph will be saved to.
353
354 return {
355 catchError {
356 stage( testName ) {
357 if ( toBeRun ){
358 def workSpace = "/var/jenkins/workspace/" + testName
359 def fileContents = ""
360 node( testMachine ) {
361 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
You Wang8e4f4c02019-01-03 10:49:46 -0800362 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
Jon Hall6af749d2018-05-29 12:59:47 -0700363 'TestONBranch=' + prop[ "TestONBranch" ],
364 'ONOSTag=' + prop[ "ONOSTag" ],
365 'WikiPrefix=' + prop[ "WikiPrefix" ],
366 'WORKSPACE=' + workSpace ] ) {
367 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700368 if ( isSCPF ){
369 // Remove the old database file
370 sh SCPFfunc.cleanupDatabaseFile( testName )
371 }
Jon Hall6af749d2018-05-29 12:59:47 -0700372 sh initAndRunTest( testName, testCategory )
373 // For the Wiki page
374 sh cleanAndCopyFiles( pureTestName )
375 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700376 databaseAndGraph( prop, testName, pureTestName, graphOnly,
377 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700378 if ( !graphOnly ){
379 sh fetchLogs( pureTestName )
380 if ( !isSCPF ){
381 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
Jeremy Ronquillo5b6279b2019-06-18 14:25:45 -0700382 prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700383 workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700384 }
385 }
Devin Lim61643762017-12-07 15:55:38 -0800386 }
Jon Hall6af749d2018-05-29 12:59:47 -0700387 }
Devin Lim61643762017-12-07 15:55:38 -0800388 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700389 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700390 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700391 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700392 isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
Jon Hall6af749d2018-05-29 12:59:47 -0700393 isSCPF )
394 }
395 }
396 }
397 }
398 }
Devin Lim61643762017-12-07 15:55:38 -0800399}
Devin Limf5175192018-05-14 19:13:22 -0700400
Jon Hall8b1e92c2018-06-13 14:07:22 -0700401def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700402 // part where it insert the data into the database.
403 // It will use the predefined encrypted variables from the Jenkins.
404 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700405 // testName : Jenkins name for the test
406 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700407 // graphOnly : boolean whether it is graph only or not
408 // graph_generator_file : Rscript file with the full path.
409 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700410 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
411 // Post Results
412 withCredentials( [
413 string( credentialsId: 'db_pass', variable: 'pass' ),
414 string( credentialsId: 'db_user', variable: 'user' ),
415 string( credentialsId: 'db_host', variable: 'host' ),
416 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
417 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
418 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
419 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800420 export DATE=\$(date +%F_%T)
421 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700422 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700423 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700424 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
425 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
426 graph_generator_file ) :
427 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800428 }
Devin Lim61643762017-12-07 15:55:38 -0800429 }
430}
Jon Hall6af749d2018-05-29 12:59:47 -0700431
432def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
433 save_path, pieTestListPart ){
434 // function that will generate the category stat graphs for the overall test.
435 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
436 // manualRun : string of "true" or "false"
437 // postresult : string of "true" or "false"
438 // stat_file : file name with full path for Rscript for the stat graph
439 // pie_file : file name with full path for Rscript for the pie graph
440 // type : type of the test ( USECASE, FUNC, HA )
You Wangf043d0a2019-04-22 16:30:40 -0700441 // branch : branch of the test ( master, onos-2.1, onos-1.15 )
Jon Hall6af749d2018-05-29 12:59:47 -0700442 // testListPart : list of the test to be included
443 // save_path : path that will save the graphs to
444 // pieTestListPart : list of the test for pie graph
445
446 if ( isPostingResult( manualRun, postresult ) ){
447 node( testMachineOn ) {
448
449 withCredentials( [
450 string( credentialsId: 'db_pass', variable: 'pass' ),
451 string( credentialsId: 'db_user', variable: 'user' ),
452 string( credentialsId: 'db_host', variable: 'host' ),
453 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
454 sh '''#!/bin/bash
455 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
456 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
457 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
458 save_path ) + '''
459 ''' +
460 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
461 }
462 }
463 postResult( [ ], true )
464 }
465}
466
Jon Hall6af749d2018-05-29 12:59:47 -0700467
Devin Lim61643762017-12-07 15:55:38 -0800468def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700469 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800470
Jon Hall6af749d2018-05-29 12:59:47 -0700471 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
472 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800473
Jon Hall6af749d2018-05-29 12:59:47 -0700474 withCredentials( [
475 string( credentialsId: 'db_pass', variable: 'pass' ),
476 string( credentialsId: 'db_user', variable: 'user' ),
477 string( credentialsId: 'db_host', variable: 'host' ),
478 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
479 testList = generalFuncs.getTestList( testCategory )
480 sh '''#!/bin/bash
481 ''' +
482 generalFuncs.basicGraphPart( trend_generator_file, host, port,
483 user, pass, testType,
484 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
485 }
Devin Lim61643762017-12-07 15:55:38 -0800486 }
Jon Hall6af749d2018-05-29 12:59:47 -0700487 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800488 }
489}
Jon Hall6af749d2018-05-29 12:59:47 -0700490
Devin Lim61643762017-12-07 15:55:38 -0800491def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700492 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700493
Jon Hall6af749d2018-05-29 12:59:47 -0700494 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
495 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800496}
Jon Hall6af749d2018-05-29 12:59:47 -0700497
Devin Lim61643762017-12-07 15:55:38 -0800498def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700499 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700500
Jon Hall6af749d2018-05-29 12:59:47 -0700501 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
502 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800503}
Jon Hall6af749d2018-05-29 12:59:47 -0700504
Devin Lim61643762017-12-07 15:55:38 -0800505def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700506 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700507
Jon Hall6af749d2018-05-29 12:59:47 -0700508 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
509 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800510}
Devin Limf5175192018-05-14 19:13:22 -0700511
Jon Hall6af749d2018-05-29 12:59:47 -0700512def databasePart( wikiPrefix, testName, database_command ){
513 // to read and insert the data from .csv to the database
514
515 return '''
Devin Lim61643762017-12-07 15:55:38 -0800516 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
517 do
518 echo \$line
519 echo ''' + database_command + '''
520 done '''
521}
Jon Hall6af749d2018-05-29 12:59:47 -0700522
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700523def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
Jon Hall6af749d2018-05-29 12:59:47 -0700524 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700525
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700526 // Will generate the stats graph.
527 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
528 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
529 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
530
531 testListParam = "FUNC-" + FUNCtestsStr + ";" +
532 "HA-" + HAtestsStr + ";" +
533 "USECASE-" + USECASEtestsStr
534
535 pieTestListParam = FUNCtestsStr + "," +
536 HAtestsStr + "," +
537 USECASEtestsStr
538
Jon Hall6af749d2018-05-29 12:59:47 -0700539 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700540 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800541}
Jon Hall6af749d2018-05-29 12:59:47 -0700542
Jon Hall6af749d2018-05-29 12:59:47 -0700543return this