blob: c0958109755c0376656a726e0b414003a625717e [file] [log] [blame]
Devin Lime1346f42018-05-15 15:41:36 -07001#!groovy
Jeremy Ronquillo6fbfdd52019-07-09 13:49:34 -07002// Copyright 2019 Open Networking Foundation (ONF)
Devin Limf5175192018-05-14 19:13:22 -07003//
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 Ronquillo6fbfdd52019-07-09 13:49:34 -070021// This is the Jenkins script for master-trigger
Devin Limf5175192018-05-14 19:13:22 -070022
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070023import groovy.time.TimeCategory
24import groovy.time.TimeDuration
25
Devin Limf5175192018-05-14 19:13:22 -070026// set the functions of the dependencies.
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070027graphs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsGraphs.groovy' )
Devin Limb734ea52018-05-14 14:13:05 -070028fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070029test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
Devin Lim2edfcec2018-05-09 17:16:21 -070030
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070031onos_tag = null
32manually_run = null
33now = null
34today = null
35onos_branches = null
36day = null
37post_result = null
38branchesParam = null
39isFabric = null
40testsParam = null
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -070041simulateDay = null
Jeremy Ronquillo4fd82442019-05-21 20:56:58 -070042
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070043dayMap = [:]
44fullDayMap = [:]
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070045all_testcases = [:]
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070046runTest = [:]
47selectedTests = [:]
48graphPaths = [:]
Devin Lim2edfcec2018-05-09 17:16:21 -070049
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070050main()
Devin Limf5175192018-05-14 19:13:22 -070051
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070052def main() {
53 init()
54 runTests()
55 generateGraphs()
56}
57
58// **************
59// Initialization
60// **************
61
62// initialize file scope vars
63def init(){
64 // get the name of the job.
65 jobName = env.JOB_NAME
66
67 // set the versions of the onos
68 fileRelated.init()
69 test_list.init()
70 readParams()
71
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070072 // list of the tests to be run will be saved in each choices.
73 day = ""
74
75 initDates()
76 onos_branches = getONOSBranches()
77 selectedTests = getONOSTests()
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -070078
Jeremy Ronquillod98c2a12019-06-07 15:13:29 -070079 initGraphPaths()
80
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -070081 echo "selectedTests: " + selectedTests
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -070082 echo "onos_branches: " + onos_branches
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070083}
84
85def readParams(){
86 // get post result from the params for manually run.
87 post_result = params.PostResult
88 manually_run = params.manual_run
89 onos_tag = params.ONOSTag
90 branchesParam = params.branches
Jeremy Ronquillo336110a2019-07-11 14:20:40 -070091 isOldFlow = true // hardcoding to true since we are always using oldFlow.
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070092 testsParam = params.Tests
93 isFabric = params.isFabric
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -070094 simulateDay = params.simulate_day
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070095}
Devin Lim2edfcec2018-05-09 17:16:21 -070096
97// Set tests based on day of week
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070098def initDates(){
99 echo "-> initDates()"
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700100 now = getCurrentTime()
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700101 dayMap = [ ( Calendar.MONDAY ) : "mon",
102 ( Calendar.TUESDAY ) : "tue",
103 ( Calendar.WEDNESDAY ) : "wed",
104 ( Calendar.THURSDAY ) : "thu",
105 ( Calendar.FRIDAY ) : "fri",
106 ( Calendar.SATURDAY ) : "sat",
107 ( Calendar.SUNDAY ) : "sun" ]
108 fullDayMap = [ ( Calendar.MONDAY ) : "Monday",
109 ( Calendar.TUESDAY ) : "Tuesday",
110 ( Calendar.WEDNESDAY ) : "Wednesday",
111 ( Calendar.THURSDAY ) : "Thursday",
112 ( Calendar.FRIDAY ) : "Friday",
113 ( Calendar.SATURDAY ) : "Saturday",
114 ( Calendar.SUNDAY ) : "Sunday" ]
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -0700115 if ( simulateDay == "" ){
116 today = now[ Calendar.DAY_OF_WEEK ]
117 day = dayMap[ today ]
118 print now.toString()
119 } else {
120 day = simulateDay
121 }
Jon Hall6af749d2018-05-29 12:59:47 -0700122}
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700123
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700124def getCurrentTime(){
125 // get time of the PST zone.
126
127 TimeZone.setDefault( TimeZone.getTimeZone( 'PST' ) )
128 return new Date()
129}
130
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700131// gets ONOS branches from params or string parameter
132def getONOSBranches(){
133 echo "-> getONOSBranches()"
134 if ( manually_run ){
135 return branchesParam.tokenize( "\n;, " )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700136 } else {
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -0700137 return test_list.getBranchesFromDay( day )
Devin Lim2edfcec2018-05-09 17:16:21 -0700138 }
139}
Devin Limf5175192018-05-14 19:13:22 -0700140
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700141def getONOSTests(){
142 echo "-> getONOSTests()"
143 if ( manually_run ){
144 return test_list.getTestsFromStringList( testsParam.tokenize( "\n;, " ) )
145 } else {
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -0700146
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700147 return test_list.getTestsFromDay( day )
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700148 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700149}
Devin Limf5175192018-05-14 19:13:22 -0700150
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700151// init paths for the files and directories.
152def initGraphPaths(){
Jeremy Ronquillo1e5d7f22019-07-17 14:18:42 -0700153 graphPaths.put( "histogramMultiple", fileRelated.rScriptPaths[ "scripts" ][ "histogramMultiple" ] )
154 graphPaths.put( "pieMultiple", fileRelated.rScriptPaths[ "scripts" ][ "pieMultiple" ] )
155 graphPaths.put( "saveDirectory", fileRelated.workspaces[ "VM" ] )
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700156}
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700157
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700158// **********************
159// Determine Tests to Run
160// **********************
161
162def printTestsToRun( runList ){
163 if ( manually_run ){
164 println "Tests to be run manually:"
165 } else {
166 if ( isFabric ){
167 postToSlackSR()
Devin Lim2edfcec2018-05-09 17:16:21 -0700168 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700169 if ( today == Calendar.MONDAY ){
170 postToSlackTestsToRun()
171 }
172 println "Defaulting to " + day + " tests:"
Devin Lim2edfcec2018-05-09 17:16:21 -0700173 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700174 for ( list in runList ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700175 echo "" + list
176 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700177}
Devin Limf5175192018-05-14 19:13:22 -0700178
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700179def postToSlackSR(){
180 // If it is automated running, it will post the beginning message to the channel.
181 slackSend( channel: 'sr-failures', color: '#03CD9F',
182 message: ":sparkles:" * 16 + "\n" +
183 "Starting tests on : " + now.toString() +
184 "\n" + ":sparkles:" * 16 )
185}
186
187def postToSlackTestsToRun(){
188 slackSend( color: '#FFD988',
189 message: "Tests to be run this weekdays : \n" +
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700190 printDaysForTest() )
191}
192
193def printDaysForTest(){
194 // Print the days for what test has.
195 AllTheTests = test_list.getAllTests()
196
197 result = ""
198 for ( String test in AllTheTests.keySet() ){
199 result += test + ": ["
200 test_schedule = AllTheTests[ test ][ "schedules" ]
201 for ( String sch_dict in test_schedule ){
202 for ( String day in test_list.convertScheduleKeyToDays( sch_dict[ "branch" ] ) ){
203 result += day + " "
204 }
205 }
206 result += "]\n"
207 }
208 return result
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700209}
210
211// *********
212// Run Tests
213// *********
214
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700215def tagCheck( onos_tag, onos_branch ){
216 // check the tag for onos if it is not empty
217
218 result = "git checkout "
219 if ( onos_tag == "" ){
220 //create new local branch
221 result += onos_branch
222 }
223 else {
224 //checkout the tag
225 result += onos_tag
226 }
227 return result
228}
229
230def preSetup( onos_branch, test_branch, onos_tag, isManual ){
231 // pre setup part which will clean up and checkout to corresponding branch.
232
233 result = ""
234 if ( !isManual ){
235 result = '''echo -e "\n##### Set TestON Branch #####"
236 echo "TestON Branch is set on: ''' + test_branch + '''"
237 cd ~/OnosSystemTest/
238 git checkout HEAD~1 # Make sure you aren't pn a branch
239 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
240 git branch -D ''' + test_branch + ''' # just in case there are local changes. This will normally result in a branch not found error
241 git clean -df # clean any local files
242 git fetch --all # update all caches from remotes
243 git reset --hard origin/''' + test_branch + ''' # force local index to match remote branch
244 git clean -df # clean any local files
245 git checkout ''' + test_branch + ''' #create new local branch
246 git branch
247 git log -1 --decorate
248 echo -e "\n##### Set ONOS Branch #####"
249 echo "ONOS Branch is set on: ''' + onos_branch + '''"
250 echo -e "\n #### check karaf version ######"
251 env |grep karaf
252 cd ~/onos
253 git checkout HEAD~1 # Make sure you aren't pn a branch
254 git branch | grep -v "detached from" | xargs git branch -d # delete all local branches merged with remote
255 git branch -D ''' + onos_branch + ''' # just incase there are local changes. This will normally result in a branch not found error
256 git clean -df # clean any local files
257 git fetch --all # update all caches from remotes
258 git reset --hard origin/''' + onos_branch + ''' # force local index to match remote branch
259 git clean -df # clean any local files
260 rm -rf buck-out
261 rm -rf bazel-*
262 ''' + tagCheck( onos_tag, onos_branch ) + '''
263 git branch
264 git log -1 --decorate
265 echo -e "\n##### set jvm heap size to 8G #####"
266 echo ${ONOSJAVAOPTS}
267 inserted_line="export JAVA_OPTS=\"\${ONOSJAVAOPTS}\""
268 sed -i "s/bash/bash\\n$inserted_line/" ~/onos/tools/package/bin/onos-service
269 echo "##### Check onos-service setting..... #####"
270 cat ~/onos/tools/package/bin/onos-service
271 export JAVA_HOME=/usr/lib/jvm/java-8-oracle'''
272 } else {
273 result = '''echo "Since this is a manual run, we'll use the current ONOS and TestON branch:"
274 echo "ONOS branch:"
275 cd ~/OnosSystemTest/
276 git branch
277 echo "TestON branch:"
278 cd ~/TestON/
279 git branch'''
280 }
281 return result
282}
283
284def postSetup( onos_branch, test_branch, onos_tag, isManual ){
285 // setup that will build ONOS
286
287 result = ""
288 if ( !isManual ){
289 result = '''echo -e "Installing bazel"
290 cd ~
291 rm -rf ci-management
292 git clone https://gerrit.onosproject.org/ci-management
293 cd ci-management/jjb/onos/
294 export GERRIT_BRANCH="''' + onos_branch + '''"
295 chmod +x install-bazel.sh
296 ./install-bazel.sh
297 '''
298 } else {
299 result = '''echo -e "Since this is a manual run, we will not install Bazel."'''
300 }
301 return result
302}
303
304def generateKey(){
305 // generate cluster-key of the onos
306
307 try {
308 sh script: '''
309 #!/bin/bash -l
310 set +e
311 . ~/.bashrc
312 env
313 onos-push-bits-through-proxy
314 onos-gen-cluster-key -f
315 ''', label: "Generate Cluster Key", returnStdout: false
316 } catch ( all ){
317 }
318}
319
320// Initialize the environment Setup for the onos and OnosSystemTest
321def envSetup( onos_branch, test_branch, onos_tag, jobOn, manuallyRun, nodeLabel ){
322 // to setup the environment using the bash script
323 stage( "Environment Setup: " + onos_branch + "-" + nodeLabel + "-" + jobOn ) {
324 // after env: ''' + borrow_mn( jobOn ) + '''
325 sh script: '''#!/bin/bash -l
326 set +e
327 . ~/.bashrc
328 env
329 ''' + preSetup( onos_branch, test_branch, onos_tag, manuallyRun ), label: "Repo Setup", returnStdout: false
330 sh script: postSetup( onos_branch, test_branch, onos_tag, manuallyRun ), label: "Install Bazel", returnStdout: false
331 generateKey()
332 }
333}
334
335// export Environment properties.
336def exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, postResult, manually_run, onosTag, isOldFlow, nodeLabel ){
337 // export environment properties to the machine.
338
339 filePath = "/var/jenkins/TestONOS-" + jobOn + "-" + onos_branch + ".property"
340
341 stage( "Property Export: " + onos_branch + "-" + nodeLabel + "-" + jobOn ) {
342 sh script: '''
343 echo "ONOSBranch=''' + onos_branch + '''" > ''' + filePath + '''
344 echo "TestONBranch=''' + test_branch + '''" >> ''' + filePath + '''
345 echo "ONOSTag=''' + onosTag + '''" >> ''' + filePath + '''
346 echo "WikiPrefix=''' + wiki + '''" >> ''' + filePath + '''
347 echo "ONOSJAVAOPTS=''' + env.ONOSJAVAOPTS + '''" >> ''' + filePath + '''
348 echo "Tests=''' + tests + '''" >> ''' + filePath + '''
349 echo "postResult=''' + postResult + '''" >> ''' + filePath + '''
350 echo "manualRun=''' + manually_run + '''" >> ''' + filePath + '''
351 echo "isOldFlow=''' + isOldFlow + '''" >> ''' + filePath + '''
352 ''', label: "Exporting Property File: " + filePath
353 }
354}
355
356def trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
357 // triggering function that will setup the environment and determine which pipeline to trigger
358
359 println "Job name: " + jobOn + "-pipeline-" + ( manuallyRun ? "manually" : branch )
360 def wiki = branch
361 def onos_branch = test_list.addPrefixToBranch( branch )
362 def test_branch = test_list.addPrefixToBranch( branch )
363 assignedNode = null
364 node( label: nodeLabel ) {
365
366 envSetup( onos_branch, test_branch, onosTag, jobOn, manuallyRun, nodeLabel )
367 exportEnvProperty( onos_branch, test_branch, jobOn, wiki, tests, post_result, manuallyRun, onosTag, isOldFlow, nodeLabel )
368 assignedNode = env.NODE_NAME
369 }
370
371 jobToRun = jobOn + "-pipeline-" + ( manuallyRun ? "manually" : wiki )
372 build job: jobToRun, propagate: false, parameters: [ [ $class: 'StringParameterValue', name: 'Category', value: jobOn ],
373 [ $class: 'StringParameterValue', name: 'Branch', value: branch ],
374 [ $class: 'StringParameterValue', name: 'TestStation', value: assignedNode ],
375 [ $class: 'StringParameterValue', name: 'NodeLabel', value: nodeLabel ] ]
376}
377
378def trigger_pipeline( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag ){
379 // nodeLabel : nodeLabel from tests.json
380 // jobOn : "SCPF" or "USECASE" or "FUNC" or "HA"
381 // this will return the function by wrapping them up with return{} to prevent them to be
382 // executed once this function is called to assign to specific variable.
383 return {
384 trigger( branch, tests, nodeLabel, jobOn, manuallyRun, onosTag )
385 }
386}
387
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700388def generateRunList(){
389 runList = [:]
Jeremy Ronquilloedb663b2019-06-26 14:09:38 -0700390 validSchedules = test_list.getValidSchedules( day )
391 echo "validSchedules: " + validSchedules
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700392 for ( branch in onos_branches ){
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700393 runBranch = []
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700394 nodeLabels = test_list.getAllNodeLabels( branch, selectedTests )
395 for ( nodeLabel in nodeLabels ){
396 selectedNodeLabelTests = test_list.getTestsFromNodeLabel( nodeLabel, branch, selectedTests )
397 selectedNodeLabelCategories = test_list.getAllTestCategories( selectedNodeLabelTests )
398 for ( category in selectedNodeLabelCategories ){
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700399 selectedNodeLabelCategoryTests = test_list.getTestsFromCategory( category, selectedNodeLabelTests )
Jeremy Ronquilloedb663b2019-06-26 14:09:38 -0700400
401 filteredList = [:]
402 for ( key in selectedNodeLabelCategoryTests.keySet() ){
403 for ( sch in selectedNodeLabelCategoryTests[ key ][ "schedules" ] ){
Jeremy Ronquillobd26bdb2019-07-08 16:15:45 -0700404 if ( validSchedules.contains( sch[ "day" ] ) && sch[ "branch" ] == test_list.convertBranchToBranchCode( branch ) || manually_run ){
Jeremy Ronquilloedb663b2019-06-26 14:09:38 -0700405 filteredList.put( key, selectedNodeLabelCategoryTests[ key ] )
406 break
407 }
408 }
409 }
410
411 echo "=========================================="
412 echo "BRANCH: " + branch
413 echo "CATEGORY: " + category
414 echo "TESTS: " + filteredList
415 if ( filteredList != [:] ){
416 exeTestList = test_list.getTestListAsString( filteredList )
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700417 runList.put( branch + "-" + nodeLabel + "-" + category, trigger_pipeline( branch, exeTestList, nodeLabel, category, manually_run, onos_tag ) )
Jeremy Ronquilloedb663b2019-06-26 14:09:38 -0700418 }
419
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700420 }
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700421 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700422 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700423 return runList
Devin Lim2edfcec2018-05-09 17:16:21 -0700424}
Devin Limf5175192018-05-14 19:13:22 -0700425
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700426def runTests(){
427 runList = generateRunList()
428 printTestsToRun( runList )
429 parallel runList
Devin Lim2edfcec2018-05-09 17:16:21 -0700430}
Devin Limf5175192018-05-14 19:13:22 -0700431
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700432// ***************
433// Generate Graphs
434// ***************
Devin Lim2edfcec2018-05-09 17:16:21 -0700435
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700436def generateGraphs(){
437 // If it is automated running, it will generate the stats graph on VM.
438 if ( !manually_run ){
439 for ( String b in onos_branches ){
Jeremy Ronquillo336110a2019-07-11 14:20:40 -0700440 graphs.generateStatGraph( "TestStation-VMs",
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700441 test_list.addPrefixToBranch( b ),
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700442 graphPaths[ "histogramMultiple" ],
443 graphPaths[ "pieMultiple" ],
444 graphPaths[ "saveDirectory" ] )
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700445 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700446 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700447}