blob: be93b7f7738059f1b23ab705d218d19ede88f511 [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
Jon Hall2ee92f82018-06-07 13:07:33 -070043 hasArgs = false
Jon Hall6af749d2018-05-29 12:59:47 -070044 isTrend = true
Devin Lim61643762017-12-07 15:55:38 -080045}
Jon Hall6af749d2018-05-29 12:59:47 -070046
Devin Lim61643762017-12-07 15:55:38 -080047def initialize( type, SCPFfuncs ){
Jon Hall6af749d2018-05-29 12:59:47 -070048 // Initializing for SCPF tests
49 // type : type of the test ( SR,FUNC,SCPF... )
50 // Passing the SCPFfunction which will be PerformanceFuncs.groovy
Devin Limf5175192018-05-14 19:13:22 -070051
Jon Hall6af749d2018-05-29 12:59:47 -070052 init( type )
53 SCPFfunc = SCPFfuncs
54 isSCPF = true
Jon Hall2ee92f82018-06-07 13:07:33 -070055 hasArgs = true // Has TestON cli arguments to be added when running the test
Jon Hall6af749d2018-05-29 12:59:47 -070056 machine = machineType[ type ]
Devin Lim61643762017-12-07 15:55:38 -080057}
Jon Hall6af749d2018-05-29 12:59:47 -070058
Devin Lim61643762017-12-07 15:55:38 -080059def initialize( type ){
Jon Hall6af749d2018-05-29 12:59:47 -070060 // initializing for FUNC,HA,SR, and USECASE
61 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070062
Jon Hall6af749d2018-05-29 12:59:47 -070063 init( type )
64 SCPFfunc = null
65 table_name = "executed_test_tests"
66 result_name = "executed_test_results"
67 trend_generator_file = fileRelated.trendMultiple
68 build_stats_generator_file = fileRelated.histogramMultiple
69 isSCPF = false
Jon Hall2ee92f82018-06-07 13:07:33 -070070 hasArgs = false
Devin Lim61643762017-12-07 15:55:38 -080071}
Jon Hall6af749d2018-05-29 12:59:47 -070072
Devin Lim61643762017-12-07 15:55:38 -080073def init( type ){
Jon Hall6af749d2018-05-29 12:59:47 -070074 // type : type of the test ( SR,FUNC,SCPF... )
Devin Limf5175192018-05-14 19:13:22 -070075
Jon Hall6af749d2018-05-29 12:59:47 -070076 machineType = [ "FUNC": "VM",
77 "HA": "VM",
78 "SR": "Fabric",
79 "SCPF": "BM",
80 "USECASE": "BM" ]
81 testType = type
82 testMachine = "TestStation-" + machineType[ type ] + "s"
83 isTrend = false
Devin Lim61643762017-12-07 15:55:38 -080084}
Jon Hall6af749d2018-05-29 12:59:47 -070085
Devin Lim86e40532018-04-06 12:44:06 -070086def additionalInitForSR( branch ){
Jon Hall6af749d2018-05-29 12:59:47 -070087 // additional setup for SegmentRouting tests to determine the machine depends on the branch it is running.
You Wangf043d0a2019-04-22 16:30:40 -070088 // branch : branch of the onos. ( master, 2.1, 1.15... )
Devin Limf5175192018-05-14 19:13:22 -070089
Jon Hall6af749d2018-05-29 12:59:47 -070090 testMachine = ( ( new StringBuilder( testMachine ) ).insert( testMachine.size() - 1, fabricOn( branch ) ) ).
91 toString()
92 if ( isTrend ){
93 machine += fabricOn( branch )
Devin Lim61643762017-12-07 15:55:38 -080094 }
Jon Hall6af749d2018-05-29 12:59:47 -070095 else {
96 machineType[ testType ] += fabricOn( branch )
97 }
98 print testMachine
Devin Lim61643762017-12-07 15:55:38 -080099}
Devin Limf5175192018-05-14 19:13:22 -0700100
Jon Hall6af749d2018-05-29 12:59:47 -0700101def fabricOn( branch ){
102 // gets the fabric machines with the branch of onos.
You Wangf043d0a2019-04-22 16:30:40 -0700103 // branch : master, 2.1, 1.15...
Jon Hall6af749d2018-05-29 12:59:47 -0700104 // branch.reverse().take(4).reverse() will get last 4 characters of the string.
You Wangdba6c9f2018-12-21 11:58:55 -0800105 switch ( branch.reverse().take( 3 ).reverse() ){
106 case "ter": return "4"
You Wangf043d0a2019-04-22 16:30:40 -0700107 case "2.1": return "3"
You Wangdba6c9f2018-12-21 11:58:55 -0800108 case "2.0": return "3"
109 case ".15": return "2"
110 case ".14": return "3"
111 case ".13": return "2"
112 case ".12": return "3"
Jon Hall6af749d2018-05-29 12:59:47 -0700113 default: return "4"
114 }
115}
116
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700117def getProperties( category, branchWithPrefix ){
Jon Hall6af749d2018-05-29 12:59:47 -0700118 // get the properties of the test by reading the TestONOS.property
119
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700120 filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property'''
121
Jon Hall6af749d2018-05-29 12:59:47 -0700122 node( testMachine ) {
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700123 return readProperties( file: filePath )
Jon Hall6af749d2018-05-29 12:59:47 -0700124 }
125}
126
127def getTestsToRun( testList ){
128 // get test to run by tokenizing the list.
129
130 testList.tokenize( "\n;, " )
131}
132
133def getCurrentTime(){
134 // get time of the PST zone.
135
136 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
137 return new Date()
138}
139
Jon Hall6af749d2018-05-29 12:59:47 -0700140def sendResultToSlack( start, isManualRun, branch ){
141 // send the result of the test to the slack when it is not manually running.
142 // start : start time of the test
143 // isManualRun : string that is whether "false" or "true"
144 // branch : branch of the onos.
145
146 try {
147 if ( isManualRun == "false" ){
148 end = getCurrentTime()
149 TimeDuration duration = TimeCategory.minus( end, start )
You Wang28cb8552019-02-19 16:11:52 -0800150 // FIXME: for now we disable notifications of normal test results
151 /*
Jon Hall6af749d2018-05-29 12:59:47 -0700152 slackSend( color: "#5816EE",
153 message: testType + "-" + branch + " tests ended at: " + end.toString() +
154 "\nTime took : " + duration )
You Wang28cb8552019-02-19 16:11:52 -0800155 */
Jon Hall6af749d2018-05-29 12:59:47 -0700156 }
157 }
158 catch ( all ){
159 }
160}
161
162def initAndRunTest( testName, testCategory ){
163 // Bash script that will
164 // Initialize the environment to the machine and run the test.
165 // testName : name of the test
166 // testCategory : (SR,FUNC ... )
167
168 return '''#!/bin/bash -l
Devin Lim61643762017-12-07 15:55:38 -0800169 set -i # interactive
170 set +e
171 shopt -s expand_aliases # expand alias in non-interactive mode
172 export PYTHONUNBUFFERED=1
173 ifconfig
Devin Lim61643762017-12-07 15:55:38 -0800174 echo "ONOS Branch is: $ONOSBranch"
175 echo "TestON Branch is: $TestONBranch"
176 echo "Test date: "
177 date
178 cd ~
179 export PATH=$PATH:onos/tools/test/bin
180 timeout 240 stc shutdown | head -100
181 timeout 240 stc teardown | head -100
182 timeout 240 stc shutdown | head -100
183 cd ~/OnosSystemTest/TestON/bin
Jon Hall2ee92f82018-06-07 13:07:33 -0700184 git log | head
Devin Lim61643762017-12-07 15:55:38 -0800185 ./cleanup.sh -f
Jon Hall6af749d2018-05-29 12:59:47 -0700186 ''' + "./cli.py run " +
Jon Hall2ee92f82018-06-07 13:07:33 -0700187 ( !hasArgs ? testName : testCategory[ testName ][ 'test' ] ) +
Jon Hall6af749d2018-05-29 12:59:47 -0700188 " --params GRAPH/nodeCluster=" + machineType[ testType ] + '''
Devin Lim61643762017-12-07 15:55:38 -0800189 ./cleanup.sh -f
190 # cleanup config changes
191 cd ~/onos/tools/package/config
192 git clean -df'''
193}
Devin Limf5175192018-05-14 19:13:22 -0700194
Jon Hall8b1e92c2018-06-13 14:07:22 -0700195def copyLogs(){
196 // bash script to copy the logs and other necessary element for SR tests.
Jon Hall6af749d2018-05-29 12:59:47 -0700197
198 result = ""
199 if ( testType == "SR" ){
200 result = '''
Devin Lim61643762017-12-07 15:55:38 -0800201 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
202 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
203 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
204 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lima7b97a42018-04-09 14:26:38 -0700205 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim6faa3f92018-05-01 13:16:25 -0700206 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
Devin Lim61643762017-12-07 15:55:38 -0800207 '''
Jon Hall6af749d2018-05-29 12:59:47 -0700208 }
209 return result
Devin Lim61643762017-12-07 15:55:38 -0800210}
Devin Limf5175192018-05-14 19:13:22 -0700211
Jon Hall6af749d2018-05-29 12:59:47 -0700212def cleanAndCopyFiles( testName ){
213 // clean up some files that were in the folder and copy the new files from the log
214 // testName : name of the test
215
216 return '''#!/bin/bash -i
Devin Lim61643762017-12-07 15:55:38 -0800217 set +e
218 echo "ONOS Branch is: ${ONOSBranch}"
219 echo "TestON Branch is: ${TestONBranch}"
220 echo "Job name is: "''' + testName + '''
221 echo "Workspace is: ${WORKSPACE}/"
222 echo "Wiki page to post is: ${WikiPrefix}-"
223 # remove any leftover files from previous tests
224 sudo rm ${WORKSPACE}/*Wiki.txt
225 sudo rm ${WORKSPACE}/*Summary.txt
226 sudo rm ${WORKSPACE}/*Result.txt
You Wangaa7bc722019-02-21 17:55:39 -0800227 sudo rm ${WORKSPACE}/*Alarm.txt || true
Devin Lim61643762017-12-07 15:55:38 -0800228 sudo rm ${WORKSPACE}/*.csv
229 #copy files to workspace
230 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
Jon Hall8b1e92c2018-06-13 14:07:22 -0700231 ''' + copyLogs() + '''
Devin Lim61643762017-12-07 15:55:38 -0800232 sudo cp *.txt ${WORKSPACE}/
233 sudo cp *.csv ${WORKSPACE}/
234 cd ${WORKSPACE}/
235 for i in *.csv
236 do mv "$i" "$WikiPrefix"-"$i"
237 done
238 ls -al
239 cd '''
240}
Devin Limf5175192018-05-14 19:13:22 -0700241
Jon Hall6af749d2018-05-29 12:59:47 -0700242def fetchLogs( testName ){
243 // fetch the logs of onos from onos nodes to onos System Test logs
244 // testName: name of the test
245
246 return '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800247 set +e
248 cd ~/OnosSystemTest/TestON/logs
Jon Hall8b1e92c2018-06-13 14:07:22 -0700249 echo "TestON test name is: "''' + testName + '''
Devin Lim61643762017-12-07 15:55:38 -0800250 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
251 echo "########################################################################################"
252 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
253 echo "########################################################################################"
254 cd $TestONlogDir
255 if [ $? -eq 1 ]
256 then
257 echo "Job name does not match any test suite name to move log!"
258 else
259 pwd
Jon Hall3e6edb32018-08-21 16:20:30 -0700260 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
261 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 -0800262 fi
263 cd'''
264}
Jon Hall6af749d2018-05-29 12:59:47 -0700265
Devin Lim61643762017-12-07 15:55:38 -0800266def isPostingResult( manual, postresult ){
Jon Hall6af749d2018-05-29 12:59:47 -0700267 // check if it is posting the result.
268 // posting when it is automatically running or has postResult condition from the manual run
Devin Limf5175192018-05-14 19:13:22 -0700269
Jon Hall6af749d2018-05-29 12:59:47 -0700270 return manual == "false" || postresult == "true"
Devin Lim61643762017-12-07 15:55:38 -0800271}
Jon Hall6af749d2018-05-29 12:59:47 -0700272
Devin Lim61643762017-12-07 15:55:38 -0800273def postResult( prop, graphOnly ){
Jon Hall6af749d2018-05-29 12:59:47 -0700274 // post the result by triggering postjob.
275 // prop : property dictionary that was read from the machine.
276 // graphOnly : if it is graph generating job
Devin Limf5175192018-05-14 19:13:22 -0700277
Jon Hall6af749d2018-05-29 12:59:47 -0700278 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
279 def post = build job: "postjob-" + ( graphOnly ? machine : machineType[ testType ] ), propagate: false
Devin Lim61643762017-12-07 15:55:38 -0800280 }
Devin Lim61643762017-12-07 15:55:38 -0800281}
Jon Hall6af749d2018-05-29 12:59:47 -0700282
283def postLogs( testName, prefix ){
284 // posting logs of the onos jobs specifically SR tests
285 // testName : name of the test
You Wangf043d0a2019-04-22 16:30:40 -0700286 // prefix : branch prefix ( master, 2.1, 1.15 ... )
Jon Hall6af749d2018-05-29 12:59:47 -0700287
288 resultURL = ""
289 if ( testType == "SR" ){
290 def post = build job: "SR-log-" + prefix, propagate: false
291 resultURL = post.getAbsoluteUrl()
292 }
293 return resultURL
294}
295
296def getSlackChannel(){
297 // get name of the slack channel.
298 // if the test is SR, it will return sr-failures
299
You Wang28cb8552019-02-19 16:11:52 -0800300 // FIXME: For now we move all notifications to #jenkins-related
301 // return "#" + ( testType == "SR" ? "sr-failures" : "jenkins-related" )
302 return "#jenkins-related"
Jon Hall6af749d2018-05-29 12:59:47 -0700303}
304
Jon Hall8b1e92c2018-06-13 14:07:22 -0700305def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
You Wang28cb8552019-02-19 16:11:52 -0800306 // analyzing the result of the test and send to slack if any abnormal result is logged.
Jon Hall6af749d2018-05-29 12:59:47 -0700307 // prop : property dictionary
308 // workSpace : workSpace where the result file is saved
Jon Hall8b1e92c2018-06-13 14:07:22 -0700309 // pureTestName : TestON name of the test
310 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
Jon Hall6af749d2018-05-29 12:59:47 -0700311 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
312 // wikiLink : link of the wiki page where the result was posted
313 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
314
315 node( testMachine ) {
You Wang28cb8552019-02-19 16:11:52 -0800316 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
317 if ( fileExists( alarmFile ) ) {
You Wang28cb8552019-02-19 16:11:52 -0800318 def alarmContents = readFile( alarmFile )
You Wang2dcde682019-02-21 12:18:15 -0800319 slackSend( channel: getSlackChannel(),
320 color: "FF0000",
321 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
322 alarmContents + "\n" +
323 "[TestON log] : \n" +
324 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
325 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
326 "https://wiki.onosproject.org/display/ONOS/" +
327 wikiLink.replaceAll( "\\s", "+" ) ) ) +
328 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
329 resultURL + "artifact/" ) : "" ),
330 teamDomain: 'onosproject' )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700331 throw new Exception( "Abnormal test result." )
Jon Hall6af749d2018-05-29 12:59:47 -0700332 }
You Wang28cb8552019-02-19 16:11:52 -0800333 else {
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700334 print "Test results are normal."
You Wang28cb8552019-02-19 16:11:52 -0800335 }
Jon Hall6af749d2018-05-29 12:59:47 -0700336 }
337}
338
Devin Lime89761a2018-03-16 17:52:57 -0700339def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700340 // publish HTML script to wiki confluence
341 // isManualRun : string "true" "false"
342 // isPostResult : string "true" "false"
343 // wikiLink : link of the wiki page to publish
344 // file : name of the file to be published
Devin Limf5175192018-05-14 19:13:22 -0700345
Jon Hall6af749d2018-05-29 12:59:47 -0700346 if ( isPostingResult( isManualRun, isPostResult ) ){
347 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
348 attachArchivedArtifacts: true, buildIfUnstable: true,
349 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
350 }
Devin Lim61643762017-12-07 15:55:38 -0800351
352}
Devin Limf5175192018-05-14 19:13:22 -0700353
Jon Hall6af749d2018-05-29 12:59:47 -0700354def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
355 graph_saved_directory ){
356 // 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 -0700357 // testName : name of the test in Jenkins
Jon Hall6af749d2018-05-29 12:59:47 -0700358 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
359 // result on pipeline view
360 // prop : dictionary property on the machine
361 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
362 // 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 -0700363 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
Jon Hall6af749d2018-05-29 12:59:47 -0700364 // graph_generator_file : Rscript file with the full path.
365 // graph_saved_directory : where the generated graph will be saved to.
366
367 return {
368 catchError {
369 stage( testName ) {
370 if ( toBeRun ){
371 def workSpace = "/var/jenkins/workspace/" + testName
372 def fileContents = ""
373 node( testMachine ) {
374 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
You Wang8e4f4c02019-01-03 10:49:46 -0800375 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
Jon Hall6af749d2018-05-29 12:59:47 -0700376 'TestONBranch=' + prop[ "TestONBranch" ],
377 'ONOSTag=' + prop[ "ONOSTag" ],
378 'WikiPrefix=' + prop[ "WikiPrefix" ],
379 'WORKSPACE=' + workSpace ] ) {
380 if ( !graphOnly ){
You Wang6d171942018-10-17 11:45:05 -0700381 if ( isSCPF ){
382 // Remove the old database file
383 sh SCPFfunc.cleanupDatabaseFile( testName )
384 }
Jon Hall6af749d2018-05-29 12:59:47 -0700385 sh initAndRunTest( testName, testCategory )
386 // For the Wiki page
387 sh cleanAndCopyFiles( pureTestName )
388 }
Jon Hall8b1e92c2018-06-13 14:07:22 -0700389 databaseAndGraph( prop, testName, pureTestName, graphOnly,
390 graph_generator_file, graph_saved_directory )
Jon Hall6af749d2018-05-29 12:59:47 -0700391 if ( !graphOnly ){
392 sh fetchLogs( pureTestName )
393 if ( !isSCPF ){
394 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
Jeremy Ronquillo5b6279b2019-06-18 14:25:45 -0700395 prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700396 workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700397 }
398 }
Devin Lim61643762017-12-07 15:55:38 -0800399 }
Jon Hall6af749d2018-05-29 12:59:47 -0700400 }
Devin Lim61643762017-12-07 15:55:38 -0800401 postResult( prop, graphOnly )
Jon Hall6af749d2018-05-29 12:59:47 -0700402 if ( !graphOnly ){
Jon Hall8b1e92c2018-06-13 14:07:22 -0700403 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
Jon Hall6af749d2018-05-29 12:59:47 -0700404 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
Jeremy Ronquilloa833e962019-06-18 13:50:40 -0700405 isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
Jon Hall6af749d2018-05-29 12:59:47 -0700406 isSCPF )
407 }
408 }
409 }
410 }
411 }
Devin Lim61643762017-12-07 15:55:38 -0800412}
Devin Limf5175192018-05-14 19:13:22 -0700413
Jon Hall8b1e92c2018-06-13 14:07:22 -0700414def databaseAndGraph( prop, testName, pureTestName, graphOnly, graph_generator_file, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700415 // part where it insert the data into the database.
416 // It will use the predefined encrypted variables from the Jenkins.
417 // prop : property dictionary that was read from the machine
Jon Hall8b1e92c2018-06-13 14:07:22 -0700418 // testName : Jenkins name for the test
419 // pureTestName : TestON name for the test
Jon Hall6af749d2018-05-29 12:59:47 -0700420 // graphOnly : boolean whether it is graph only or not
421 // graph_generator_file : Rscript file with the full path.
422 // graph_saved_directory : where the generated graph will be saved to.
Jon Hall6af749d2018-05-29 12:59:47 -0700423 if ( graphOnly || isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
424 // Post Results
425 withCredentials( [
426 string( credentialsId: 'db_pass', variable: 'pass' ),
427 string( credentialsId: 'db_user', variable: 'user' ),
428 string( credentialsId: 'db_host', variable: 'host' ),
429 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
430 def database_command = generalFuncs.database_command_create( pass, host, port, user ) +
431 ( !isSCPF ? sqlCommand( testName ) : SCPFfunc.sqlCommand( testName ) )
432 sh '''#!/bin/bash
Devin Lim61643762017-12-07 15:55:38 -0800433 export DATE=\$(date +%F_%T)
434 cd ~
Jon Hall6af749d2018-05-29 12:59:47 -0700435 pwd ''' + ( graphOnly ? "" :
Jon Hall8b1e92c2018-06-13 14:07:22 -0700436 ( !isSCPF ? databasePart( prop[ "WikiPrefix" ], pureTestName, database_command ) :
Jon Hall6af749d2018-05-29 12:59:47 -0700437 SCPFfunc.databasePart( testName, database_command ) ) ) + '''
438 ''' + ( !isSCPF ? graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory,
439 graph_generator_file ) :
440 SCPFfunc.getGraphGeneratingCommand( host, port, user, pass, testName, prop ) )
Devin Lim61643762017-12-07 15:55:38 -0800441 }
Devin Lim61643762017-12-07 15:55:38 -0800442 }
443}
Jon Hall6af749d2018-05-29 12:59:47 -0700444
445def generateCategoryStatsGraph( testMachineOn, manualRun, postresult, stat_file, pie_file, type, branch, testListPart,
446 save_path, pieTestListPart ){
447 // function that will generate the category stat graphs for the overall test.
448 // testMachineOn : the machine the graph will be generated. It will be TestStation-VMs for the most cases
449 // manualRun : string of "true" or "false"
450 // postresult : string of "true" or "false"
451 // stat_file : file name with full path for Rscript for the stat graph
452 // pie_file : file name with full path for Rscript for the pie graph
453 // type : type of the test ( USECASE, FUNC, HA )
You Wangf043d0a2019-04-22 16:30:40 -0700454 // branch : branch of the test ( master, onos-2.1, onos-1.15 )
Jon Hall6af749d2018-05-29 12:59:47 -0700455 // testListPart : list of the test to be included
456 // save_path : path that will save the graphs to
457 // pieTestListPart : list of the test for pie graph
458
459 if ( isPostingResult( manualRun, postresult ) ){
460 node( testMachineOn ) {
461
462 withCredentials( [
463 string( credentialsId: 'db_pass', variable: 'pass' ),
464 string( credentialsId: 'db_user', variable: 'user' ),
465 string( credentialsId: 'db_host', variable: 'host' ),
466 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
467 sh '''#!/bin/bash
468 ''' + generalFuncs.basicGraphPart( stat_file, host, port, user, pass, type,
469 branch ) + " \"" + testListPart + "\" latest " + save_path + '''
470 ''' + getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'y',
471 save_path ) + '''
472 ''' +
473 getOverallPieGraph( pie_file, host, port, user, pass, branch, type, pieTestListPart, 'n', save_path )
474 }
475 }
476 postResult( [ ], true )
477 }
478}
479
Jon Hall6af749d2018-05-29 12:59:47 -0700480
Devin Lim61643762017-12-07 15:55:38 -0800481def generateOverallGraph( prop, testCategory, graph_saved_directory ){
Jon Hall6af749d2018-05-29 12:59:47 -0700482 // generate the overall graph for the test
Devin Lim61643762017-12-07 15:55:38 -0800483
Jon Hall6af749d2018-05-29 12:59:47 -0700484 if ( isPostingResult( prop[ "manualRun" ], prop[ "postResult" ] ) ){
485 node( testMachine ) {
Devin Lim61643762017-12-07 15:55:38 -0800486
Jon Hall6af749d2018-05-29 12:59:47 -0700487 withCredentials( [
488 string( credentialsId: 'db_pass', variable: 'pass' ),
489 string( credentialsId: 'db_user', variable: 'user' ),
490 string( credentialsId: 'db_host', variable: 'host' ),
491 string( credentialsId: 'db_port', variable: 'port' ) ] ) {
492 testList = generalFuncs.getTestList( testCategory )
493 sh '''#!/bin/bash
494 ''' +
495 generalFuncs.basicGraphPart( trend_generator_file, host, port,
496 user, pass, testType,
497 prop[ "ONOSBranch" ] ) + " " + testList + " 20 " + graph_saved_directory
498 }
Devin Lim61643762017-12-07 15:55:38 -0800499 }
Jon Hall6af749d2018-05-29 12:59:47 -0700500 postResult( prop, false )
Devin Lim61643762017-12-07 15:55:38 -0800501 }
502}
Jon Hall6af749d2018-05-29 12:59:47 -0700503
Devin Lim61643762017-12-07 15:55:38 -0800504def getOverallPieGraph( file, host, port, user, pass, branch, type, testList, yOrN, path ){
Jon Hall6af749d2018-05-29 12:59:47 -0700505 // Rcommand for the pie graph
Devin Limf5175192018-05-14 19:13:22 -0700506
Jon Hall6af749d2018-05-29 12:59:47 -0700507 return generalFuncs.basicGraphPart( file, host, port, user, pass, type, branch ) +
508 " \"" + testList + "\" latest " + yOrN + " " + path
Devin Lim61643762017-12-07 15:55:38 -0800509}
Jon Hall6af749d2018-05-29 12:59:47 -0700510
Devin Lim61643762017-12-07 15:55:38 -0800511def sqlCommand( testName ){
Jon Hall6af749d2018-05-29 12:59:47 -0700512 // get the inserting sqlCommand for non-SCPF tests.
Devin Limf5175192018-05-14 19:13:22 -0700513
Jon Hall6af749d2018-05-29 12:59:47 -0700514 return "\"INSERT INTO " + table_name + " VALUES('\$DATE','" + result_name + "','" +
515 testName + "',\$BUILD_NUMBER, '\$ONOSBranch', \$line);\" "
Devin Lim61643762017-12-07 15:55:38 -0800516}
Jon Hall6af749d2018-05-29 12:59:47 -0700517
Devin Lim61643762017-12-07 15:55:38 -0800518def graphGenerating( host, port, user, pass, testName, prop, graph_saved_directory, graph_generator_file ){
Jon Hall6af749d2018-05-29 12:59:47 -0700519 // get the graphGenerating R command for non-SCPF tests
Devin Limf5175192018-05-14 19:13:22 -0700520
Jon Hall6af749d2018-05-29 12:59:47 -0700521 return generalFuncs.basicGraphPart( graph_generator_file, host, port, user, pass, testName,
522 prop[ "ONOSBranch" ] ) + " 20 " + graph_saved_directory
Devin Lim61643762017-12-07 15:55:38 -0800523}
Devin Limf5175192018-05-14 19:13:22 -0700524
Jon Hall6af749d2018-05-29 12:59:47 -0700525def databasePart( wikiPrefix, testName, database_command ){
526 // to read and insert the data from .csv to the database
527
528 return '''
Devin Lim61643762017-12-07 15:55:38 -0800529 sed 1d ''' + workSpace + "/" + wikiPrefix + "-" + testName + '''.csv | while read line
530 do
531 echo \$line
532 echo ''' + database_command + '''
533 done '''
534}
Jon Hall6af749d2018-05-29 12:59:47 -0700535
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700536def generateStatGraph( testMachineOn, onos_branch, stat_graph_generator_file, pie_graph_generator_file,
Jon Hall6af749d2018-05-29 12:59:47 -0700537 graph_saved_directory ){
Devin Limf5175192018-05-14 19:13:22 -0700538
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700539 // Will generate the stats graph.
540 FUNCtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "FUNC" ) )
541 HAtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "HA" ) )
542 USECASEtestsStr = test_list.getTestListAsString( test_list.getTestsFromCategory( "USECASE" ) )
543
544 testListParam = "FUNC-" + FUNCtestsStr + ";" +
545 "HA-" + HAtestsStr + ";" +
546 "USECASE-" + USECASEtestsStr
547
548 pieTestListParam = FUNCtestsStr + "," +
549 HAtestsStr + "," +
550 USECASEtestsStr
551
Jon Hall6af749d2018-05-29 12:59:47 -0700552 generateCategoryStatsGraph( testMachineOn, "false", "true", stat_graph_generator_file, pie_graph_generator_file,
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700553 "ALL", onos_branch, testListParam, graph_saved_directory, pieTestListParam )
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800554}
Jon Hall6af749d2018-05-29 12:59:47 -0700555
Jon Hall6af749d2018-05-29 12:59:47 -0700556return this