blob: eef8526d0c8fc79722ababb96f94a0cc101acd9e [file] [log] [blame]
Devin Lime1346f42018-05-15 15:41:36 -07001#!groovy
2
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -07003// Copyright 2019 Open Networking Foundation (ONF)
Devin Limf5175192018-05-14 19:13:22 -07004//
5// Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6// the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7// or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
8//
9// TestON is free software: you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 2 of the License, or
12// (at your option) any later version.
13//
14// TestON is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with TestON. If not, see <http://www.gnu.org/licenses/>.
21
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070022allTests = [:]
23schedules = [:]
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070024branches = [:]
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -080025
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070026// read all json files and save as maps
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070027def init(){
Jeremy Ronquillobc631c12019-05-21 15:29:04 -070028 def tests_buffer = readTrusted( "TestON/JenkinsFile/dependencies/tests.json" )
29 def schedules_buffer = readTrusted( "TestON/JenkinsFile/dependencies/schedule.json" )
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070030 def branches_buffer = readTrusted( "TestON/JenkinsFile/dependencies/branches.json" )
Jeremy Ronquillo266b92e2019-05-21 15:45:20 -070031 allTests = readJSON text: tests_buffer
32 schedules = readJSON text: schedules_buffer
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070033 branches = readJSON text: branches_buffer
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070034}
Devin Limf5175192018-05-14 19:13:22 -070035
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070036// ***************
37// General Methods
38// ***************
39
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070040// returns the entire set of TestON tests from the json file
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070041def getAllTests(){
42 return allTests
43}
Devin Limf5175192018-05-14 19:13:22 -070044
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070045// returns the entire set of schedules from the json file
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070046def getSchedules(){
47 return schedules
48}
49
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070050// returns a list of days corresponding to the given schedule code
51def convertScheduleKeyToDays( sch ){
52 return schedules[ sch ]
53}
54
55// given a test dictionary, returns a list of tests as a string
56def getTestListAsString( tests ){
57 str_result = ""
58 for ( String test in tests.keySet() ){
59 str_result += test + ","
60 }
61 return str_result[ 0..-2 ]
62}
63
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070064// given a list of tests as a string, returns the list of tests as a map, similar formatted to tests.json
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070065def getTestsFromStringList( list ){
66 testsResult = [:]
67 for ( item in list ){
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -070068 if ( allTests.keySet().contains( item ) ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070069 testsResult.put( item, allTests[ item ] )
70 }
71 }
72 return testsResult
73}
74
75// Get a given test property from the schedules list for a given test
76// Example: getTestScheduleProperty( "FUNCflow", "nodeLabel" ) gets all node labels for each branch
77def getTestScheduleProperty( test_name, property, tests=[:] ){
78 schedulePropertyResult = [:]
79
80 if ( tests == [:] ){
81 tests = allTests
82 }
83 for ( subDict in tests[ test_name ][ "schedules" ] ){
84 schedulePropertyResult.put( subDict[ "branch" ], subDict[ property ] )
85 }
86
87 return schedulePropertyResult
88}
89
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070090// ********
91// Branches
92// ********
93
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -070094// returns all branches from branches.json
95def getAllBranches(){
96 return branches
97}
98
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070099// given a day, returns all branches that are run on that day
100def getBranchesFromDay( day, tests=[:] ){
101 branchesFromDayResult = []
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700102 if ( tests == [:] ){
103 tests = allTests
104 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700105 validSchedules = getValidSchedules( day )
106
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700107 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700108 for ( subDict in tests[ key ][ "schedules" ] ){
109 sch = subDict[ "day" ]
Jeremy Ronquilloedb663b2019-06-26 14:09:38 -0700110 new_branch = convertBranchCodeToBranch( subDict[ "branch" ], false )
111 if ( validSchedules.contains( sch ) && !branchesFromDayResult.contains( new_branch ) ){
112 branchesFromDayResult += new_branch
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700113 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700114 }
115 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700116 return branchesFromDayResult
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700117}
118
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700119// Converts a branch code to an actual ONOS branch.
Jeremy Ronquillof5482c92020-12-09 16:30:49 -0800120// Example: converts onos-LTS1 to onos-1.15
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700121def convertBranchCodeToBranch( branch_code, withPrefix=true ){
122 for ( String branch_type in branches.keySet() ){
123 for ( String b in branches[ branch_type ].keySet() ){
124 if ( branch_code == b ){
125 return withPrefix ? ( "onos-" + branches[ branch_type ][ b ] ) : branches[ branch_type ][ b ]
126 }
127 }
128 }
129 return branch_code
130}
131
Jeremy Ronquillof5482c92020-12-09 16:30:49 -0800132// given a branch, returns the corresponding branch code
133// Example: given "onos-1.15", returns "onos-LTS1"
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700134def convertBranchToBranchCode( branch ){
Jeremy Ronquillo94c0e272019-06-11 13:51:10 -0700135 if ( branch == "master" ){
Jeremy Ronquillof5482c92020-12-09 16:30:49 -0800136 return branch
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700137 }
Jeremy Ronquillof5482c92020-12-09 16:30:49 -0800138 for ( String branch_type in branches.keySet() ){
139 for ( String b in branches[ branch_type ].keySet() ){
140 if ( branches[ branch_type ][ b ] == branch ){
141 return b
142 }
143 }
144 }
145 return "UNKNOWN"
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700146}
147
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700148// given a branch without a prefix, returns the branch with the "onos-" prefix
149def addPrefixToBranch( branchNoPrefix ){
150 if ( branchNoPrefix == "master" ){
151 return "master"
152 } else {
153 return "onos-" + branchNoPrefix
154 }
155}
156
157// given a branch with the prefix "onos-", returns the branch without the prefix
Jeremy Ronquillo31ed9012019-06-11 14:28:59 -0700158def removePrefixFromBranch( branchWithPrefix ){
159 return branchWithPrefix.minus( "onos-" )
160}
161
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700162// *************
163// Test Category
164// *************
165
166// given a test category ("FUNC", "HA", etc.), returns all tests associated with that category
167def getTestsFromCategory( category, tests=[:] ){
168 testsFromCategoryResult = [:]
169 if ( tests == [:] ){
170 tests = allTests
171 }
172 for ( String test_name in tests.keySet() ){
173 if ( getCategoryOfTest( test_name ) == category ){
174 testsFromCategoryResult.put( test_name, tests[ test_name ] )
175 }
176 }
177 return testsFromCategoryResult
178}
179
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700180// given the test name, returns the category (FUNC, HA, etc.) of that test
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700181def getCategoryOfTest( test_name, tests=[:] ){
182 if ( tests == [:] ){
183 tests = allTests
184 }
185 return tests[ test_name ][ "category" ]
186}
187
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700188// returns all categories of all tests, or the given test list
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700189def getAllTestCategories( tests=[:] ){
190 testCategoriesResult = []
191 if ( tests == [:] ){
192 tests = allTests
193 }
194 for ( String test_name in tests.keySet() ){
195 category = getCategoryOfTest( test_name, tests )
196 if ( !testCategoriesResult.contains( category ) ){
197 testCategoriesResult += category
198 }
199 }
200 return testCategoriesResult
201}
202
203// ********************
204// Test Schedule / Days
205// ********************
206
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700207// given a day, returns schedules that contain that day
208def getValidSchedules( day ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700209 validSchedules = []
210 for ( String key in schedules.keySet() ){
211 if ( schedules[ key ].contains( day ) ){
212 validSchedules += key
213 }
214 }
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700215 return validSchedules
216}
217
Jeremy Ronquilloedb663b2019-06-26 14:09:38 -0700218// given a day, returns all tests that run on the given day on the given branch
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700219def getTestsFromDay( day, tests=[:] ){
220 resultDict = [:]
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700221 if ( tests == [:] ){
222 tests = allTests
223 }
224 validSchedules = getValidSchedules( day )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700225 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700226 scheduleProperty = getTestScheduleProperty( key, "day", tests )
227 for ( b in scheduleProperty.keySet() ){
228 if ( validSchedules.contains( scheduleProperty[ b ] ) ){
229 resultDict.put( key, tests[ key ] )
230 break
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700231 }
232 }
233 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700234 return resultDict
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700235}
236
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700237// **********
238// Node Label
239// **********
240
241// Given a node label and branch, return all tests that run on that node.
242def getTestsFromNodeLabel( nodeLabel, branch, tests=[:] ){
243 nodeLabelTestsResult = [:]
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700244 if ( tests == [:] ){
245 tests = allTests
246 }
247 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700248 branchNodeLabelMap = getTestScheduleProperty( key, "nodeLabel", tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700249 if ( branchNodeLabelMap[ convertBranchToBranchCode( branch ) ] == nodeLabel ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700250 nodeLabelTestsResult.put( key, tests[ key ] )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700251 }
252 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700253 return nodeLabelTestsResult
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700254}
255
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700256// Given a test name and branch, return the node label associated.
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700257def getNodeLabel( test_name, branch, tests=[:] ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700258 if ( tests == [:] ){
259 tests = allTests
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700260 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700261 result = getTestScheduleProperty( test_name, "nodeLabel", tests )
262 if ( result == [:] ){
263 return "UNKNOWN"
264 } else {
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700265 return result[ convertBranchToBranchCode( branch ) ]
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700266 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700267}
268
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700269// given a branch, returns all nodeLabels from all tests, or a given test list
270def getAllNodeLabels( branch, tests=[:] ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700271 nodeLabelResult = []
272 if ( tests == [:] ){
273 tests = allTests
274 }
275 for ( test_name in tests.keySet() ){
276 nodeLabel = getNodeLabel( test_name, branch, tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700277 if ( !nodeLabelResult.contains( nodeLabel ) && nodeLabel != null ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700278 nodeLabelResult += nodeLabel
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700279 }
280 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700281 return nodeLabelResult
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700282}
283
Jon Hall6af749d2018-05-29 12:59:47 -0700284return this