blob: 2a358df87ecd2b918bfb9dca19d251827fdb5a5f [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" ]
110 if ( validSchedules.contains( sch ) && !branchesFromDayResult.contains( sch ) ){
Jeremy Ronquillo31ed9012019-06-11 14:28:59 -0700111 branchesFromDayResult += convertBranchCodeToBranch( subDict[ "branch" ], false )
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700112 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700113 }
114 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700115 return branchesFromDayResult
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700116}
117
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700118// Converts a branch code to an actual ONOS branch.
119// Example: converts onos-1.x to onos-1.15
120def convertBranchCodeToBranch( branch_code, withPrefix=true ){
121 for ( String branch_type in branches.keySet() ){
122 for ( String b in branches[ branch_type ].keySet() ){
123 if ( branch_code == b ){
124 return withPrefix ? ( "onos-" + branches[ branch_type ][ b ] ) : branches[ branch_type ][ b ]
125 }
126 }
127 }
128 return branch_code
129}
130
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700131// given a branch, returns the corresponding branch code (hack)
132// Example: given "onos-1.15", returns "onos-1.x"
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700133def convertBranchToBranchCode( branch ){
Jeremy Ronquillo94c0e272019-06-11 13:51:10 -0700134 if ( branch == "master" ){
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700135 return branch
Jeremy Ronquillo94c0e272019-06-11 13:51:10 -0700136 } else if ( branch.substring( 0, 1 ) == "o" ) {
137 return branch.substring( 0, 6 ) + ".x"
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700138 } else {
139 return "onos-" + branch.substring( 0, 1 ) + ".x"
140 }
141}
142
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700143// given a branch without a prefix, returns the branch with the "onos-" prefix
144def addPrefixToBranch( branchNoPrefix ){
145 if ( branchNoPrefix == "master" ){
146 return "master"
147 } else {
148 return "onos-" + branchNoPrefix
149 }
150}
151
152// given a branch with the prefix "onos-", returns the branch without the prefix
Jeremy Ronquillo31ed9012019-06-11 14:28:59 -0700153def removePrefixFromBranch( branchWithPrefix ){
154 return branchWithPrefix.minus( "onos-" )
155}
156
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700157// *************
158// Test Category
159// *************
160
161// given a test category ("FUNC", "HA", etc.), returns all tests associated with that category
162def getTestsFromCategory( category, tests=[:] ){
163 testsFromCategoryResult = [:]
164 if ( tests == [:] ){
165 tests = allTests
166 }
167 for ( String test_name in tests.keySet() ){
168 if ( getCategoryOfTest( test_name ) == category ){
169 testsFromCategoryResult.put( test_name, tests[ test_name ] )
170 }
171 }
172 return testsFromCategoryResult
173}
174
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700175// given the test name, returns the category (FUNC, HA, etc.) of that test
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700176def getCategoryOfTest( test_name, tests=[:] ){
177 if ( tests == [:] ){
178 tests = allTests
179 }
180 return tests[ test_name ][ "category" ]
181}
182
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700183// returns all categories of all tests, or the given test list
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700184def getAllTestCategories( tests=[:] ){
185 testCategoriesResult = []
186 if ( tests == [:] ){
187 tests = allTests
188 }
189 for ( String test_name in tests.keySet() ){
190 category = getCategoryOfTest( test_name, tests )
191 if ( !testCategoriesResult.contains( category ) ){
192 testCategoriesResult += category
193 }
194 }
195 return testCategoriesResult
196}
197
198// ********************
199// Test Schedule / Days
200// ********************
201
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700202// given a day, returns schedules that contain that day
203def getValidSchedules( day ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700204 validSchedules = []
205 for ( String key in schedules.keySet() ){
206 if ( schedules[ key ].contains( day ) ){
207 validSchedules += key
208 }
209 }
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700210 return validSchedules
211}
212
213// given a day and branch, returns all tests that run on the given day on the given branch
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700214def getTestsFromDay( day, tests=[:] ){
215 resultDict = [:]
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700216 if ( tests == [:] ){
217 tests = allTests
218 }
219 validSchedules = getValidSchedules( day )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700220 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700221 scheduleProperty = getTestScheduleProperty( key, "day", tests )
222 for ( b in scheduleProperty.keySet() ){
223 if ( validSchedules.contains( scheduleProperty[ b ] ) ){
224 resultDict.put( key, tests[ key ] )
225 break
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700226 }
227 }
228 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700229 return resultDict
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700230}
231
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700232// **********
233// Node Label
234// **********
235
236// Given a node label and branch, return all tests that run on that node.
237def getTestsFromNodeLabel( nodeLabel, branch, tests=[:] ){
238 nodeLabelTestsResult = [:]
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700239 if ( tests == [:] ){
240 tests = allTests
241 }
242 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700243 branchNodeLabelMap = getTestScheduleProperty( key, "nodeLabel", tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700244 if ( branchNodeLabelMap[ convertBranchToBranchCode( branch ) ] == nodeLabel ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700245 nodeLabelTestsResult.put( key, tests[ key ] )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700246 }
247 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700248 return nodeLabelTestsResult
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700249}
250
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700251// Given a test name and branch, return the node label associated.
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700252def getNodeLabel( test_name, branch, tests=[:] ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700253 if ( tests == [:] ){
254 tests = allTests
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700255 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700256 result = getTestScheduleProperty( test_name, "nodeLabel", tests )
257 if ( result == [:] ){
258 return "UNKNOWN"
259 } else {
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700260 return result[ convertBranchToBranchCode( branch ) ]
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700261 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700262}
263
Jeremy Ronquillo21c29fc2019-06-05 11:15:24 -0700264// given a branch, returns all nodeLabels from all tests, or a given test list
265def getAllNodeLabels( branch, tests=[:] ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700266 nodeLabelResult = []
267 if ( tests == [:] ){
268 tests = allTests
269 }
270 for ( test_name in tests.keySet() ){
271 nodeLabel = getNodeLabel( test_name, branch, tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700272 if ( !nodeLabelResult.contains( nodeLabel ) && nodeLabel != null ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700273 nodeLabelResult += nodeLabel
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700274 }
275 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700276 return nodeLabelResult
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700277}
278
Jon Hall6af749d2018-05-29 12:59:47 -0700279return this