blob: 3f805b395109a889d983d2aa7e942c43c41a5396 [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
You Wangaa7bc722019-02-21 17:55:39 -0800243 sudo rm ${WORKSPACE}/*Alarm.txt || true
Devin Lim61643762017-12-07 15:55:38 -0800244 sudo rm ${WORKSPACE}/*.csv
245 #copy files to workspace
246 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700247 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800248 sudo cp *.txt ${WORKSPACE}/
249 sudo cp *.csv ${WORKSPACE}/
250 cd ${WORKSPACE}/
251 for i in *.csv
252 do mv "$i" "$WikiPrefix"-"$i"
253 done
254 ls -al
255 cd '''
256}
Devin Limf5175192018-05-14 19:13:22 -0700257
Jon Hall6af749d2018-05-29 12:59:47 -0700258def fetchLogs( testName ){
259 // fetch the logs of onos from onos nodes to onos System Test logs
260 // testName: name of the test
261
262 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800263 set +e
264 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700265 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800266 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
267 echo "########################################################################################"
268 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
269 echo "########################################################################################"
270 cd $TestONlogDir
271 if [ $? -eq 1 ]
272 then
273 echo "Job name does not match any test suite name to move log!"
274 else
275 pwd
Jon Hall3e6edb32018-08-21 16:20:30 -0700276 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
277 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 -0800278 fi
279 cd'''
280}
Jon Hall6af749d2018-05-29 12:59:47 -0700281
Devin Lim61643762017-12-07 15:55:38 -0800282def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700283 // check if it is posting the result.
284 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700285
Jon Hall6af749d2018-05-29 12:59:47 -0700286 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800287}
Jon Hall6af749d2018-05-29 12:59:47 -0700288
Devin Lim61643762017-12-07 15:55:38 -0800289def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700290 // post the result by triggering postjob.
291 // prop : property dictionary that was read from the machine.
292 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700293
Jon Hall6af749d2018-05-29 12:59:47 -0700294 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
295 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800296 }
Devin Lim61643762017-12-07 15:55:38 -0800297}
Jon Hall6af749d2018-05-29 12:59:47 -0700298
299def postLogs( testName, prefix ){
300 // posting logs of the onos jobs specifically SR tests
301 // testName : name of the test
You Wangdba6c9f2018-12-21 11:58:55 -0800302 // prefix : branch prefix ( master, 2.0, 1.15 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700303
304 resultURL = ""
305 if ( testType == "SR" ){
306 def post = build job: "SR-log-" + prefix, propagate: false
307 resultURL = post.getAbsoluteUrl()
308 }
309 return resultURL
310}
311
312def getSlackChannel(){
313 // get name of the slack channel.
314 // if the test is SR, it will return sr-failures
315
You Wang28cb8552019-02-19 16:11:52 -0800316 // FIXME: For now we move all notifications to #jenkins-related
317 // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
318 return "#jenkins-related"
Jon Hall6af749d2018-05-29 12:59:47 -0700319}
320
Jon Hall8b1e92c2018-06-13 14:07:22 -0700321def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
You Wang28cb8552019-02-19 16:11:52 -0800322 // analyzing the result of the test and send to slack if any abnormal result is logged.
Jon Hall6af749d2018-05-29 12:59:47 -0700323 // prop : property dictionary
324 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700325 // pureTestName : TestON name of the test
326 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700327 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
328 // wikiLink : link of the wiki page where the result was posted
329 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
330
331 node( testMachine ) {
You Wang28cb8552019-02-19 16:11:52 -0800332 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
333 if ( fileExists( alarmFile ) ) {
334 print "Abnormal test result logged"
335 def alarmContents = readFile( alarmFile )
You Wang2dcde682019-02-21 12:18:15 -0800336 slackSend( channel: getSlackChannel(),
337 color: "FF0000",
338 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
339 alarmContents + "\n" +
340 "[TestON log] : \n" +
341 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
342 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
343 "https://wiki.onosproject.org/display/ONOS/" +
344 wikiLink.replaceAll( "\\s", "+" ) ) ) +
345 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
346 resultURL + "artifact/" ) : "" ),
347 teamDomain: 'onosproject' )
Jon Hall6af749d2018-05-29 12:59:47 -0700348 Failed
349 }
You Wang28cb8552019-02-19 16:11:52 -0800350 else {
351 print "Test results are normal"
352 }
Jon Hall6af749d2018-05-29 12:59:47 -0700353 }
354}
355
Devin Lime89761a2018-03-16 17:52:57 -0700356def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700357 // publish HTML script to wiki confluence
358 // isManualRun : string "true" "false"
359 // isPostResult : string "true" "false"
360 // wikiLink : link of the wiki page to publish
361 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700362
Jon Hall6af749d2018-05-29 12:59:47 -0700363 if ( isPostingResult( isManualRun, isPostResult ) ){
364 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
365 attachArchivedArtifacts: true, buildIfUnstable: true,
366 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
367 }
Devin Lim61643762017-12-07 15:55:38 -0800368
369}
Devin Limf5175192018-05-14 19:13:22 -0700370
Jon Hall6af749d2018-05-29 12:59:47 -0700371def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
372 graph_saved_directory ){
373 // 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 -0700374 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700375 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
376 // result on pipeline view
377 // prop : dictionary property on the machine
378 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
379 // 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 -0700380 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700381 // graph_generator_file : Rscript file with the full path.
382 // graph_saved_directory : where the generated graph will be saved to.
383
384 return {
385 catchError {
386 stage( testName ) {
387 if ( toBeRun ){
388 def workSpace = "/var/jenkins/workspace/" + testName
389 def fileContents = ""
390 node( testMachine ) {
391 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
You Wang8e4f4c02019-01-03 10:49:46 -0800392 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
Jon Hall6af749d2018-05-29 12:59:47 -0700393 'TestONBranch=' + prop[ "TestONBranch" ],
394 'ONOSTag=' + prop[ "ONOSTag" ],
395 'WikiPrefix=' + prop[ "WikiPrefix" ],
396 'WORKSPACE=' + workSpace ] ) {
397 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700398 if ( isSCPF ){
399 // Remove the old database file
400 sh SCPFfunc.cleanupDatabaseFile( testName )
401 }
Jon Hall6af749d2018-05-29 12:59:47 -0700402 sh initAndRunTest( testName, testCategory )
403 // For the Wiki page
404 sh cleanAndCopyFiles( pureTestName )
405 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700406 databaseAndGraph( prop, testName, pureTestName, graphOnly,
407 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700408 if ( !graphOnly ){
409 sh fetchLogs( pureTestName )
410 if ( !isSCPF ){
411 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
412 testCategory[ testName ][ 'wiki_link' ],
413 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
414 }
415 }
Devin Lim61643762017-12-07 15:55:38 -0800416 }
Jon Hall6af749d2018-05-29 12:59:47 -0700417 }
Devin Lim61643762017-12-07 15:55:38 -0800418 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700419 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700420 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700421 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
422 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
423 isSCPF )
424 }
425 }
426 }
427 }
428 }
Devin Lim61643762017-12-07 15:55:38 -0800429}
Devin Limf5175192018-05-14 19:13:22 -0700430
Jon Hall8b1e92c2018-06-13 14:07:22 -0700431def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700432 // part where it insert the data into the database.
433 // It will use the predefined encrypted variables from the Jenkins.
434 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700435 // testName : Jenkins name for the test
436 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700437 // graphOnly : boolean whether it is graph only or not
438 // graph_generator_file : Rscript file with the full path.
439 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700440 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
441 // Post Results
442 withCredentials( [
443 string( credentialsId: 'db_pass', variable: 'pass' ),
444 string( credentialsId: 'db_user', variable: 'user' ),
445 string( credentialsId: 'db_host', variable: 'host' ),
446 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
447 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
448 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
449 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800450 export DATE=\$(date +%F_%T)
451 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700452 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700453 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700454 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
455 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
456 graph_generator_file ) :
457 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800458 }
Devin Lim61643762017-12-07 15:55:38 -0800459 }
460}
Jon Hall6af749d2018-05-29 12:59:47 -0700461
462def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
463 save_path, pieTestListPart ){
464 // function that will generate the category stat graphs for the overall test.
465 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
466 // manualRun : string of "true" or "false"
467 // postresult : string of "true" or "false"
468 // stat_file : file name with full path for Rscript for the stat graph
469 // pie_file : file name with full path for Rscript for the pie graph
470 // type : type of the test ( USECASE, FUNC, HA )
You Wangdba6c9f2018-12-21 11:58:55 -0800471 // branch : branch of the test ( master, onos-2.0, onos-1.15 )
Jon Hall6af749d2018-05-29 12:59:47 -0700472 // testListPart : list of the test to be included
473 // save_path : path that will save the graphs to
474 // pieTestListPart : list of the test for pie graph
475
476 if ( isPostingResult( manualRun, postresult ) ){
477 node( testMachineOn ) {
478
479 withCredentials( [
480 string( credentialsId: 'db_pass', variable: 'pass' ),
481 string( credentialsId: 'db_user', variable: 'user' ),
482 string( credentialsId: 'db_host', variable: 'host' ),
483 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
484 sh '''#!/bin/bash
485 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
486 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
487 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
488 save_path ) + '''
489 ''' +
490 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
491 }
492 }
493 postResult( [ ], true )
494 }
495}
496
Devin Lim61643762017-12-07 15:55:38 -0800497def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700498 // make the list of the test in to a string.
499 // list : list of the test
500 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700501
Jon Hall6af749d2018-05-29 12:59:47 -0700502 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800503}
Jon Hall6af749d2018-05-29 12:59:47 -0700504
Devin Lim61643762017-12-07 15:55:38 -0800505def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700506 // make the list for stats
507 // testCategory : category of the test
508 // list : list of the test
509 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700510
Jon Hall6af749d2018-05-29 12:59:47 -0700511 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800512}
Jon Hall6af749d2018-05-29 12:59:47 -0700513
Devin Lim61643762017-12-07 15:55:38 -0800514def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700515 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800516
Jon Hall6af749d2018-05-29 12:59:47 -0700517 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
518 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800519
Jon Hall6af749d2018-05-29 12:59:47 -0700520 withCredentials( [
521 string( credentialsId: 'db_pass', variable: 'pass' ),
522 string( credentialsId: 'db_user', variable: 'user' ),
523 string( credentialsId: 'db_host', variable: 'host' ),
524 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
525 testList = generalFuncs.getTestList( testCategory )
526 sh '''#!/bin/bash
527 ''' +
528 generalFuncs.basicGraphPart( trend_generator_file, host, port,
529 user, pass, testType,
530 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
531 }
Devin Lim61643762017-12-07 15:55:38 -0800532 }
Jon Hall6af749d2018-05-29 12:59:47 -0700533 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800534 }
535}
Jon Hall6af749d2018-05-29 12:59:47 -0700536
Devin Lim61643762017-12-07 15:55:38 -0800537def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700538 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700539
Jon Hall6af749d2018-05-29 12:59:47 -0700540 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
541 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800542}
Jon Hall6af749d2018-05-29 12:59:47 -0700543
Devin Lim61643762017-12-07 15:55:38 -0800544def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700545 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700546
Jon Hall6af749d2018-05-29 12:59:47 -0700547 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
548 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800549}
Jon Hall6af749d2018-05-29 12:59:47 -0700550
Devin Lim61643762017-12-07 15:55:38 -0800551def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700552 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700553
Jon Hall6af749d2018-05-29 12:59:47 -0700554 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
555 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800556}
Devin Limf5175192018-05-14 19:13:22 -0700557
Jon Hall6af749d2018-05-29 12:59:47 -0700558def databasePart( wikiPrefix, testName, database_command ){
559 // to read and insert the data from .csv to the database
560
561 return '''
Devin Lim61643762017-12-07 15:55:38 -0800562 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
563 do
564 echo \$line
565 echo ''' + database_command + '''
566 done '''
567}
Jon Hall6af749d2018-05-29 12:59:47 -0700568
569def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
570 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700571 // Will generate the stats graph.
572
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800573 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
574 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
575 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
576 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
577 makeTestList( AllTheTests[ "HA" ], true ) +
578 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700579 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
580 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800581}
Jon Hall6af749d2018-05-29 12:59:47 -0700582
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700583def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700584 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700585 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
586}
Jon Hall6af749d2018-05-29 12:59:47 -0700587
You Wangfe3877b2018-08-02 11:48:35 -0700588def testBranchWithPrefix( branch ){
589 // get TestON branch with the prefix ( "onos-" )
You Wang8f12d7d2018-11-09 13:47:23 -0800590 if ( branch == "1.12" )
You Wangfe3877b2018-08-02 11:48:35 -0700591 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800592 else if ( branch == "1.13" )
You Wangfe3877b2018-08-02 11:48:35 -0700593 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800594 else if ( branch == "1.14" )
You Wangda4b1442018-11-29 12:31:22 -0800595 return "onos-1.15"
You Wang8f12d7d2018-11-09 13:47:23 -0800596 else if ( branch == "1.15" )
You Wangda4b1442018-11-29 12:31:22 -0800597 return "onos-1.15"
You Wangdba6c9f2018-12-21 11:58:55 -0800598 else if ( branch == "2.0" )
599 return "master"
You Wangfe3877b2018-08-02 11:48:35 -0700600 else
601 return "master"
602}
603
Jon Hall6af749d2018-05-29 12:59:47 -0700604return this