blob: 36d0e1c209d74cc50a6bac2d72383740c114890c [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.
You Wangdba6c9f2018-12-21 11:58:55 -080086 // branch : branch of the onos. ( master, 2.0, 1.15... )
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.
You Wangdba6c9f2018-12-21 11:58:55 -0800101 // branch : master, 2.0, 1.15...
Jon Hall6af749d2018-05-29 12:59:47 -0700102 // branch.reverse().take(4).reverse() will get last 4 characters of the string.
You Wangdba6c9f2018-12-21 11:58:55 -0800103 switch ( branch.reverse().take( 3 ).reverse() ){
104 case "ter": return "4"
105 case "2.0": return "3"
106 case ".15": return "2"
107 case ".14": return "3"
108 case ".13": return "2"
109 case ".12": return "3"
Jon Hall6af749d2018-05-29 12:59:47 -0700110 default: return "4"
111 }
112}
113
114def printType(){
115 // print the test type and test machine that was initialized.
116
117 echo testType
118 echo testMachine
119}
120
121def getProperties(){
122 // get the properties of the test by reading the TestONOS.property
123
124 node( testMachine ) {
125 return readProperties( file: '/var/jenkins/TestONOS.property' )
126 }
127}
128
129def getTestsToRun( testList ){
130 // get test to run by tokenizing the list.
131
132 testList.tokenize( "\n;, " )
133}
134
135def getCurrentTime(){
136 // get time of the PST zone.
137
138 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
139 return new Date()
140}
141
142def getTotalTime( start, end ){
143 // get total time of the test using start and end time.
144
145 return TimeCategory.minus( end, start )
146}
147
148def printTestToRun( testList ){
149 // printout the list of the test in the list.
150
151 for ( String test : testList ){
152 println test
153 }
154}
155
156def sendResultToSlack( start, isManualRun, branch ){
157 // send the result of the test to the slack when it is not manually running.
158 // start : start time of the test
159 // isManualRun : string that is whether "false" or "true"
160 // branch : branch of the onos.
161
162 try {
163 if ( isManualRun == "false" ){
164 end = getCurrentTime()
165 TimeDuration duration = TimeCategory.minus( end, start )
You Wang28cb8552019-02-19 16:11:52 -0800166 // FIXME: for now we disable notifications of normal test results
167 /*
Jon Hall6af749d2018-05-29 12:59:47 -0700168 slackSend( color: "#5816EE",
169 message: testType + "-" + branch + " tests ended at: " + end.toString() +
170 "\nTime took : " + duration )
You Wang28cb8552019-02-19 16:11:52 -0800171 */
Jon Hall6af749d2018-05-29 12:59:47 -0700172 }
173 }
174 catch ( all ){
175 }
176}
177
178def initAndRunTest( testName, testCategory ){
179 // Bash script that will
180 // Initialize the environment to the machine and run the test.
181 // testName : name of the test
182 // testCategory : (SR,FUNC ... )
183
184 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800185 set -i # interactive
186 set +e
187 shopt -s expand_aliases # expand alias in non-interactive mode
188 export PYTHONUNBUFFERED=1
189 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800190 echo "ONOS Branch is: $ONOSBranch"
191 echo "TestON Branch is: $TestONBranch"
192 echo "Test date: "
193 date
194 cd ~
195 export PATH=$PATH:onos/tools/test/bin
196 timeout 240 stc shutdown | head -100
197 timeout 240 stc teardown | head -100
198 timeout 240 stc shutdown | head -100
199 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700200 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800201 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700202 ''' + "./cli.py run " +
Jon Hall2ee92f82018-06-07 13:07:33 -0700203 ( !hasArgs ? testName : testCategory[ testName ][ 'test' ] ) +
Jon Hall6af749d2018-05-29 12:59:47 -0700204 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800205 ./cleanup.sh -f
206 # cleanup config changes
207 cd ~/onos/tools/package/config
208 git clean -df'''
209}
Devin Limf5175192018-05-14 19:13:22 -0700210
Jon Hall8b1e92c2018-06-13 14:07:22 -0700211def copyLogs(){
212 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700213
214 result = ""
215 if ( testType == "SR" ){
216 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800217 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
218 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
219 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
220 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700221 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700222 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800223 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700224 }
225 return result
Devin Lim61643762017-12-07 15:55:38 -0800226}
Devin Limf5175192018-05-14 19:13:22 -0700227
Jon Hall6af749d2018-05-29 12:59:47 -0700228def cleanAndCopyFiles( testName ){
229 // clean up some files that were in the folder and copy the new files from the log
230 // testName : name of the test
231
232 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800233 set +e
234 echo "ONOS Branch is: ${ONOSBranch}"
235 echo "TestON Branch is: ${TestONBranch}"
236 echo "Job name is: "''' + testName + '''
237 echo "Workspace is: ${WORKSPACE}/"
238 echo "Wiki page to post is: ${WikiPrefix}-"
239 # remove any leftover files from previous tests
240 sudo rm ${WORKSPACE}/*Wiki.txt
241 sudo rm ${WORKSPACE}/*Summary.txt
242 sudo rm ${WORKSPACE}/*Result.txt
243 sudo rm ${WORKSPACE}/*.csv
244 #copy files to workspace
245 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700246 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800247 sudo cp *.txt ${WORKSPACE}/
248 sudo cp *.csv ${WORKSPACE}/
249 cd ${WORKSPACE}/
250 for i in *.csv
251 do mv "$i" "$WikiPrefix"-"$i"
252 done
253 ls -al
254 cd '''
255}
Devin Limf5175192018-05-14 19:13:22 -0700256
Jon Hall6af749d2018-05-29 12:59:47 -0700257def fetchLogs( testName ){
258 // fetch the logs of onos from onos nodes to onos System Test logs
259 // testName: name of the test
260
261 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800262 set +e
263 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700264 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800265 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
266 echo "########################################################################################"
267 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
268 echo "########################################################################################"
269 cd $TestONlogDir
270 if [ $? -eq 1 ]
271 then
272 echo "Job name does not match any test suite name to move log!"
273 else
274 pwd
Jon Hall3e6edb32018-08-21 16:20:30 -0700275 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
276 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 -0800277 fi
278 cd'''
279}
Jon Hall6af749d2018-05-29 12:59:47 -0700280
Devin Lim61643762017-12-07 15:55:38 -0800281def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700282 // check if it is posting the result.
283 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700284
Jon Hall6af749d2018-05-29 12:59:47 -0700285 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800286}
Jon Hall6af749d2018-05-29 12:59:47 -0700287
Devin Lim61643762017-12-07 15:55:38 -0800288def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700289 // post the result by triggering postjob.
290 // prop : property dictionary that was read from the machine.
291 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700292
Jon Hall6af749d2018-05-29 12:59:47 -0700293 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
294 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800295 }
Devin Lim61643762017-12-07 15:55:38 -0800296}
Jon Hall6af749d2018-05-29 12:59:47 -0700297
298def postLogs( testName, prefix ){
299 // posting logs of the onos jobs specifically SR tests
300 // testName : name of the test
You Wangdba6c9f2018-12-21 11:58:55 -0800301 // prefix : branch prefix ( master, 2.0, 1.15 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700302
303 resultURL = ""
304 if ( testType == "SR" ){
305 def post = build job: "SR-log-" + prefix, propagate: false
306 resultURL = post.getAbsoluteUrl()
307 }
308 return resultURL
309}
310
311def getSlackChannel(){
312 // get name of the slack channel.
313 // if the test is SR, it will return sr-failures
314
You Wang28cb8552019-02-19 16:11:52 -0800315 // FIXME: For now we move all notifications to #jenkins-related
316 // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
317 return "#jenkins-related"
Jon Hall6af749d2018-05-29 12:59:47 -0700318}
319
Jon Hall8b1e92c2018-06-13 14:07:22 -0700320def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
You Wang28cb8552019-02-19 16:11:52 -0800321 // analyzing the result of the test and send to slack if any abnormal result is logged.
Jon Hall6af749d2018-05-29 12:59:47 -0700322 // prop : property dictionary
323 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700324 // pureTestName : TestON name of the test
325 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700326 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
327 // wikiLink : link of the wiki page where the result was posted
328 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
329
330 node( testMachine ) {
You Wang28cb8552019-02-19 16:11:52 -0800331 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
332 if ( fileExists( alarmFile ) ) {
333 print "Abnormal test result logged"
334 def alarmContents = readFile( alarmFile )
You Wang2dcde682019-02-21 12:18:15 -0800335 slackSend( channel: getSlackChannel(),
336 color: "FF0000",
337 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
338 alarmContents + "\n" +
339 "[TestON log] : \n" +
340 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
341 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
342 "https://wiki.onosproject.org/display/ONOS/" +
343 wikiLink.replaceAll( "\\s", "+" ) ) ) +
344 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
345 resultURL + "artifact/" ) : "" ),
346 teamDomain: 'onosproject' )
Jon Hall6af749d2018-05-29 12:59:47 -0700347 Failed
348 }
You Wang28cb8552019-02-19 16:11:52 -0800349 else {
350 print "Test results are normal"
351 }
Jon Hall6af749d2018-05-29 12:59:47 -0700352 }
353}
354
Devin Lime89761a2018-03-16 17:52:57 -0700355def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700356 // publish HTML script to wiki confluence
357 // isManualRun : string "true" "false"
358 // isPostResult : string "true" "false"
359 // wikiLink : link of the wiki page to publish
360 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700361
Jon Hall6af749d2018-05-29 12:59:47 -0700362 if ( isPostingResult( isManualRun, isPostResult ) ){
363 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
364 attachArchivedArtifacts: true, buildIfUnstable: true,
365 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
366 }
Devin Lim61643762017-12-07 15:55:38 -0800367
368}
Devin Limf5175192018-05-14 19:13:22 -0700369
Jon Hall6af749d2018-05-29 12:59:47 -0700370def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
371 graph_saved_directory ){
372 // 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 -0700373 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700374 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
375 // result on pipeline view
376 // prop : dictionary property on the machine
377 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
378 // 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 -0700379 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700380 // graph_generator_file : Rscript file with the full path.
381 // graph_saved_directory : where the generated graph will be saved to.
382
383 return {
384 catchError {
385 stage( testName ) {
386 if ( toBeRun ){
387 def workSpace = "/var/jenkins/workspace/" + testName
388 def fileContents = ""
389 node( testMachine ) {
390 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
You Wang8e4f4c02019-01-03 10:49:46 -0800391 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
Jon Hall6af749d2018-05-29 12:59:47 -0700392 'TestONBranch=' + prop[ "TestONBranch" ],
393 'ONOSTag=' + prop[ "ONOSTag" ],
394 'WikiPrefix=' + prop[ "WikiPrefix" ],
395 'WORKSPACE=' + workSpace ] ) {
396 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700397 if ( isSCPF ){
398 // Remove the old database file
399 sh SCPFfunc.cleanupDatabaseFile( testName )
400 }
Jon Hall6af749d2018-05-29 12:59:47 -0700401 sh initAndRunTest( testName, testCategory )
402 // For the Wiki page
403 sh cleanAndCopyFiles( pureTestName )
404 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700405 databaseAndGraph( prop, testName, pureTestName, graphOnly,
406 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700407 if ( !graphOnly ){
408 sh fetchLogs( pureTestName )
409 if ( !isSCPF ){
410 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
411 testCategory[ testName ][ 'wiki_link' ],
412 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
413 }
414 }
Devin Lim61643762017-12-07 15:55:38 -0800415 }
Jon Hall6af749d2018-05-29 12:59:47 -0700416 }
Devin Lim61643762017-12-07 15:55:38 -0800417 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700418 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700419 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700420 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
421 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
422 isSCPF )
423 }
424 }
425 }
426 }
427 }
Devin Lim61643762017-12-07 15:55:38 -0800428}
Devin Limf5175192018-05-14 19:13:22 -0700429
Jon Hall8b1e92c2018-06-13 14:07:22 -0700430def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700431 // part where it insert the data into the database.
432 // It will use the predefined encrypted variables from the Jenkins.
433 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700434 // testName : Jenkins name for the test
435 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700436 // graphOnly : boolean whether it is graph only or not
437 // graph_generator_file : Rscript file with the full path.
438 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700439 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
440 // Post Results
441 withCredentials( [
442 string( credentialsId: 'db_pass', variable: 'pass' ),
443 string( credentialsId: 'db_user', variable: 'user' ),
444 string( credentialsId: 'db_host', variable: 'host' ),
445 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
446 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
447 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
448 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800449 export DATE=\$(date +%F_%T)
450 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700451 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700452 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700453 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
454 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
455 graph_generator_file ) :
456 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800457 }
Devin Lim61643762017-12-07 15:55:38 -0800458 }
459}
Jon Hall6af749d2018-05-29 12:59:47 -0700460
461def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
462 save_path, pieTestListPart ){
463 // function that will generate the category stat graphs for the overall test.
464 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
465 // manualRun : string of "true" or "false"
466 // postresult : string of "true" or "false"
467 // stat_file : file name with full path for Rscript for the stat graph
468 // pie_file : file name with full path for Rscript for the pie graph
469 // type : type of the test ( USECASE, FUNC, HA )
You Wangdba6c9f2018-12-21 11:58:55 -0800470 // branch : branch of the test ( master, onos-2.0, onos-1.15 )
Jon Hall6af749d2018-05-29 12:59:47 -0700471 // testListPart : list of the test to be included
472 // save_path : path that will save the graphs to
473 // pieTestListPart : list of the test for pie graph
474
475 if ( isPostingResult( manualRun, postresult ) ){
476 node( testMachineOn ) {
477
478 withCredentials( [
479 string( credentialsId: 'db_pass', variable: 'pass' ),
480 string( credentialsId: 'db_user', variable: 'user' ),
481 string( credentialsId: 'db_host', variable: 'host' ),
482 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
483 sh '''#!/bin/bash
484 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
485 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
486 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
487 save_path ) + '''
488 ''' +
489 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
490 }
491 }
492 postResult( [ ], true )
493 }
494}
495
Devin Lim61643762017-12-07 15:55:38 -0800496def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700497 // make the list of the test in to a string.
498 // list : list of the test
499 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700500
Jon Hall6af749d2018-05-29 12:59:47 -0700501 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800502}
Jon Hall6af749d2018-05-29 12:59:47 -0700503
Devin Lim61643762017-12-07 15:55:38 -0800504def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700505 // make the list for stats
506 // testCategory : category of the test
507 // list : list of the test
508 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700509
Jon Hall6af749d2018-05-29 12:59:47 -0700510 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800511}
Jon Hall6af749d2018-05-29 12:59:47 -0700512
Devin Lim61643762017-12-07 15:55:38 -0800513def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700514 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800515
Jon Hall6af749d2018-05-29 12:59:47 -0700516 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
517 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800518
Jon Hall6af749d2018-05-29 12:59:47 -0700519 withCredentials( [
520 string( credentialsId: 'db_pass', variable: 'pass' ),
521 string( credentialsId: 'db_user', variable: 'user' ),
522 string( credentialsId: 'db_host', variable: 'host' ),
523 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
524 testList = generalFuncs.getTestList( testCategory )
525 sh '''#!/bin/bash
526 ''' +
527 generalFuncs.basicGraphPart( trend_generator_file, host, port,
528 user, pass, testType,
529 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
530 }
Devin Lim61643762017-12-07 15:55:38 -0800531 }
Jon Hall6af749d2018-05-29 12:59:47 -0700532 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800533 }
534}
Jon Hall6af749d2018-05-29 12:59:47 -0700535
Devin Lim61643762017-12-07 15:55:38 -0800536def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700537 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700538
Jon Hall6af749d2018-05-29 12:59:47 -0700539 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
540 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800541}
Jon Hall6af749d2018-05-29 12:59:47 -0700542
Devin Lim61643762017-12-07 15:55:38 -0800543def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700544 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700545
Jon Hall6af749d2018-05-29 12:59:47 -0700546 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
547 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800548}
Jon Hall6af749d2018-05-29 12:59:47 -0700549
Devin Lim61643762017-12-07 15:55:38 -0800550def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700551 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700552
Jon Hall6af749d2018-05-29 12:59:47 -0700553 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
554 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800555}
Devin Limf5175192018-05-14 19:13:22 -0700556
Jon Hall6af749d2018-05-29 12:59:47 -0700557def databasePart( wikiPrefix, testName, database_command ){
558 // to read and insert the data from .csv to the database
559
560 return '''
Devin Lim61643762017-12-07 15:55:38 -0800561 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
562 do
563 echo \$line
564 echo ''' + database_command + '''
565 done '''
566}
Jon Hall6af749d2018-05-29 12:59:47 -0700567
568def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
569 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700570 // Will generate the stats graph.
571
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800572 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
573 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
574 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
575 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
576 makeTestList( AllTheTests[ "HA" ], true ) +
577 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700578 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
579 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800580}
Jon Hall6af749d2018-05-29 12:59:47 -0700581
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700582def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700583 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700584 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
585}
Jon Hall6af749d2018-05-29 12:59:47 -0700586
You Wangfe3877b2018-08-02 11:48:35 -0700587def testBranchWithPrefix( branch ){
588 // get TestON branch with the prefix ( "onos-" )
You Wang8f12d7d2018-11-09 13:47:23 -0800589 if ( branch == "1.12" )
You Wangfe3877b2018-08-02 11:48:35 -0700590 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800591 else if ( branch == "1.13" )
You Wangfe3877b2018-08-02 11:48:35 -0700592 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800593 else if ( branch == "1.14" )
You Wangda4b1442018-11-29 12:31:22 -0800594 return "onos-1.15"
You Wang8f12d7d2018-11-09 13:47:23 -0800595 else if ( branch == "1.15" )
You Wangda4b1442018-11-29 12:31:22 -0800596 return "onos-1.15"
You Wangdba6c9f2018-12-21 11:58:55 -0800597 else if ( branch == "2.0" )
598 return "master"
You Wangfe3877b2018-08-02 11:48:35 -0700599 else
600 return "master"
601}
602
Jon Hall6af749d2018-05-29 12:59:47 -0700603return this