blob: 6d98b7e992eac24277b1908dbcfa92062481ce55 [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
65 if ( category == "SCPF" ){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070066 isSCPF = true
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070067 SCPFfuncs.init()
Jeremy Ronquillo442ce4d2019-07-26 16:35:11 -070068 graphs.initialize( SCPFfuncs );
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070069 prop = getProperties()
70 isOldFlow = ( prop[ "isOldFlow" ] == "true" )
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -070071 SCPFfuncs.oldFlowRuleCheck( isOldFlow, prop[ "ONOSBranch" ] )
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -070072 } else {
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070073 isSCPF = false
74 graphs.initialize()
75 prop = getProperties()
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070076 }
77
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070078 // get the list of the test and init branch to it.
79 testsFromList = test_list.getTestsFromCategory( category )
80
81 initGraphPaths()
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070082 tokenizeTokens = "\n;, "
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070083
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070084 if ( testsOverride == "" || testsOverride == null ){
85 testsToRunStrList = prop[ "Tests" ].tokenize( tokenizeTokens )
86 } else {
87 testsToRunStrList = testsOverride.tokenize( tokenizeTokens )
88 }
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -070089 testsToRun = test_list.getTestsFromStringList( testsToRunStrList )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070090}
91
92def readParams(){
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070093 category = params.Category // "FUNC", "HA", "USECASE", etc.
94 branch = params.Branch // "1.15", "2.1", "master", etc.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070095 branchWithPrefix = test_list.addPrefixToBranch( branch )
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -070096 testStation = params.TestStation // "TestStation-BMs", etc.
97 nodeLabel = params.NodeLabel // "BM", "VM", "Fabric-1.x", etc.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070098 testsOverride = params.TestsOverride // "FUNCflow, FUNCintent, [...]", overrides property file
99 isGraphOnly = params.OnlyRefreshGraphs // true or false
100}
101
102def getProperties(){
103 // get the properties of the test by reading the TestONOS.property
104
105 filePath = '''/var/jenkins/TestONOS-''' + category + '''-''' + branchWithPrefix + '''.property'''
106
107 node( testStation ) {
108 return readProperties( file: filePath )
109 }
110}
111
112def getCurrentTime(){
113 // get time of the PST zone.
114
115 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
116 return new Date()
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700117}
118
119def initGraphPaths(){
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700120 graphPaths.put( "trendIndividual", fileRelated.rScriptPaths[ "scripts" ][ "trendIndividual" ] )
Jeremy Ronquilloa8490fb2019-06-26 11:59:50 -0700121 if ( category == "SR" ){
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700122 graphPaths.put( "saveDirectory", fileRelated.workspaces[ "base" ] + "postjob-" + ( testStation - "TestStation-" - "s" ) + "/" )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700123 } else if ( category == "SRHA" ) {
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700124 graphPaths.put( "saveDirectory", fileRelated.workspaces[ "Fabric" ] )
Jeremy Ronquillobb3001f2019-07-01 12:57:07 -0700125 } else if ( category == "SCPF" || category == "USECASE" ){
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700126 graphPaths.put( "saveDirectory", fileRelated.workspaces[ "BM" ] )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700127 } else {
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700128 graphPaths.put( "saveDirectory", fileRelated.workspaces[ "VM" ] )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700129 }
130}
131
132def runTests(){
133 // run the test sequentially and save the function into the dictionary.
134 for ( String test : testsToRun.keySet() ){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700135 toBeRun = test
136 stepName = ( toBeRun ? "" : "Not " ) + "Running $test"
137 pureTestName = ( testsToRun[ test ].containsKey( "test" ) ? testsToRun[ test ][ "test" ].split().head() : test )
138 pipeline[ stepName ] = runTest( test,
139 toBeRun,
140 prop,
141 pureTestName,
142 isGraphOnly,
143 testsToRun,
144 graphPaths[ "trendIndividual" ],
145 graphPaths[ "saveDirectory" ] )
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700146 }
147
148 // get the start time of the test.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700149 start = getCurrentTime()
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700150
151 // run the tests sequentially.
152 for ( test in pipeline.keySet() ){
153 pipeline[ test ].call()
154 }
155}
156
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700157def initTest(){
158 return '''#!/bin/bash -l
159 set -i # interactive
160 set +e
161 shopt -s expand_aliases # expand alias in non-interactive mode
162 export PYTHONUNBUFFERED=1
163 ifconfig
164 echo "ONOS Branch is: $ONOSBranch"
165 echo "TestON Branch is: $TestONBranch"
166 echo "Test date: "
167 date
168 cd ~
169 export PATH=$PATH:onos/tools/test/bin
170 timeout 240 stc shutdown | head -100
171 timeout 240 stc teardown | head -100
172 timeout 240 stc shutdown | head -100
173 cd ~/OnosSystemTest/TestON/bin
174 git log | head
175 ./cleanup.sh -f || true
176 '''
177}
178
179def runTestCli_py( testName, testCategory ){
180 // Bash script that will run the test.
181 // testName : name of the test
182 // testCategory : (SR,FUNC ... )
183
184 return '''cd ~/OnosSystemTest/TestON/bin
185 ./cli.py run ''' +
186 testName +
187 ''' --params GRAPH/nodeCluster=''' + nodeLabel
188}
189
190def concludeRunTest(){
191 return '''cd ~/OnosSystemTest/TestON/bin
192 ./cleanup.sh -f || true
193 # cleanup config changes
194 cd ~/onos/tools/package/config
195 git clean -df'''
196}
197
198def copyLogs(){
199 // bash script to copy the logs and other necessary element for SR tests.
200
201 result = ""
202 if ( category == "SR" ){
203 result = '''
204 sudo rm /var/jenkins/workspace/SR-log-${WikiPrefix}/*
205 sudo cp *karaf.log.* /var/jenkins/workspace/SR-log-${WikiPrefix}/
206 sudo cp *Flows* /var/jenkins/workspace/SR-log-${WikiPrefix}/
207 sudo cp *Groups* /var/jenkins/workspace/SR-log-${WikiPrefix}/
208 sudo cp *.tar.gz /var/jenkins/workspace/SR-log-${WikiPrefix}/
209 sudo cp t3-* /var/jenkins/workspace/SR-log-${WikiPrefix}/
210 '''
211 }
212 return result
213}
214
215def cleanAndCopyFiles( testName ){
216 // clean up some files that were in the folder and copy the new files from the log
217 // testName : name of the test
218
219 return '''#!/bin/bash -i
220 set +e
221 echo "ONOS Branch is: ${ONOSBranch}"
222 echo "TestON Branch is: ${TestONBranch}"
223 echo "Job name is: "''' + testName + '''
224 echo "Workspace is: ${WORKSPACE}/"
225 echo "Wiki page to post is: ${WikiPrefix}-"
226 # remove any leftover files from previous tests
227 sudo rm ${WORKSPACE}/*Wiki.txt
228 sudo rm ${WORKSPACE}/*Summary.txt
229 sudo rm ${WORKSPACE}/*Result.txt
230 sudo rm ${WORKSPACE}/*Alarm.txt || true
231 sudo rm ${WORKSPACE}/*.csv
232 #copy files to workspace
233 cd `ls -t ~/OnosSystemTest/TestON/logs/*/ | head -1 | sed 's/://'`
234 ''' + copyLogs() + '''
235 sudo cp *.txt ${WORKSPACE}/
236 sudo cp *.csv ${WORKSPACE}/
237 cd ${WORKSPACE}/
238 for i in *.csv
239 do mv "$i" "$WikiPrefix"-"$i"
240 done
241 ls -al
242 cd '''
243}
244
245def fetchLogs( testName ){
246 // fetch the logs of onos from onos nodes to onos System Test logs
247 // testName: name of the test
248
249 return '''#!/bin/bash
250 set +e
251 cd ~/OnosSystemTest/TestON/logs
252 echo "TestON test name is: "''' + testName + '''
253 TestONlogDir=$(ls -t | grep ${TEST_NAME}_ |head -1)
254 echo "########################################################################################"
255 echo "##### copying ONOS logs from all nodes to TestON/logs directory: ${TestONlogDir}"
256 echo "########################################################################################"
257 cd $TestONlogDir
258 if [ $? -eq 1 ]
259 then
260 echo "Job name does not match any test suite name to move log!"
261 else
262 pwd
263 for i in $OC{1..7}; do onos-fetch-logs $i || echo log does not exist for onos $i; done
264 for i in $OC{1..7}; do atomix-fetch-logs $i || echo log does not exist for atomix $i; done
265 fi
266 cd'''
267}
268
Jeremy Ronquilloe4e83912019-07-29 12:58:48 -0700269def isPostingResult( manual, postresult ){
270 // check if it is posting the result.
271 // posting when it is automatically running or has postResult condition from the manual run
272
273 return manual == "false" || postresult == "true"
274}
275
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700276def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
277 // publish HTML script to wiki confluence
278 // isManualRun : string "true" "false"
279 // isPostResult : string "true" "false"
280 // wikiLink : link of the wiki page to publish
281 // file : name of the file to be published
282
283 if ( isPostingResult( isManualRun, isPostResult ) ){
284 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
285 attachArchivedArtifacts: true, buildIfUnstable: true,
286 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
287 }
288}
289
290def postLogs( testName, prefix ){
291 // posting logs of the onos jobs specifically SR tests
292 // testName : name of the test
293 // prefix : branch prefix ( master, 2.1, 1.15 ... )
294
295 resultURL = ""
296 if ( category == "SR" ){
297 def post = build job: "SR-log-" + prefix, propagate: false
298 resultURL = post.getAbsoluteUrl()
299 }
300 return resultURL
301}
302
303def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
304 // analyzing the result of the test and send to slack if any abnormal result is logged.
305 // prop : property dictionary
306 // workSpace : workSpace where the result file is saved
307 // pureTestName : TestON name of the test
308 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
309 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
310 // wikiLink : link of the wiki page where the result was posted
311 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
312
313 node( testStation ) {
314 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
315 if ( fileExists( alarmFile ) ) {
316 def alarmContents = readFile( alarmFile )
317 slackSend( channel: "#jenkins-related",
318 color: "FF0000",
319 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
320 alarmContents + "\n" +
321 "[TestON log] : \n" +
322 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
323 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
324 "https://wiki.onosproject.org/display/ONOS/" +
325 wikiLink.replaceAll( "\\s", "+" ) ) ) +
326 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
327 resultURL + "artifact/" ) : "" ),
328 teamDomain: 'onosproject' )
Jeremy Ronquilloe4e83912019-07-29 12:58:48 -0700329 print "Abnormal test result."
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700330 throw new Exception( "Abnormal test result." )
331 }
332 else {
333 print "Test results are OK."
334 }
335 }
336}
337
338def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
339 graph_saved_directory ){
340 // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
341 // testName : name of the test in Jenkins
342 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
343 // result on pipeline view
344 // prop : dictionary property on the machine
345 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
346 // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
347 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
348 // graph_generator_file : Rscript file with the full path.
349 // graph_saved_directory : where the generated graph will be saved to.
350
351 return {
352 catchError {
353 stage( testName ) {
354 if ( toBeRun ){
355 def workSpace = "/var/jenkins/workspace/" + testName
356 def fileContents = ""
357 node( testStation ) {
358 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
359 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
360 'TestONBranch=' + prop[ "TestONBranch" ],
361 'ONOSTag=' + prop[ "ONOSTag" ],
362 'WikiPrefix=' + prop[ "WikiPrefix" ],
363 'WORKSPACE=' + workSpace ] ) {
364 if ( !graphOnly ){
365 if ( isSCPF ){
366 // Remove the old database file
367 sh SCPFfuncs.cleanupDatabaseFile( testName )
368 }
369 sh script: initTest(), label: "Test Initialization: stc shutdown; stc teardown; ./cleanup.sh"
370 catchError{
371 sh script: runTestCli_py( testName, testCategory ), label: ( "Run Test: ./cli.py run " + testName )
372 }
373 catchError{
374 sh script: concludeRunTest(), label: "Conclude Running Test: ./cleanup.sh; git clean -df"
375 }
376 catchError{
377 // For the Wiki page
378 sh script: cleanAndCopyFiles( pureTestName ), label: "Clean and Copy Files"
379 }
380 }
381 graphs.databaseAndGraph( prop, testName, pureTestName, graphOnly,
382 graph_generator_file, graph_saved_directory )
383 if ( !graphOnly ){
384 sh script: fetchLogs( pureTestName ), label: "Fetch Logs"
385 if ( !isSCPF ){
386 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
387 prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
388 workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
389 }
390 }
391 }
392 }
393 graphs.postResult( prop, graphOnly, nodeLabel )
394 if ( !graphOnly ){
395 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
396 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
397 isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
398 isSCPF )
399 }
400 }
401 }
402 }
403 }
404}
405
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700406def generateGraphs(){
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700407 if ( category != "SCPF" ){
408 // generate the overall graph of the non SCPF tests.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700409 graphs.generateOverallGraph( prop, testsToRun, graphPaths[ "saveDirectory" ], nodeLabel, category )
Jeremy Ronquillobb3001f2019-07-01 12:57:07 -0700410 }
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700411}
412
413def sendToSlack(){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700414 // send the result of the test to the slack when it is not manually running.
415 // start : start time of the test
416 // isManualRun : string that is whether "false" or "true"
417 // branch : branch of the onos.
418
419 try {
420 if ( prop[ "manualRun" ] == "false" ){
421 end = getCurrentTime()
422 TimeDuration duration = TimeCategory.minus( end, start )
423 // FIXME: for now we disable notifications of normal test results
424 /*
425 slackSend( color: "#5816EE",
426 message: category + "-" + prop[ "WikiPrefix" ] + " tests ended at: " + end.toString() +
427 "\nTime took : " + duration )
428 */
429 }
430 }
431 catch ( all ){
432 }
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700433}