blob: 4c1fcad78dae6bf4b2d8860d0c75cd0d9416f597 [file] [log] [blame]
Devin Lime1346f42018-05-15 15:41:36 -07001#!groovy
Devin Limf5175192018-05-14 19:13:22 -07002// 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
21// This is the Jenkins script for vm-pipeline-trigger or bm-pipeline-trigger
22
Devin Limf5175192018-05-14 19:13:22 -070023// set the functions of the dependencies.
Devin Limb734ea52018-05-14 14:13:05 -070024funcs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsCommonFuncs.groovy' )
Devin Limb734ea52018-05-14 14:13:05 -070025triggerFuncs = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/TriggerFuncs.groovy' )
26fileRelated = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsPathAndFiles.groovy' )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070027test_list = evaluate readTrusted( 'TestON/JenkinsFile/dependencies/JenkinsTestONTests.groovy' )
Devin Lim2edfcec2018-05-09 17:16:21 -070028
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070029onos_tag = null
30manually_run = null
31now = null
32today = null
33onos_branches = null
34day = null
35post_result = null
36branchesParam = null
37isFabric = null
38testsParam = null
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -070039simulateDay = null
Jeremy Ronquillo4fd82442019-05-21 20:56:58 -070040
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070041dayMap = [:]
42fullDayMap = [:]
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070043all_testcases = [:]
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070044runTest = [:]
45selectedTests = [:]
46graphPaths = [:]
Devin Lim2edfcec2018-05-09 17:16:21 -070047
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070048main()
Devin Limf5175192018-05-14 19:13:22 -070049
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070050def main() {
51 init()
52 runTests()
53 generateGraphs()
54}
55
56// **************
57// Initialization
58// **************
59
60// initialize file scope vars
61def init(){
62 // get the name of the job.
63 jobName = env.JOB_NAME
64
65 // set the versions of the onos
66 fileRelated.init()
67 test_list.init()
68 readParams()
69
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -070070 funcs.initializeTrend( "Fabric" )
71 funcs.initialize( "Fabric" )
72
73 funcs.initializeTrend( "VM" )
74
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070075 triggerFuncs.init( funcs )
76
77 // list of the tests to be run will be saved in each choices.
78 day = ""
79
80 initDates()
81 onos_branches = getONOSBranches()
82 selectedTests = getONOSTests()
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -070083
Jeremy Ronquillod98c2a12019-06-07 15:13:29 -070084 initGraphPaths()
85
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -070086 echo "selectedTests: " + selectedTests
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -070087 echo "onos_branches: " + onos_branches
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070088}
89
90def readParams(){
91 // get post result from the params for manually run.
92 post_result = params.PostResult
93 manually_run = params.manual_run
94 onos_tag = params.ONOSTag
95 branchesParam = params.branches
96 isOldFlow = params.isOldFlow
97 testsParam = params.Tests
98 isFabric = params.isFabric
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -070099 simulateDay = params.simulate_day
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700100}
Devin Lim2edfcec2018-05-09 17:16:21 -0700101
102// Set tests based on day of week
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700103def initDates(){
104 echo "-> initDates()"
105 now = funcs.getCurrentTime()
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700106 dayMap = [ ( Calendar.MONDAY ) : "mon",
107 ( Calendar.TUESDAY ) : "tue",
108 ( Calendar.WEDNESDAY ) : "wed",
109 ( Calendar.THURSDAY ) : "thu",
110 ( Calendar.FRIDAY ) : "fri",
111 ( Calendar.SATURDAY ) : "sat",
112 ( Calendar.SUNDAY ) : "sun" ]
113 fullDayMap = [ ( Calendar.MONDAY ) : "Monday",
114 ( Calendar.TUESDAY ) : "Tuesday",
115 ( Calendar.WEDNESDAY ) : "Wednesday",
116 ( Calendar.THURSDAY ) : "Thursday",
117 ( Calendar.FRIDAY ) : "Friday",
118 ( Calendar.SATURDAY ) : "Saturday",
119 ( Calendar.SUNDAY ) : "Sunday" ]
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -0700120 if ( simulateDay == "" ){
121 today = now[ Calendar.DAY_OF_WEEK ]
122 day = dayMap[ today ]
123 print now.toString()
124 } else {
125 day = simulateDay
126 }
Jon Hall6af749d2018-05-29 12:59:47 -0700127}
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700128
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700129// gets ONOS branches from params or string parameter
130def getONOSBranches(){
131 echo "-> getONOSBranches()"
132 if ( manually_run ){
133 return branchesParam.tokenize( "\n;, " )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700134 } else {
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -0700135 return test_list.getBranchesFromDay( day )
Devin Lim2edfcec2018-05-09 17:16:21 -0700136 }
137}
Devin Limf5175192018-05-14 19:13:22 -0700138
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700139def getONOSTests(){
140 echo "-> getONOSTests()"
141 if ( manually_run ){
142 return test_list.getTestsFromStringList( testsParam.tokenize( "\n;, " ) )
143 } else {
Jeremy Ronquillo3c2f10d2019-06-10 16:54:46 -0700144
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700145 return test_list.getTestsFromDay( day )
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700146 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700147}
Devin Limf5175192018-05-14 19:13:22 -0700148
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700149// init paths for the files and directories.
150def initGraphPaths(){
Jeremy Ronquillod98c2a12019-06-07 15:13:29 -0700151 graphPaths.put( "histogramMultiple", fileRelated.histogramMultiple )
152 graphPaths.put( "pieMultiple", fileRelated.pieMultiple )
153 graphPaths.put( "saveDirectory", fileRelated.jenkinsWorkspace + "postjob-VM/" )
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700154}
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700155
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700156// **********************
157// Determine Tests to Run
158// **********************
159
160def printTestsToRun( runList ){
161 if ( manually_run ){
162 println "Tests to be run manually:"
163 } else {
164 if ( isFabric ){
165 postToSlackSR()
Devin Lim2edfcec2018-05-09 17:16:21 -0700166 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700167 if ( today == Calendar.MONDAY ){
168 postToSlackTestsToRun()
169 }
170 println "Defaulting to " + day + " tests:"
Devin Lim2edfcec2018-05-09 17:16:21 -0700171 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700172 for ( list in runList ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700173 echo "" + list
174 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700175}
Devin Limf5175192018-05-14 19:13:22 -0700176
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700177def postToSlackSR(){
178 // If it is automated running, it will post the beginning message to the channel.
179 slackSend( channel: 'sr-failures', color: '#03CD9F',
180 message: ":sparkles:" * 16 + "\n" +
181 "Starting tests on : " + now.toString() +
182 "\n" + ":sparkles:" * 16 )
183}
184
185def postToSlackTestsToRun(){
186 slackSend( color: '#FFD988',
187 message: "Tests to be run this weekdays : \n" +
188 triggerFuncs.printDaysForTest() )
189}
190
191// *********
192// Run Tests
193// *********
194
195def generateRunList(){
196 runList = [:]
Jeremy Ronquilloedb663b2019-06-26 14:09:38 -0700197 validSchedules = test_list.getValidSchedules( day )
198 echo "validSchedules: " + validSchedules
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700199 for ( branch in onos_branches ){
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700200 runBranch = []
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700201 nodeLabels = test_list.getAllNodeLabels( branch, selectedTests )
202 for ( nodeLabel in nodeLabels ){
203 selectedNodeLabelTests = test_list.getTestsFromNodeLabel( nodeLabel, branch, selectedTests )
204 selectedNodeLabelCategories = test_list.getAllTestCategories( selectedNodeLabelTests )
205 for ( category in selectedNodeLabelCategories ){
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700206 selectedNodeLabelCategoryTests = test_list.getTestsFromCategory( category, selectedNodeLabelTests )
Jeremy Ronquilloedb663b2019-06-26 14:09:38 -0700207
208 filteredList = [:]
209 for ( key in selectedNodeLabelCategoryTests.keySet() ){
210 for ( sch in selectedNodeLabelCategoryTests[ key ][ "schedules" ] ){
211 if ( validSchedules.contains( sch[ "day" ] ) && sch[ "branch" ] == test_list.convertBranchToBranchCode( branch ) ){
212 filteredList.put( key, selectedNodeLabelCategoryTests[ key ] )
213 break
214 }
215 }
216 }
217
218 echo "=========================================="
219 echo "BRANCH: " + branch
220 echo "CATEGORY: " + category
221 echo "TESTS: " + filteredList
222 if ( filteredList != [:] ){
223 exeTestList = test_list.getTestListAsString( filteredList )
224 runList.put( branch + "-" + nodeLabel + "-" + category, triggerFuncs.trigger_pipeline( branch, exeTestList, nodeLabel, category, manually_run, onos_tag ) )
225 }
226
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700227 }
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700228 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700229 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700230 return runList
Devin Lim2edfcec2018-05-09 17:16:21 -0700231}
Devin Limf5175192018-05-14 19:13:22 -0700232
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700233def runTests(){
234 runList = generateRunList()
235 printTestsToRun( runList )
236 parallel runList
Devin Lim2edfcec2018-05-09 17:16:21 -0700237}
Devin Limf5175192018-05-14 19:13:22 -0700238
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700239// ***************
240// Generate Graphs
241// ***************
Devin Lim2edfcec2018-05-09 17:16:21 -0700242
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700243def generateGraphs(){
244 // If it is automated running, it will generate the stats graph on VM.
245 if ( !manually_run ){
246 for ( String b in onos_branches ){
247 funcs.generateStatGraph( "TestStation-VMs",
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700248 test_list.addPrefixToBranch( b ),
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700249 graphPaths[ "histogramMultiple" ],
250 graphPaths[ "pieMultiple" ],
251 graphPaths[ "saveDirectory" ] )
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700252 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700253 }
Devin Lim2edfcec2018-05-09 17:16:21 -0700254}