blob: 3060f084809f3d143c956f9d752ae7e8efe1d046 [file] [log] [blame]
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -07001#!groovy
2// 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
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070021import groovy.time.TimeCategory
22import groovy.time.TimeDuration
23
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070024// read the dependency files
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070025graphs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsGraphs.groovy' )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070026test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
27fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
28SCPFfuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/PerformanceFuncs.groovy' )
29
30category = null
31prop = null
32testsToRun = null
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -070033testsToRunStrList = null
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070034branch = null
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070035branchWithPrefix = null
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -070036start = null
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070037nodeLabel = null
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070038testStation = null
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070039testsOverride = null
40isGraphOnly = false
41isSCPF = false
Jeremy Ronquillo6da78cf2019-07-29 11:47:19 -070042pipelineTimeout = null
43
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070044testsFromList = [:]
45graphPaths = [:]
46pipeline = [:]
47
48main()
49
50def main(){
Jeremy Ronquillo892c1732019-07-29 15:22:57 -070051 pipelineTimeout = params.TimeOut.toInteger() // integer minutes until the entire pipeline times out. Usually passed from upstream master-trigger job.
Jeremy Ronquillo6da78cf2019-07-29 11:47:19 -070052 timeout( time: pipelineTimeout, unit: "MINUTES" ){
Jeremy Ronquillo892c1732019-07-29 15:22:57 -070053 init()
Jeremy Ronquillo6da78cf2019-07-29 11:47:19 -070054 runTests()
55 generateGraphs()
56 sendToSlack()
57 }
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070058}
59
60def init(){
61 fileRelated.init()
62 test_list.init()
63 readParams()
64
Jeremy Ronquillob8aac442019-07-31 13:28:01 -070065 if ( branch == "manually" ){
66 echo '''Warning: entered branch was: "manually". Defaulting to master branch.'''
67 branch = "master"
68 branchWithPrefix = test_list.addPrefixToBranch( branch )
69 }
70
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070071 if ( category == "SCPF" ){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070072 isSCPF = true
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070073 SCPFfuncs.init()
Jeremy Ronquillo442ce4d2019-07-26 16:35:11 -070074 graphs.initialize( SCPFfuncs );
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070075 prop = getProperties()
76 isOldFlow = ( prop[ "isOldFlow" ] == "true" )
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -070077 SCPFfuncs.oldFlowRuleCheck( isOldFlow, prop[ "ONOSBranch" ] )
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -070078 } else {
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070079 isSCPF = false
80 graphs.initialize()
81 prop = getProperties()
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070082 }
83
Jeremy Ronquillob8aac442019-07-31 13:28:01 -070084 // get the list of the tests from category
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070085 testsFromList = test_list.getTestsFromCategory( category )
86
87 initGraphPaths()
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070088 tokenizeTokens = "\n;, "
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070089
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070090 if ( testsOverride == "" || testsOverride == null ){
91 testsToRunStrList = prop[ "Tests" ].tokenize( tokenizeTokens )
92 } else {
93 testsToRunStrList = testsOverride.tokenize( tokenizeTokens )
94 }
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -070095 testsToRun = test_list.getTestsFromStringList( testsToRunStrList )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070096}
97
98def readParams(){
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070099 category = params.Category // "FUNC", "HA", "USECASE", etc.
100 branch = params.Branch // "1.15", "2.1", "master", etc.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700101 branchWithPrefix = test_list.addPrefixToBranch( branch )
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -0700102 testStation = params.TestStation // "TestStation-BMs", etc.
103 nodeLabel = params.NodeLabel // "BM", "VM", "Fabric-1.x", etc.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700104 testsOverride = params.TestsOverride // "FUNCflow, FUNCintent, [...]", overrides property file
105 isGraphOnly = params.OnlyRefreshGraphs // true or false
106}
107
108def getProperties(){
109 // get the properties of the test by reading the TestONOS.property
110
111 filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property'''
112
113 node( testStation ) {
114 return readProperties( file: filePath )
115 }
116}
117
118def getCurrentTime(){
119 // get time of the PST zone.
120
121 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
122 return new Date()
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700123}
124
125def initGraphPaths(){
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700126 graphPaths.put( "trendIndividual", fileRelated.rScriptPaths[ "scripts" ][ "trendIndividual" ] )
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -0700127 if ( category == "SR" ){
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700128 graphPaths.put( "saveDirectory", fileRelated.workspaces[ "base" ] + "postjob-" + ( testStation - "TestStation-" - "s" ) + "/" )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700129 } else if ( category == "SRHA" ) {
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700130 graphPaths.put( "saveDirectory", fileRelated.workspaces[ "Fabric" ] )
Jeremy Ronquillobb3001f2019-07-01 12:57:07 -0700131 } else if ( category == "SCPF" || category == "USECASE" ){
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700132 graphPaths.put( "saveDirectory", fileRelated.workspaces[ "BM" ] )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700133 } else {
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700134 graphPaths.put( "saveDirectory", fileRelated.workspaces[ "VM" ] )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700135 }
136}
137
138def runTests(){
139 // run the test sequentially and save the function into the dictionary.
Jeremy Ronquillob8aac442019-07-31 13:28:01 -0700140 for ( String test : testsFromList.keySet() ){
141 toBeRun = testsToRun.keySet().contains( test )
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700142 stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
Jeremy Ronquillo31a3eb32019-08-02 13:30:37 -0700143 pureTestName = test.contains( "WithFlowObj" ) ? test - "WithFlowObj" : test
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700144 pipeline[ stepName ] = runTest( test,
145 toBeRun,
146 prop,
147 pureTestName,
148 isGraphOnly,
149 testsToRun,
150 graphPaths[ "trendIndividual" ],
151 graphPaths[ "saveDirectory" ] )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700152 }
153
154 // get the start time of the test.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700155 start = getCurrentTime()
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700156
157 // run the tests sequentially.
158 for ( test in pipeline.keySet() ){
159 pipeline[ test ].call()
160 }
161}
162
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700163def initTest(){
164 return '''#!/bin/bash -l
165 set -i # interactive
166 set +e
167 shopt -s expand_aliases # expand alias in non-interactive mode
168 export PYTHONUNBUFFERED=1
169 ifconfig
170 echo "ONOS Branch is: $ONOSBranch"
171 echo "TestON Branch is: $TestONBranch"
172 echo "Test date: "
173 date
174 cd ~
175 export PATH=$PATH:onos/tools/test/bin
176 timeout 240 stc shutdown | head -100
177 timeout 240 stc teardown | head -100
178 timeout 240 stc shutdown | head -100
179 cd ~/OnosSystemTest/TestON/bin
180 git log | head
181 ./cleanup.sh -f || true
182 '''
183}
184
Jeremy Ronquillo31a3eb32019-08-02 13:30:37 -0700185def runTestCli_py( testName, pureTestName, testCategory ){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700186 // Bash script that will run the test.
187 // testName : name of the test
188 // testCategory : (SR,FUNC ... )
Jeremy Ronquillo31a3eb32019-08-02 13:30:37 -0700189 flowObjFlag = false
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700190
Jeremy Ronquillo31a3eb32019-08-02 13:30:37 -0700191 if ( isSCPF && testName.contains( "WithFlowObj" ) ){
192 flowObjFlag = true
193 }
194
195 command = '''cd ~/OnosSystemTest/TestON/bin
196 ./cli.py run ''' + pureTestName + ''' --params''' + ( flowObjFlag ? '''TEST/flowObj=True ''' : ''' ''' ) + '''GRAPH/nodeCluster=''' + graphs.getPostjobType( nodeLabel ) + ''' '''
197 echo command
198
199 return command
200
201
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700202}
203
204def concludeRunTest(){
205 return '''cd ~/OnosSystemTest/TestON/bin
206 ./cleanup.sh -f || true
207 # cleanup config changes
208 cd ~/onos/tools/package/config
209 git clean -df'''
210}
211
212def copyLogs(){
213 // bash script to copy the logs and other necessary element for SR tests.
214
215 result = ""
216 if ( category == "SR" ){
217 result = '''
218 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
219 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
220 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
221 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
222 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
223 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
224 '''
225 }
226 return result
227}
228
229def cleanAndCopyFiles( testName ){
230 // clean up some files that were in the folder and copy the new files from the log
231 // testName : name of the test
232
233 return '''#!/bin/bash -i
234 set +e
235 echo "ONOS Branch is: ${ONOSBranch}"
236 echo "TestON Branch is: ${TestONBranch}"
237 echo "Job name is: "''' + testName + '''
238 echo "Workspace is: ${WORKSPACE}/"
239 echo "Wiki page to post is: ${WikiPrefix}-"
240 # remove any leftover files from previous tests
241 sudo rm ${WORKSPACE}/*Wiki.txt
242 sudo rm ${WORKSPACE}/*Summary.txt
243 sudo rm ${WORKSPACE}/*Result.txt
244 sudo rm ${WORKSPACE}/*Alarm.txt || true
245 sudo rm ${WORKSPACE}/*.csv
246 #copy files to workspace
247 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
248 ''' + copyLogs() + '''
249 sudo cp *.txt ${WORKSPACE}/
250 sudo cp *.csv ${WORKSPACE}/
251 cd ${WORKSPACE}/
252 for i in *.csv
253 do mv "$i" "$WikiPrefix"-"$i"
254 done
255 ls -al
256 cd '''
257}
258
259def fetchLogs( testName ){
260 // fetch the logs of onos from onos nodes to onos System Test logs
261 // testName: name of the test
262
263 return '''#!/bin/bash
264 set +e
265 cd ~/OnosSystemTest/TestON/logs
266 echo "TestON test name is: "''' + testName + '''
267 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
268 echo "########################################################################################"
269 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
270 echo "########################################################################################"
271 cd $TestONlogDir
272 if [ $? -eq 1 ]
273 then
274 echo "Job name does not match any test suite name to move log!"
275 else
276 pwd
277 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
278 for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done
279 fi
280 cd'''
281}
282
283def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
284 // publish HTML script to wiki confluence
285 // isManualRun : string "true" "false"
286 // isPostResult : string "true" "false"
287 // wikiLink : link of the wiki page to publish
288 // file : name of the file to be published
289
Jeremy Ronquillo31a3eb32019-08-02 13:30:37 -0700290 if ( graphs.isPostingResult( isManualRun, isPostResult ) ){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700291 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
292 attachArchivedArtifacts: true, buildIfUnstable: true,
293 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
294 }
295}
296
297def postLogs( testName, prefix ){
298 // posting logs of the onos jobs specifically SR tests
299 // testName : name of the test
300 // prefix : branch prefix ( master, 2.1, 1.15 ... )
301
302 resultURL = ""
303 if ( category == "SR" ){
304 def post = build job: "SR-log-" + prefix, propagate: false
305 resultURL = post.getAbsoluteUrl()
306 }
307 return resultURL
308}
309
310def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
311 // analyzing the result of the test and send to slack if any abnormal result is logged.
312 // prop : property dictionary
313 // workSpace : workSpace where the result file is saved
314 // pureTestName : TestON name of the test
315 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
316 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
317 // wikiLink : link of the wiki page where the result was posted
318 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
319
320 node( testStation ) {
321 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
322 if ( fileExists( alarmFile ) ) {
323 def alarmContents = readFile( alarmFile )
324 slackSend( channel: "#jenkins-related",
325 color: "FF0000",
326 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
327 alarmContents + "\n" +
328 "[TestON log] : \n" +
329 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
330 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
331 "https://wiki.onosproject.org/display/ONOS/" +
332 wikiLink.replaceAll( "\\s", "+" ) ) ) +
333 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
334 resultURL + "artifact/" ) : "" ),
335 teamDomain: 'onosproject' )
Jeremy Ronquilloe4e83912019-07-29 12:58:48 -0700336 print "Abnormal test result."
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700337 throw new Exception( "Abnormal test result." )
338 }
339 else {
340 print "Test results are OK."
341 }
342 }
343}
344
345def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
346 graph_saved_directory ){
347 // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
348 // testName : name of the test in Jenkins
349 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
350 // result on pipeline view
351 // prop : dictionary property on the machine
352 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
353 // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
354 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
355 // graph_generator_file : Rscript file with the full path.
356 // graph_saved_directory : where the generated graph will be saved to.
357
358 return {
359 catchError {
360 stage( testName ) {
361 if ( toBeRun ){
362 def workSpace = "/var/jenkins/workspace/" + testName
363 def fileContents = ""
364 node( testStation ) {
365 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
366 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
367 'TestONBranch=' + prop[ "TestONBranch" ],
368 'ONOSTag=' + prop[ "ONOSTag" ],
369 'WikiPrefix=' + prop[ "WikiPrefix" ],
370 'WORKSPACE=' + workSpace ] ) {
371 if ( !graphOnly ){
372 if ( isSCPF ){
373 // Remove the old database file
374 sh SCPFfuncs.cleanupDatabaseFile( testName )
375 }
376 sh script: initTest(), label: "Test Initialization: stc shutdown; stc teardown; ./cleanup.sh"
377 catchError{
Jeremy Ronquillo31a3eb32019-08-02 13:30:37 -0700378 sh script: runTestCli_py( testName, pureTestName, testCategory ), label: ( "Run Test: ./cli.py run " + testName )
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700379 }
380 catchError{
381 sh script: concludeRunTest(), label: "Conclude Running Test: ./cleanup.sh; git clean -df"
382 }
383 catchError{
384 // For the Wiki page
385 sh script: cleanAndCopyFiles( pureTestName ), label: "Clean and Copy Files"
386 }
387 }
388 graphs.databaseAndGraph( prop, testName, pureTestName, graphOnly,
389 graph_generator_file, graph_saved_directory )
390 if ( !graphOnly ){
391 sh script: fetchLogs( pureTestName ), label: "Fetch Logs"
392 if ( !isSCPF ){
393 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
394 prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
395 workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
396 }
397 }
398 }
399 }
400 graphs.postResult( prop, graphOnly, nodeLabel )
401 if ( !graphOnly ){
402 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
403 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
404 isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
405 isSCPF )
406 }
Jeremy Ronquillob8aac442019-07-31 13:28:01 -0700407 } else {
408 echo testName + " is not being run today. Leaving the rest of stage contents blank."
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700409 }
410 }
411 }
412 }
413}
414
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700415def generateGraphs(){
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700416 if ( category != "SCPF" ){
417 // generate the overall graph of the non SCPF tests.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700418 graphs.generateOverallGraph( prop, testsToRun, graphPaths[ "saveDirectory" ], nodeLabel, category )
Jeremy Ronquillobb3001f2019-07-01 12:57:07 -0700419 }
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700420}
421
422def sendToSlack(){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700423 // send the result of the test to the slack when it is not manually running.
424 // start : start time of the test
425 // isManualRun : string that is whether "false" or "true"
426 // branch : branch of the onos.
427
428 try {
429 if ( prop[ "manualRun" ] == "false" ){
430 end = getCurrentTime()
431 TimeDuration duration = TimeCategory.minus( end, start )
432 // FIXME: for now we disable notifications of normal test results
433 /*
434 slackSend( color: "#5816EE",
435 message: category + "-" + prop[ "WikiPrefix" ] + " tests ended at: " + end.toString() +
436 "\nTime took : " + duration )
437 */
438 }
439 }
440 catch ( all ){
441 }
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700442}