blob: d62e1143b902930c5577a9d2f41ce900210cb7ab [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.
120// Example: converts onos-1.x to onos-1.15
121def 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 Ronquillo21c29fc2019-06-05 11:15:24 -0700132// given a branch, returns the corresponding branch code (hack)
133// Example: given "onos-1.15", returns "onos-1.x"
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700134def convertBranchToBranchCode( branch ){
Jeremy Ronquillo94c0e272019-06-11 13:51:10 -0700135 if ( branch == "master" ){
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700136 return branch
Jeremy Ronquillo94c0e272019-06-11 13:51:10 -0700137 } else if ( branch.substring( 0, 1 ) == "o" ) {
138 return branch.substring( 0, 6 ) + ".x"
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700139 } else {
140 return "onos-" + branch.substring( 0, 1 ) + ".x"
141 }
142}
143
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700144// given a branch without a prefix, returns the branch with the "onos-" prefix
145def addPrefixToBranch( branchNoPrefix ){
146 if ( branchNoPrefix == "master" ){
147 return "master"
148 } else {
149 return "onos-" + branchNoPrefix
150 }
151}
152
153// given a branch with the prefix "onos-", returns the branch without the prefix
Jeremy Ronquillo31ed9012019-06-11 14:28:59 -0700154def removePrefixFromBranch( branchWithPrefix ){
155 return branchWithPrefix.minus( "onos-" )
156}
157
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700158// *************
159// Test Category
160// *************
161
162// given a test category ("FUNC", "HA", etc.), returns all tests associated with that category
163def getTestsFromCategory( category, tests=[:] ){
164 testsFromCategoryResult = [:]
165 if ( tests == [:] ){
166 tests = allTests
167 }
168 for ( String test_name in tests.keySet() ){
169 if ( getCategoryOfTest( test_name ) == category ){
170 testsFromCategoryResult.put( test_name, tests[ test_name ] )
171 }
172 }
173 return testsFromCategoryResult
174}
175
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700176// given the test name, returns the category (FUNC, HA, etc.) of that test
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700177def getCategoryOfTest( test_name, tests=[:] ){
178 if ( tests == [:] ){
179 tests = allTests
180 }
181 return tests[ test_name ][ "category" ]
182}
183
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700184// returns all categories of all tests, or the given test list
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700185def getAllTestCategories( tests=[:] ){
186 testCategoriesResult = []
187 if ( tests == [:] ){
188 tests = allTests
189 }
190 for ( String test_name in tests.keySet() ){
191 category = getCategoryOfTest( test_name, tests )
192 if ( !testCategoriesResult.contains( category ) ){
193 testCategoriesResult += category
194 }
195 }
196 return testCategoriesResult
197}
198
199// ********************
200// Test Schedule / Days
201// ********************
202
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700203// given a day, returns schedules that contain that day
204def getValidSchedules( day ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700205 validSchedules = []
206 for ( String key in schedules.keySet() ){
207 if ( schedules[ key ].contains( day ) ){
208 validSchedules += key
209 }
210 }
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700211 return validSchedules
212}
213
Jeremy Ronquilloedb663b2019-06-26 14:09:38 -0700214// given a day, returns all tests that run on the given day on the given branch
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700215def getTestsFromDay( day, tests=[:] ){
216 resultDict = [:]
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700217 if ( tests == [:] ){
218 tests = allTests
219 }
220 validSchedules = getValidSchedules( day )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700221 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700222 scheduleProperty = getTestScheduleProperty( key, "day", tests )
223 for ( b in scheduleProperty.keySet() ){
224 if ( validSchedules.contains( scheduleProperty[ b ] ) ){
225 resultDict.put( key, tests[ key ] )
226 break
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700227 }
228 }
229 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700230 return resultDict
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700231}
232
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700233// **********
234// Node Label
235// **********
236
237// Given a node label and branch, return all tests that run on that node.
238def getTestsFromNodeLabel( nodeLabel, branch, tests=[:] ){
239 nodeLabelTestsResult = [:]
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700240 if ( tests == [:] ){
241 tests = allTests
242 }
243 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700244 branchNodeLabelMap = getTestScheduleProperty( key, "nodeLabel", tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700245 if ( branchNodeLabelMap[ convertBranchToBranchCode( branch ) ] == nodeLabel ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700246 nodeLabelTestsResult.put( key, tests[ key ] )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700247 }
248 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700249 return nodeLabelTestsResult
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700250}
251
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700252// Given a test name and branch, return the node label associated.
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700253def getNodeLabel( test_name, branch, tests=[:] ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700254 if ( tests == [:] ){
255 tests = allTests
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700256 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700257 result = getTestScheduleProperty( test_name, "nodeLabel", tests )
258 if ( result == [:] ){
259 return "UNKNOWN"
260 } else {
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700261 return result[ convertBranchToBranchCode( branch ) ]
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700262 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700263}
264
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700265// given a branch, returns all nodeLabels from all tests, or a given test list
266def getAllNodeLabels( branch, tests=[:] ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700267 nodeLabelResult = []
268 if ( tests == [:] ){
269 tests = allTests
270 }
271 for ( test_name in tests.keySet() ){
272 nodeLabel = getNodeLabel( test_name, branch, tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700273 if ( !nodeLabelResult.contains( nodeLabel ) && nodeLabel != null ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700274 nodeLabelResult += nodeLabel
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700275 }
276 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700277 return nodeLabelResult
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700278}
279
Jon Hall6af749d2018-05-29 12:59:47 -0700280return this