blob: ac60785d37874bc6b0c372c5d8ab58000d0bae00 [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 Ronquillob8aac442019-07-31 13:28:01 -0700143 pureTestName = ( testsFromList[ test ].containsKey( "test" ) ? testsFromList[ test ][ "test" ].split().head() : 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
185def runTestCli_py( testName, testCategory ){
186 // Bash script that will run the test.
187 // testName : name of the test
188 // testCategory : (SR,FUNC ... )
189
190 return '''cd ~/OnosSystemTest/TestON/bin
191 ./cli.py run ''' +
192 testName +
193 ''' --params GRAPH/nodeCluster=''' + nodeLabel
194}
195
196def concludeRunTest(){
197 return '''cd ~/OnosSystemTest/TestON/bin
198 ./cleanup.sh -f || true
199 # cleanup config changes
200 cd ~/onos/tools/package/config
201 git clean -df'''
202}
203
204def copyLogs(){
205 // bash script to copy the logs and other necessary element for SR tests.
206
207 result = ""
208 if ( category == "SR" ){
209 result = '''
210 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
211 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
212 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
213 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
214 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
215 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
216 '''
217 }
218 return result
219}
220
221def cleanAndCopyFiles( testName ){
222 // clean up some files that were in the folder and copy the new files from the log
223 // testName : name of the test
224
225 return '''#!/bin/bash -i
226 set +e
227 echo "ONOS Branch is: ${ONOSBranch}"
228 echo "TestON Branch is: ${TestONBranch}"
229 echo "Job name is: "''' + testName + '''
230 echo "Workspace is: ${WORKSPACE}/"
231 echo "Wiki page to post is: ${WikiPrefix}-"
232 # remove any leftover files from previous tests
233 sudo rm ${WORKSPACE}/*Wiki.txt
234 sudo rm ${WORKSPACE}/*Summary.txt
235 sudo rm ${WORKSPACE}/*Result.txt
236 sudo rm ${WORKSPACE}/*Alarm.txt || true
237 sudo rm ${WORKSPACE}/*.csv
238 #copy files to workspace
239 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
240 ''' + copyLogs() + '''
241 sudo cp *.txt ${WORKSPACE}/
242 sudo cp *.csv ${WORKSPACE}/
243 cd ${WORKSPACE}/
244 for i in *.csv
245 do mv "$i" "$WikiPrefix"-"$i"
246 done
247 ls -al
248 cd '''
249}
250
251def fetchLogs( testName ){
252 // fetch the logs of onos from onos nodes to onos System Test logs
253 // testName: name of the test
254
255 return '''#!/bin/bash
256 set +e
257 cd ~/OnosSystemTest/TestON/logs
258 echo "TestON test name is: "''' + testName + '''
259 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
260 echo "########################################################################################"
261 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
262 echo "########################################################################################"
263 cd $TestONlogDir
264 if [ $? -eq 1 ]
265 then
266 echo "Job name does not match any test suite name to move log!"
267 else
268 pwd
269 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
270 for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done
271 fi
272 cd'''
273}
274
Jeremy Ronquilloe4e83912019-07-29 12:58:48 -0700275def isPostingResult( manual, postresult ){
276 // check if it is posting the result.
277 // posting when it is automatically running or has postResult condition from the manual run
278
279 return manual == "false" || postresult == "true"
280}
281
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700282def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
283 // publish HTML script to wiki confluence
284 // isManualRun : string "true" "false"
285 // isPostResult : string "true" "false"
286 // wikiLink : link of the wiki page to publish
287 // file : name of the file to be published
288
289 if ( isPostingResult( isManualRun, isPostResult ) ){
290 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
291 attachArchivedArtifacts: true, buildIfUnstable: true,
292 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
293 }
294}
295
296def postLogs( testName, prefix ){
297 // posting logs of the onos jobs specifically SR tests
298 // testName : name of the test
299 // prefix : branch prefix ( master, 2.1, 1.15 ... )
300
301 resultURL = ""
302 if ( category == "SR" ){
303 def post = build job: "SR-log-" + prefix, propagate: false
304 resultURL = post.getAbsoluteUrl()
305 }
306 return resultURL
307}
308
309def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
310 // analyzing the result of the test and send to slack if any abnormal result is logged.
311 // prop : property dictionary
312 // workSpace : workSpace where the result file is saved
313 // pureTestName : TestON name of the test
314 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
315 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
316 // wikiLink : link of the wiki page where the result was posted
317 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
318
319 node( testStation ) {
320 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
321 if ( fileExists( alarmFile ) ) {
322 def alarmContents = readFile( alarmFile )
323 slackSend( channel: "#jenkins-related",
324 color: "FF0000",
325 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
326 alarmContents + "\n" +
327 "[TestON log] : \n" +
328 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
329 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
330 "https://wiki.onosproject.org/display/ONOS/" +
331 wikiLink.replaceAll( "\\s", "+" ) ) ) +
332 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
333 resultURL + "artifact/" ) : "" ),
334 teamDomain: 'onosproject' )
Jeremy Ronquilloe4e83912019-07-29 12:58:48 -0700335 print "Abnormal test result."
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700336 throw new Exception( "Abnormal test result." )
337 }
338 else {
339 print "Test results are OK."
340 }
341 }
342}
343
344def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
345 graph_saved_directory ){
346 // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
347 // testName : name of the test in Jenkins
348 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
349 // result on pipeline view
350 // prop : dictionary property on the machine
351 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
352 // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
353 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
354 // graph_generator_file : Rscript file with the full path.
355 // graph_saved_directory : where the generated graph will be saved to.
356
357 return {
358 catchError {
359 stage( testName ) {
360 if ( toBeRun ){
361 def workSpace = "/var/jenkins/workspace/" + testName
362 def fileContents = ""
363 node( testStation ) {
364 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
365 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
366 'TestONBranch=' + prop[ "TestONBranch" ],
367 'ONOSTag=' + prop[ "ONOSTag" ],
368 'WikiPrefix=' + prop[ "WikiPrefix" ],
369 'WORKSPACE=' + workSpace ] ) {
370 if ( !graphOnly ){
371 if ( isSCPF ){
372 // Remove the old database file
373 sh SCPFfuncs.cleanupDatabaseFile( testName )
374 }
375 sh script: initTest(), label: "Test Initialization: stc shutdown; stc teardown; ./cleanup.sh"
376 catchError{
377 sh script: runTestCli_py( testName, testCategory ), label: ( "Run Test: ./cli.py run " + testName )
378 }
379 catchError{
380 sh script: concludeRunTest(), label: "Conclude Running Test: ./cleanup.sh; git clean -df"
381 }
382 catchError{
383 // For the Wiki page
384 sh script: cleanAndCopyFiles( pureTestName ), label: "Clean and Copy Files"
385 }
386 }
387 graphs.databaseAndGraph( prop, testName, pureTestName, graphOnly,
388 graph_generator_file, graph_saved_directory )
389 if ( !graphOnly ){
390 sh script: fetchLogs( pureTestName ), label: "Fetch Logs"
391 if ( !isSCPF ){
392 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
393 prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
394 workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
395 }
396 }
397 }
398 }
399 graphs.postResult( prop, graphOnly, nodeLabel )
400 if ( !graphOnly ){
401 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
402 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
403 isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
404 isSCPF )
405 }
Jeremy Ronquillob8aac442019-07-31 13:28:01 -0700406 } else {
407 echo testName + " is not being run today. Leaving the rest of stage contents blank."
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700408 }
409 }
410 }
411 }
412}
413
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700414def generateGraphs(){
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700415 if ( category != "SCPF" ){
416 // generate the overall graph of the non SCPF tests.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700417 graphs.generateOverallGraph( prop, testsToRun, graphPaths[ "saveDirectory" ], nodeLabel, category )
Jeremy Ronquillobb3001f2019-07-01 12:57:07 -0700418 }
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700419}
420
421def sendToSlack(){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700422 // send the result of the test to the slack when it is not manually running.
423 // start : start time of the test
424 // isManualRun : string that is whether "false" or "true"
425 // branch : branch of the onos.
426
427 try {
428 if ( prop[ "manualRun" ] == "false" ){
429 end = getCurrentTime()
430 TimeDuration duration = TimeCategory.minus( end, start )
431 // FIXME: for now we disable notifications of normal test results
432 /*
433 slackSend( color: "#5816EE",
434 message: category + "-" + prop[ "WikiPrefix" ] + " tests ended at: " + end.toString() +
435 "\nTime took : " + duration )
436 */
437 }
438 }
439 catch ( all ){
440 }
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700441}