blob: ae8c2bc67bab0a9bb60528f60e074d1c8a7c601a [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
269def publishToConfluence( isManualRun, isPostResult, wikiLink, file ){
270 // publish HTML script to wiki confluence
271 // isManualRun : string "true" "false"
272 // isPostResult : string "true" "false"
273 // wikiLink : link of the wiki page to publish
274 // file : name of the file to be published
275
276 if ( isPostingResult( isManualRun, isPostResult ) ){
277 publishConfluence siteName: 'wiki.onosproject.org', pageName: wikiLink, spaceName: 'ONOS',
278 attachArchivedArtifacts: true, buildIfUnstable: true,
279 editorList: [ confluenceWritePage( confluenceFile( file ) ) ]
280 }
281}
282
283def postLogs( testName, prefix ){
284 // posting logs of the onos jobs specifically SR tests
285 // testName : name of the test
286 // prefix : branch prefix ( master, 2.1, 1.15 ... )
287
288 resultURL = ""
289 if ( category == "SR" ){
290 def post = build job: "SR-log-" + prefix, propagate: false
291 resultURL = post.getAbsoluteUrl()
292 }
293 return resultURL
294}
295
296def analyzeResult( prop, workSpace, pureTestName, testName, resultURL, wikiLink, isSCPF ){
297 // analyzing the result of the test and send to slack if any abnormal result is logged.
298 // prop : property dictionary
299 // workSpace : workSpace where the result file is saved
300 // pureTestName : TestON name of the test
301 // testName : Jenkins name of the test. Example: SCPFflowTPFobj
302 // resultURL : url for the logs for SR tests. Will not be posted if it is empty
303 // wikiLink : link of the wiki page where the result was posted
304 // isSCPF : Check if it is SCPF. If so, it won't post the wiki link.
305
306 node( testStation ) {
307 def alarmFile = workSpace + "/" + pureTestName + "Alarm.txt"
308 if ( fileExists( alarmFile ) ) {
309 def alarmContents = readFile( alarmFile )
310 slackSend( channel: "#jenkins-related",
311 color: "FF0000",
312 message: "[" + prop[ "ONOSBranch" ] + "]" + testName + " : triggered alarms:\n" +
313 alarmContents + "\n" +
314 "[TestON log] : \n" +
315 "https://jenkins.onosproject.org/blue/organizations/jenkins/${ env.JOB_NAME }/detail/${ env.JOB_NAME }/${ env.BUILD_NUMBER }/pipeline" +
316 ( isSCPF ? "" : ( "\n[Result on Wiki] : \n" +
317 "https://wiki.onosproject.org/display/ONOS/" +
318 wikiLink.replaceAll( "\\s", "+" ) ) ) +
319 ( resultURL != "" ? ( "\n[Karaf log] : \n" +
320 resultURL + "artifact/" ) : "" ),
321 teamDomain: 'onosproject' )
322 throw new Exception( "Abnormal test result." )
323 }
324 else {
325 print "Test results are OK."
326 }
327 }
328}
329
330def runTest( testName, toBeRun, prop, pureTestName, graphOnly, testCategory, graph_generator_file,
331 graph_saved_directory ){
332 // run the test on the machine that contains all the steps : init and run test, copy files, publish result ...
333 // testName : name of the test in Jenkins
334 // toBeRun : boolean value whether the test will be run or not. If not, it won't be run but shows up with empty
335 // result on pipeline view
336 // prop : dictionary property on the machine
337 // pureTestName : Pure name of the test. ( ex. pureTestName of SCPFflowTpFobj will be SCPFflowTp )
338 // graphOnly : check if it is generating graph job. If so, it will only generate the generating graph part
339 // testCategory : Map for the test suit ( SCPF, SR, FUNC, ... ) which contains information about the tests
340 // graph_generator_file : Rscript file with the full path.
341 // graph_saved_directory : where the generated graph will be saved to.
342
343 return {
344 catchError {
345 stage( testName ) {
346 if ( toBeRun ){
347 def workSpace = "/var/jenkins/workspace/" + testName
348 def fileContents = ""
349 node( testStation ) {
350 withEnv( [ 'ONOSBranch=' + prop[ "ONOSBranch" ],
351 'ONOSJAVAOPTS=' + prop[ "ONOSJAVAOPTS" ],
352 'TestONBranch=' + prop[ "TestONBranch" ],
353 'ONOSTag=' + prop[ "ONOSTag" ],
354 'WikiPrefix=' + prop[ "WikiPrefix" ],
355 'WORKSPACE=' + workSpace ] ) {
356 if ( !graphOnly ){
357 if ( isSCPF ){
358 // Remove the old database file
359 sh SCPFfuncs.cleanupDatabaseFile( testName )
360 }
361 sh script: initTest(), label: "Test Initialization: stc shutdown; stc teardown; ./cleanup.sh"
362 catchError{
363 sh script: runTestCli_py( testName, testCategory ), label: ( "Run Test: ./cli.py run " + testName )
364 }
365 catchError{
366 sh script: concludeRunTest(), label: "Conclude Running Test: ./cleanup.sh; git clean -df"
367 }
368 catchError{
369 // For the Wiki page
370 sh script: cleanAndCopyFiles( pureTestName ), label: "Clean and Copy Files"
371 }
372 }
373 graphs.databaseAndGraph( prop, testName, pureTestName, graphOnly,
374 graph_generator_file, graph_saved_directory )
375 if ( !graphOnly ){
376 sh script: fetchLogs( pureTestName ), label: "Fetch Logs"
377 if ( !isSCPF ){
378 publishToConfluence( prop[ "manualRun" ], prop[ "postResult" ],
379 prop[ "WikiPrefix" ] + "-" + testCategory[ testName ][ 'wikiName' ],
380 workSpace + "/" + testCategory[ testName ][ 'wikiFile' ] )
381 }
382 }
383 }
384 }
385 graphs.postResult( prop, graphOnly, nodeLabel )
386 if ( !graphOnly ){
387 def resultURL = postLogs( testName, prop[ "WikiPrefix" ] )
388 analyzeResult( prop, workSpace, pureTestName, testName, resultURL,
389 isSCPF ? "" : testCategory[ testName ][ 'wikiName' ],
390 isSCPF )
391 }
392 }
393 }
394 }
395 }
396}
397
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700398def generateGraphs(){
Jeremy Ronquillo06950992019-07-09 11:16:49 -0700399 if ( category != "SCPF" ){
400 // generate the overall graph of the non SCPF tests.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700401 graphs.generateOverallGraph( prop, testsToRun, graphPaths[ "saveDirectory" ], nodeLabel, category )
Jeremy Ronquillobb3001f2019-07-01 12:57:07 -0700402 }
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700403}
404
405def sendToSlack(){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700406 // send the result of the test to the slack when it is not manually running.
407 // start : start time of the test
408 // isManualRun : string that is whether "false" or "true"
409 // branch : branch of the onos.
410
411 try {
412 if ( prop[ "manualRun" ] == "false" ){
413 end = getCurrentTime()
414 TimeDuration duration = TimeCategory.minus( end, start )
415 // FIXME: for now we disable notifications of normal test results
416 /*
417 slackSend( color: "#5816EE",
418 message: category + "-" + prop[ "WikiPrefix" ] + " tests ended at: " + end.toString() +
419 "\nTime took : " + duration )
420 */
421 }
422 }
423 catch ( all ){
424 }
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700425}