blob: eddb588dc6597359b0364eb0ff770161b61bc128 [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
Jeremy Ronquillobd26bdb2019-07-08 16:15:45 -0700264
Jeremy Ronquillo593e5002019-07-08 11:30:35 -0700265 if ( graphOnly ){
Jeremy Ronquillobd26bdb2019-07-08 16:15:45 -0700266 if ( machine == null ){
267 machine = machineType[ testType ]
268 }
Jeremy Ronquillo593e5002019-07-08 11:30:35 -0700269 def post = build job: "postjob-" + machine, propagate: false
270 } else if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
Jeremy Ronquilloafca6702019-07-02 16:05:36 -0700271 def post = build job: "postjob-" + machineType[ testType ], propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800272 }
Devin Lim61643762017-12-07 15:55:38 -0800273}
Jon Hall6af749d2018-05-29 12:59:47 -0700274
275def postLogs( testName, prefix ){
276 // posting logs of the onos jobs specifically SR tests
277 // testName : name of the test
You Wangf043d0a2019-04-22 16:30:40 -0700278 // prefix : branch prefix ( master, 2.1, 1.15 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700279
280 resultURL = ""
281 if ( testType == "SR" ){
282 def post = build job: "SR-log-" + prefix, propagate: false
283 resultURL = post.getAbsoluteUrl()
284 }
285 return resultURL
286}
287
288def getSlackChannel(){
289 // get name of the slack channel.
290 // if the test is SR, it will return sr-failures
291
You Wang28cb8552019-02-19 16:11:52 -0800292 // FIXME: For now we move all notifications to #jenkins-related
293 // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
294 return "#jenkins-related"
Jon Hall6af749d2018-05-29 12:59:47 -0700295}
296
Jon Hall8b1e92c2018-06-13 14:07:22 -0700297def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
You Wang28cb8552019-02-19 16:11:52 -0800298 // analyzing the result of the test and send to slack if any abnormal result is logged.
Jon Hall6af749d2018-05-29 12:59:47 -0700299 // prop : property dictionary
300 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700301 // pureTestName : TestON name of the test
302 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700303 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
304 // wikiLink : link of the wiki page where the result was posted
305 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
306
307 node( testMachine ) {
You Wang28cb8552019-02-19 16:11:52 -0800308 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
309 if ( fileExists( alarmFile ) ) {
You Wang28cb8552019-02-19 16:11:52 -0800310 def alarmContents = readFile( alarmFile )
You Wang2dcde682019-02-21 12:18:15 -0800311 slackSend( channel: getSlackChannel(),
312 color: "FF0000",
313 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
314 alarmContents + "\n" +
315 "[TestON log] : \n" +
316 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
317 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
318 "https://wiki.onosproject.org/display/ONOS/" +
319 wikiLink.replaceAll( "\\s", "+" ) ) ) +
320 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
321 resultURL + "artifact/" ) : "" ),
322 teamDomain: 'onosproject' )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700323 throw new Exception( "Abnormal test result." )
Jon Hall6af749d2018-05-29 12:59:47 -0700324 }
You Wang28cb8552019-02-19 16:11:52 -0800325 else {
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700326 print "Test results are OK."
You Wang28cb8552019-02-19 16:11:52 -0800327 }
Jon Hall6af749d2018-05-29 12:59:47 -0700328 }
329}
330
Devin Lime89761a2018-03-16 17:52:57 -0700331def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700332 // publish HTML script to wiki confluence
333 // isManualRun : string "true" "false"
334 // isPostResult : string "true" "false"
335 // wikiLink : link of the wiki page to publish
336 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700337
Jon Hall6af749d2018-05-29 12:59:47 -0700338 if ( isPostingResult( isManualRun, isPostResult ) ){
339 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
340 attachArchivedArtifacts: true, buildIfUnstable: true,
341 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
342 }
Devin Lim61643762017-12-07 15:55:38 -0800343
344}
Devin Limf5175192018-05-14 19:13:22 -0700345
Jon Hall6af749d2018-05-29 12:59:47 -0700346def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
347 graph_saved_directory ){
348 // 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 -0700349 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700350 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
351 // result on pipeline view
352 // prop : dictionary property on the machine
353 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
354 // 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 -0700355 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700356 // graph_generator_file : Rscript file with the full path.
357 // graph_saved_directory : where the generated graph will be saved to.
358
359 return {
360 catchError {
361 stage( testName ) {
362 if ( toBeRun ){
363 def workSpace = "/var/jenkins/workspace/" + testName
364 def fileContents = ""
365 node( testMachine ) {
366 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
You Wang8e4f4c02019-01-03 10:49:46 -0800367 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
Jon Hall6af749d2018-05-29 12:59:47 -0700368 'TestONBranch=' + prop[ "TestONBranch" ],
369 'ONOSTag=' + prop[ "ONOSTag" ],
370 'WikiPrefix=' + prop[ "WikiPrefix" ],
371 'WORKSPACE=' + workSpace ] ) {
372 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700373 if ( isSCPF ){
374 // Remove the old database file
375 sh SCPFfunc.cleanupDatabaseFile( testName )
376 }
Jon Hall6af749d2018-05-29 12:59:47 -0700377 sh initAndRunTest( testName, testCategory )
378 // For the Wiki page
379 sh cleanAndCopyFiles( pureTestName )
380 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700381 databaseAndGraph( prop, testName, pureTestName, graphOnly,
382 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700383 if ( !graphOnly ){
384 sh fetchLogs( pureTestName )
385 if ( !isSCPF ){
386 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
Jeremy Ronquillo5b6279b2019-06-18 14:25:45 -0700387 prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700388 workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700389 }
390 }
Devin Lim61643762017-12-07 15:55:38 -0800391 }
Jon Hall6af749d2018-05-29 12:59:47 -0700392 }
Devin Lim61643762017-12-07 15:55:38 -0800393 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700394 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700395 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700396 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700397 isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
Jon Hall6af749d2018-05-29 12:59:47 -0700398 isSCPF )
399 }
400 }
401 }
402 }
403 }
Devin Lim61643762017-12-07 15:55:38 -0800404}
Devin Limf5175192018-05-14 19:13:22 -0700405
Jon Hall8b1e92c2018-06-13 14:07:22 -0700406def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700407 // part where it insert the data into the database.
408 // It will use the predefined encrypted variables from the Jenkins.
409 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700410 // testName : Jenkins name for the test
411 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700412 // graphOnly : boolean whether it is graph only or not
413 // graph_generator_file : Rscript file with the full path.
414 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700415 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
416 // Post Results
417 withCredentials( [
418 string( credentialsId: 'db_pass', variable: 'pass' ),
419 string( credentialsId: 'db_user', variable: 'user' ),
420 string( credentialsId: 'db_host', variable: 'host' ),
421 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
422 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
423 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
424 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800425 export DATE=\$(date +%F_%T)
426 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700427 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700428 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700429 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
430 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
431 graph_generator_file ) :
432 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800433 }
Devin Lim61643762017-12-07 15:55:38 -0800434 }
435}
Jon Hall6af749d2018-05-29 12:59:47 -0700436
437def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
438 save_path, pieTestListPart ){
439 // function that will generate the category stat graphs for the overall test.
440 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
441 // manualRun : string of "true" or "false"
442 // postresult : string of "true" or "false"
443 // stat_file : file name with full path for Rscript for the stat graph
444 // pie_file : file name with full path for Rscript for the pie graph
445 // type : type of the test ( USECASE, FUNC, HA )
You Wangf043d0a2019-04-22 16:30:40 -0700446 // branch : branch of the test ( master, onos-2.1, onos-1.15 )
Jon Hall6af749d2018-05-29 12:59:47 -0700447 // testListPart : list of the test to be included
448 // save_path : path that will save the graphs to
449 // pieTestListPart : list of the test for pie graph
450
451 if ( isPostingResult( manualRun, postresult ) ){
452 node( testMachineOn ) {
453
454 withCredentials( [
455 string( credentialsId: 'db_pass', variable: 'pass' ),
456 string( credentialsId: 'db_user', variable: 'user' ),
457 string( credentialsId: 'db_host', variable: 'host' ),
458 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
459 sh '''#!/bin/bash
460 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
461 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
462 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
463 save_path ) + '''
464 ''' +
465 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
466 }
467 }
468 postResult( [ ], true )
469 }
470}
471
Jon Hall6af749d2018-05-29 12:59:47 -0700472
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700473def generateOverallGraph( prop, tests, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700474 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800475
Jon Hall6af749d2018-05-29 12:59:47 -0700476 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
477 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800478
Jon Hall6af749d2018-05-29 12:59:47 -0700479 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' ) ] ) {
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700484 testList = test_list.getTestListAsString( tests )
Jon Hall6af749d2018-05-29 12:59:47 -0700485 sh '''#!/bin/bash
486 ''' +
487 generalFuncs.basicGraphPart( trend_generator_file, host, port,
488 user, pass, testType,
489 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
490 }
Devin Lim61643762017-12-07 15:55:38 -0800491 }
Jon Hall6af749d2018-05-29 12:59:47 -0700492 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800493 }
494}
Jon Hall6af749d2018-05-29 12:59:47 -0700495
Devin Lim61643762017-12-07 15:55:38 -0800496def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700497 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700498
Jon Hall6af749d2018-05-29 12:59:47 -0700499 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
500 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800501}
Jon Hall6af749d2018-05-29 12:59:47 -0700502
Devin Lim61643762017-12-07 15:55:38 -0800503def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700504 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700505
Jon Hall6af749d2018-05-29 12:59:47 -0700506 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
507 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800508}
Jon Hall6af749d2018-05-29 12:59:47 -0700509
Devin Lim61643762017-12-07 15:55:38 -0800510def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700511 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700512
Jon Hall6af749d2018-05-29 12:59:47 -0700513 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
514 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800515}
Devin Limf5175192018-05-14 19:13:22 -0700516
Jon Hall6af749d2018-05-29 12:59:47 -0700517def databasePart( wikiPrefix, testName, database_command ){
518 // to read and insert the data from .csv to the database
519
520 return '''
Devin Lim61643762017-12-07 15:55:38 -0800521 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
522 do
523 echo \$line
524 echo ''' + database_command + '''
525 done '''
526}
Jon Hall6af749d2018-05-29 12:59:47 -0700527
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700528def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
Jon Hall6af749d2018-05-29 12:59:47 -0700529 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700530
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700531 // Will generate the stats graph.
532 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
533 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
534 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
535
536 testListParam = "FUNC-" + FUNCtestsStr + ";" +
537 "HA-" + HAtestsStr + ";" +
538 "USECASE-" + USECASEtestsStr
539
540 pieTestListParam = FUNCtestsStr + "," +
541 HAtestsStr + "," +
542 USECASEtestsStr
543
Jon Hall6af749d2018-05-29 12:59:47 -0700544 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700545 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800546}
Jon Hall6af749d2018-05-29 12:59:47 -0700547
Jon Hall6af749d2018-05-29 12:59:47 -0700548return this