blob: b3948b467b8f4a9ebfcd0fbb11ebf049456b1437 [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 Wang8f12d7d2018-11-09 13:47:23 -080086 // branch : branch of the onos. ( master, 1.15, 1.14... )
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 Wang8f12d7d2018-11-09 13:47:23 -0800101 // branch : master, 1.15, 1.14...
Jon Hall6af749d2018-05-29 12:59:47 -0700102 // branch.reverse().take(4).reverse() will get last 4 characters of the string.
103 switch ( branch.reverse().take( 4 ).reverse() ){
104 case "ster": return "4"
You Wang8f12d7d2018-11-09 13:47:23 -0800105 case "1.15": return "2"
You Wang5cf67da2018-08-20 15:06:46 -0700106 case "1.14": return "3"
You Wang8f12d7d2018-11-09 13:47:23 -0800107 case "1.13": return "2"
Jon Hall6af749d2018-05-29 12:59:47 -0700108 case "1.12": return "3"
109 default: return "4"
110 }
111}
112
113def printType(){
114 // print the test type and test machine that was initialized.
115
116 echo testType
117 echo testMachine
118}
119
120def getProperties(){
121 // get the properties of the test by reading the TestONOS.property
122
123 node( testMachine ) {
124 return readProperties( file: '/var/jenkins/TestONOS.property' )
125 }
126}
127
128def getTestsToRun( testList ){
129 // get test to run by tokenizing the list.
130
131 testList.tokenize( "\n;, " )
132}
133
134def getCurrentTime(){
135 // get time of the PST zone.
136
137 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
138 return new Date()
139}
140
141def getTotalTime( start, end ){
142 // get total time of the test using start and end time.
143
144 return TimeCategory.minus( end, start )
145}
146
147def printTestToRun( testList ){
148 // printout the list of the test in the list.
149
150 for ( String test : testList ){
151 println test
152 }
153}
154
155def sendResultToSlack( start, isManualRun, branch ){
156 // send the result of the test to the slack when it is not manually running.
157 // start : start time of the test
158 // isManualRun : string that is whether "false" or "true"
159 // branch : branch of the onos.
160
161 try {
162 if ( isManualRun == "false" ){
163 end = getCurrentTime()
164 TimeDuration duration = TimeCategory.minus( end, start )
You Wang03d90e72019-02-19 16:11:52 -0800165 // FIXME: for now we disable notifications of normal test results
166 /*
Jon Hall6af749d2018-05-29 12:59:47 -0700167 slackSend( color: "#5816EE",
168 message: testType + "-" + branch + " tests ended at: " + end.toString() +
169 "\nTime took : " + duration )
You Wang03d90e72019-02-19 16:11:52 -0800170 */
Jon Hall6af749d2018-05-29 12:59:47 -0700171 }
172 }
173 catch ( all ){
174 }
175}
176
177def initAndRunTest( testName, testCategory ){
178 // Bash script that will
179 // Initialize the environment to the machine and run the test.
180 // testName : name of the test
181 // testCategory : (SR,FUNC ... )
182
183 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800184 set -i # interactive
185 set +e
186 shopt -s expand_aliases # expand alias in non-interactive mode
187 export PYTHONUNBUFFERED=1
188 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800189 echo "ONOS Branch is: $ONOSBranch"
190 echo "TestON Branch is: $TestONBranch"
191 echo "Test date: "
192 date
193 cd ~
194 export PATH=$PATH:onos/tools/test/bin
195 timeout 240 stc shutdown | head -100
196 timeout 240 stc teardown | head -100
197 timeout 240 stc shutdown | head -100
198 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700199 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800200 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700201 ''' + "./cli.py run " +
Jon Hall2ee92f82018-06-07 13:07:33 -0700202 ( !hasArgs ? testName : testCategory[ testName ][ 'test' ] ) +
Jon Hall6af749d2018-05-29 12:59:47 -0700203 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800204 ./cleanup.sh -f
205 # cleanup config changes
206 cd ~/onos/tools/package/config
207 git clean -df'''
208}
Devin Limf5175192018-05-14 19:13:22 -0700209
Jon Hall8b1e92c2018-06-13 14:07:22 -0700210def copyLogs(){
211 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700212
213 result = ""
214 if ( testType == "SR" ){
215 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800216 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
217 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
218 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
219 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700220 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700221 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800222 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700223 }
224 return result
Devin Lim61643762017-12-07 15:55:38 -0800225}
Devin Limf5175192018-05-14 19:13:22 -0700226
Jon Hall6af749d2018-05-29 12:59:47 -0700227def cleanAndCopyFiles( testName ){
228 // clean up some files that were in the folder and copy the new files from the log
229 // testName : name of the test
230
231 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800232 set +e
233 echo "ONOS Branch is: ${ONOSBranch}"
234 echo "TestON Branch is: ${TestONBranch}"
235 echo "Job name is: "''' + testName + '''
236 echo "Workspace is: ${WORKSPACE}/"
237 echo "Wiki page to post is: ${WikiPrefix}-"
238 # remove any leftover files from previous tests
239 sudo rm ${WORKSPACE}/*Wiki.txt
240 sudo rm ${WORKSPACE}/*Summary.txt
241 sudo rm ${WORKSPACE}/*Result.txt
You Wang54f58722019-02-21 15:38:26 -0800242 sudo rm ${WORKSPACE}/*Alarm.txt
Devin Lim61643762017-12-07 15:55:38 -0800243 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 Wang8f12d7d2018-11-09 13:47:23 -0800301 // prefix : branch prefix ( master, 1.15, 1.14 ... )
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 Wang03d90e72019-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 Wang03d90e72019-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 Wang03d90e72019-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 )
Jon Hall6af749d2018-05-29 12:59:47 -0700335 if ( prop[ "manualRun" ] == "false" ){
336 slackSend( channel: getSlackChannel(),
337 color: "FF0000",
You Wang03d90e72019-02-19 16:11:52 -0800338 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
339 alarmContents + "\n" +
Jon Hall6af749d2018-05-29 12:59:47 -0700340 "[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' )
348 }
349 Failed
350 }
You Wang03d90e72019-02-19 16:11:52 -0800351 else {
352 print "Test results are normal"
353 }
Jon Hall6af749d2018-05-29 12:59:47 -0700354 }
355}
356
Devin Lime89761a2018-03-16 17:52:57 -0700357def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700358 // publish HTML script to wiki confluence
359 // isManualRun : string "true" "false"
360 // isPostResult : string "true" "false"
361 // wikiLink : link of the wiki page to publish
362 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700363
Jon Hall6af749d2018-05-29 12:59:47 -0700364 if ( isPostingResult( isManualRun, isPostResult ) ){
365 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
366 attachArchivedArtifacts: true, buildIfUnstable: true,
367 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
368 }
Devin Lim61643762017-12-07 15:55:38 -0800369
370}
Devin Limf5175192018-05-14 19:13:22 -0700371
Jon Hall6af749d2018-05-29 12:59:47 -0700372def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
373 graph_saved_directory ){
374 // 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 -0700375 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700376 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
377 // result on pipeline view
378 // prop : dictionary property on the machine
379 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
380 // 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 -0700381 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700382 // graph_generator_file : Rscript file with the full path.
383 // graph_saved_directory : where the generated graph will be saved to.
384
385 return {
386 catchError {
387 stage( testName ) {
388 if ( toBeRun ){
389 def workSpace = "/var/jenkins/workspace/" + testName
390 def fileContents = ""
391 node( testMachine ) {
392 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
393 'ONOSJVMHeap=' + prop[ "ONOSJVMHeap" ],
394 'TestONBranch=' + prop[ "TestONBranch" ],
395 'ONOSTag=' + prop[ "ONOSTag" ],
396 'WikiPrefix=' + prop[ "WikiPrefix" ],
397 'WORKSPACE=' + workSpace ] ) {
398 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700399 if ( isSCPF ){
400 // Remove the old database file
401 sh SCPFfunc.cleanupDatabaseFile( testName )
402 }
Jon Hall6af749d2018-05-29 12:59:47 -0700403 sh initAndRunTest( testName, testCategory )
404 // For the Wiki page
405 sh cleanAndCopyFiles( pureTestName )
406 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700407 databaseAndGraph( prop, testName, pureTestName, graphOnly,
408 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700409 if ( !graphOnly ){
410 sh fetchLogs( pureTestName )
411 if ( !isSCPF ){
412 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
413 testCategory[ testName ][ 'wiki_link' ],
414 workSpace + "/" + testCategory[ testName ][ 'wiki_file' ] )
415 }
416 }
Devin Lim61643762017-12-07 15:55:38 -0800417 }
Jon Hall6af749d2018-05-29 12:59:47 -0700418 }
Devin Lim61643762017-12-07 15:55:38 -0800419 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700420 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700421 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700422 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
423 isSCPF ? "" : testCategory[ testName ][ 'wiki_link' ],
424 isSCPF )
425 }
426 }
427 }
428 }
429 }
Devin Lim61643762017-12-07 15:55:38 -0800430}
Devin Limf5175192018-05-14 19:13:22 -0700431
Jon Hall8b1e92c2018-06-13 14:07:22 -0700432def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700433 // part where it insert the data into the database.
434 // It will use the predefined encrypted variables from the Jenkins.
435 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700436 // testName : Jenkins name for the test
437 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700438 // graphOnly : boolean whether it is graph only or not
439 // graph_generator_file : Rscript file with the full path.
440 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700441 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
442 // Post Results
443 withCredentials( [
444 string( credentialsId: 'db_pass', variable: 'pass' ),
445 string( credentialsId: 'db_user', variable: 'user' ),
446 string( credentialsId: 'db_host', variable: 'host' ),
447 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
448 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
449 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
450 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800451 export DATE=\$(date +%F_%T)
452 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700453 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700454 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700455 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
456 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
457 graph_generator_file ) :
458 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800459 }
Devin Lim61643762017-12-07 15:55:38 -0800460 }
461}
Jon Hall6af749d2018-05-29 12:59:47 -0700462
463def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
464 save_path, pieTestListPart ){
465 // function that will generate the category stat graphs for the overall test.
466 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
467 // manualRun : string of "true" or "false"
468 // postresult : string of "true" or "false"
469 // stat_file : file name with full path for Rscript for the stat graph
470 // pie_file : file name with full path for Rscript for the pie graph
471 // type : type of the test ( USECASE, FUNC, HA )
You Wang8f12d7d2018-11-09 13:47:23 -0800472 // branch : branch of the test ( master, onos-1.15, onos-1.14 )
Jon Hall6af749d2018-05-29 12:59:47 -0700473 // testListPart : list of the test to be included
474 // save_path : path that will save the graphs to
475 // pieTestListPart : list of the test for pie graph
476
477 if ( isPostingResult( manualRun, postresult ) ){
478 node( testMachineOn ) {
479
480 withCredentials( [
481 string( credentialsId: 'db_pass', variable: 'pass' ),
482 string( credentialsId: 'db_user', variable: 'user' ),
483 string( credentialsId: 'db_host', variable: 'host' ),
484 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
485 sh '''#!/bin/bash
486 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
487 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
488 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
489 save_path ) + '''
490 ''' +
491 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
492 }
493 }
494 postResult( [ ], true )
495 }
496}
497
Devin Lim61643762017-12-07 15:55:38 -0800498def makeTestList( list, commaNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700499 // make the list of the test in to a string.
500 // list : list of the test
501 // commaNeeded : if comma is needed for the string
Devin Limf5175192018-05-14 19:13:22 -0700502
Jon Hall6af749d2018-05-29 12:59:47 -0700503 return generalFuncs.getTestList( list ) + ( commaNeeded ? "," : "" )
Devin Lim61643762017-12-07 15:55:38 -0800504}
Jon Hall6af749d2018-05-29 12:59:47 -0700505
Devin Lim61643762017-12-07 15:55:38 -0800506def createStatsList( testCategory, list, semiNeeded ){
Jon Hall6af749d2018-05-29 12:59:47 -0700507 // make the list for stats
508 // testCategory : category of the test
509 // list : list of the test
510 // semiNeeded: if semi colon is needed
Devin Limf5175192018-05-14 19:13:22 -0700511
Jon Hall6af749d2018-05-29 12:59:47 -0700512 return testCategory + "-" + generalFuncs.getTestList( list ) + ( semiNeeded ? ";" : "" )
Devin Lim61643762017-12-07 15:55:38 -0800513}
Jon Hall6af749d2018-05-29 12:59:47 -0700514
Devin Lim61643762017-12-07 15:55:38 -0800515def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700516 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800517
Jon Hall6af749d2018-05-29 12:59:47 -0700518 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
519 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800520
Jon Hall6af749d2018-05-29 12:59:47 -0700521 withCredentials( [
522 string( credentialsId: 'db_pass', variable: 'pass' ),
523 string( credentialsId: 'db_user', variable: 'user' ),
524 string( credentialsId: 'db_host', variable: 'host' ),
525 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
526 testList = generalFuncs.getTestList( testCategory )
527 sh '''#!/bin/bash
528 ''' +
529 generalFuncs.basicGraphPart( trend_generator_file, host, port,
530 user, pass, testType,
531 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
532 }
Devin Lim61643762017-12-07 15:55:38 -0800533 }
Jon Hall6af749d2018-05-29 12:59:47 -0700534 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800535 }
536}
Jon Hall6af749d2018-05-29 12:59:47 -0700537
Devin Lim61643762017-12-07 15:55:38 -0800538def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700539 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700540
Jon Hall6af749d2018-05-29 12:59:47 -0700541 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
542 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800543}
Jon Hall6af749d2018-05-29 12:59:47 -0700544
Devin Lim61643762017-12-07 15:55:38 -0800545def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700546 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700547
Jon Hall6af749d2018-05-29 12:59:47 -0700548 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
549 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800550}
Jon Hall6af749d2018-05-29 12:59:47 -0700551
Devin Lim61643762017-12-07 15:55:38 -0800552def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700553 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700554
Jon Hall6af749d2018-05-29 12:59:47 -0700555 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
556 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800557}
Devin Limf5175192018-05-14 19:13:22 -0700558
Jon Hall6af749d2018-05-29 12:59:47 -0700559def databasePart( wikiPrefix, testName, database_command ){
560 // to read and insert the data from .csv to the database
561
562 return '''
Devin Lim61643762017-12-07 15:55:38 -0800563 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
564 do
565 echo \$line
566 echo ''' + database_command + '''
567 done '''
568}
Jon Hall6af749d2018-05-29 12:59:47 -0700569
570def generateStatGraph( testMachineOn, onos_branch, AllTheTests, stat_graph_generator_file, pie_graph_generator_file,
571 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700572 // Will generate the stats graph.
573
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800574 testListPart = createStatsList( "FUNC", AllTheTests[ "FUNC" ], true ) +
575 createStatsList( "HA", AllTheTests[ "HA" ], true ) +
576 createStatsList( "USECASE", AllTheTests[ "USECASE" ], false )
577 pieTestList = makeTestList( AllTheTests[ "FUNC" ], true ) +
578 makeTestList( AllTheTests[ "HA" ], true ) +
579 makeTestList( AllTheTests[ "USECASE" ], false )
Jon Hall6af749d2018-05-29 12:59:47 -0700580 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
581 "ALL", onos_branch, testListPart, graph_saved_directory, pieTestList )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800582}
Jon Hall6af749d2018-05-29 12:59:47 -0700583
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700584def branchWithPrefix( branch ){
Devin Limf5175192018-05-14 19:13:22 -0700585 // get the branch with the prefix ( "onos-" )
Jeremy Ronquillof78a6ca2018-03-12 09:20:57 -0700586 return ( ( branch != "master" ) ? "onos-" : "" ) + branch
587}
Jon Hall6af749d2018-05-29 12:59:47 -0700588
You Wangfe3877b2018-08-02 11:48:35 -0700589def testBranchWithPrefix( branch ){
590 // get TestON branch with the prefix ( "onos-" )
You Wang8f12d7d2018-11-09 13:47:23 -0800591 if ( branch == "1.12" )
You Wangfe3877b2018-08-02 11:48:35 -0700592 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800593 else if ( branch == "1.13" )
You Wangfe3877b2018-08-02 11:48:35 -0700594 return "onos-1.13"
You Wang8f12d7d2018-11-09 13:47:23 -0800595 else if ( branch == "1.14" )
596 return "onos-1.14"
597 else if ( branch == "1.15" )
598 return "onos-1.14"
You Wangfe3877b2018-08-02 11:48:35 -0700599 else
600 return "master"
601}
602
Jon Hall6af749d2018-05-29 12:59:47 -0700603return this