blob: a93fa1c28a78f71c0e07ac59e4950a358a2cb072 [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 Ronquillo64eeeb12019-05-13 11:19:46 -070026def init(){
Jeremy Ronquillobc631c12019-05-21 15:29:04 -070027 def tests_buffer = readTrusted( "TestON/JenkinsFile/dependencies/tests.json" )
28 def schedules_buffer = readTrusted( "TestON/JenkinsFile/dependencies/schedule.json" )
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070029 def branches_buffer = readTrusted( "TestON/JenkinsFile/dependencies/branches.json" )
Jeremy Ronquillo266b92e2019-05-21 15:45:20 -070030 allTests = readJSON text: tests_buffer
31 schedules = readJSON text: schedules_buffer
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070032 branches = readJSON text: branches_buffer
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070033}
Devin Limf5175192018-05-14 19:13:22 -070034
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070035// ***************
36// General Methods
37// ***************
38
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070039// returns the entire set of TestON tests from the json file
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070040def getAllTests(){
41 return allTests
42}
Devin Limf5175192018-05-14 19:13:22 -070043
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070044// returns the entire set of schedules from the json file
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070045def getSchedules(){
46 return schedules
47}
48
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070049// returns a list of days corresponding to the given schedule code
50def convertScheduleKeyToDays( sch ){
51 return schedules[ sch ]
52}
53
54// given a test dictionary, returns a list of tests as a string
55def getTestListAsString( tests ){
56 str_result = ""
57 for ( String test in tests.keySet() ){
58 str_result += test + ","
59 }
60 return str_result[ 0..-2 ]
61}
62
63def getTestsFromStringList( list ){
64 testsResult = [:]
65 for ( item in list ){
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -070066 if ( allTests.keySet().contains( item ) ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070067 testsResult.put( item, allTests[ item ] )
68 }
69 }
70 return testsResult
71}
72
73// Get a given test property from the schedules list for a given test
74// Example: getTestScheduleProperty( "FUNCflow", "nodeLabel" ) gets all node labels for each branch
75def getTestScheduleProperty( test_name, property, tests=[:] ){
76 schedulePropertyResult = [:]
77
78 if ( tests == [:] ){
79 tests = allTests
80 }
81 for ( subDict in tests[ test_name ][ "schedules" ] ){
82 schedulePropertyResult.put( subDict[ "branch" ], subDict[ property ] )
83 }
84
85 return schedulePropertyResult
86}
87
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070088def getAllBranches(){
89 return branches
90}
91
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -070092// ********
93// Branches
94// ********
95
96// given a day, returns all branches that are run on that day
97def getBranchesFromDay( day, tests=[:] ){
98 branchesFromDayResult = []
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070099 if ( tests == [:] ){
100 tests = allTests
101 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700102 validSchedules = getValidSchedules( day )
103
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700104 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700105 for ( subDict in tests[ key ][ "schedules" ] ){
106 sch = subDict[ "day" ]
107 if ( validSchedules.contains( sch ) && !branchesFromDayResult.contains( sch ) ){
Jeremy Ronquillo31ed9012019-06-11 14:28:59 -0700108 branchesFromDayResult += convertBranchCodeToBranch( subDict[ "branch" ], false )
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700109 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700110 }
111 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700112 return branchesFromDayResult
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700113}
114
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700115// Converts a branch code to an actual ONOS branch.
116// Example: converts onos-1.x to onos-1.15
117def convertBranchCodeToBranch( branch_code, withPrefix=true ){
118 for ( String branch_type in branches.keySet() ){
119 for ( String b in branches[ branch_type ].keySet() ){
120 if ( branch_code == b ){
121 return withPrefix ? ( "onos-" + branches[ branch_type ][ b ] ) : branches[ branch_type ][ b ]
122 }
123 }
124 }
125 return branch_code
126}
127
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700128def convertBranchToBranchCode( branch ){
Jeremy Ronquillo94c0e272019-06-11 13:51:10 -0700129 if ( branch == "master" ){
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700130 return branch
Jeremy Ronquillo94c0e272019-06-11 13:51:10 -0700131 } else if ( branch.substring( 0, 1 ) == "o" ) {
132 return branch.substring( 0, 6 ) + ".x"
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700133 } else {
134 return "onos-" + branch.substring( 0, 1 ) + ".x"
135 }
136}
137
Jeremy Ronquillo31ed9012019-06-11 14:28:59 -0700138def removePrefixFromBranch( branchWithPrefix ){
139 return branchWithPrefix.minus( "onos-" )
140}
141
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700142// *************
143// Test Category
144// *************
145
146// given a test category ("FUNC", "HA", etc.), returns all tests associated with that category
147def getTestsFromCategory( category, tests=[:] ){
148 testsFromCategoryResult = [:]
149 if ( tests == [:] ){
150 tests = allTests
151 }
152 for ( String test_name in tests.keySet() ){
153 if ( getCategoryOfTest( test_name ) == category ){
154 testsFromCategoryResult.put( test_name, tests[ test_name ] )
155 }
156 }
157 return testsFromCategoryResult
158}
159
160def getCategoryOfTest( test_name, tests=[:] ){
161 if ( tests == [:] ){
162 tests = allTests
163 }
164 return tests[ test_name ][ "category" ]
165}
166
167def getAllTestCategories( tests=[:] ){
168 testCategoriesResult = []
169 if ( tests == [:] ){
170 tests = allTests
171 }
172 for ( String test_name in tests.keySet() ){
173 category = getCategoryOfTest( test_name, tests )
174 if ( !testCategoriesResult.contains( category ) ){
175 testCategoriesResult += category
176 }
177 }
178 return testCategoriesResult
179}
180
181// ********************
182// Test Schedule / Days
183// ********************
184
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700185// given a day, returns schedules that contain that day
186def getValidSchedules( day ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700187 validSchedules = []
188 for ( String key in schedules.keySet() ){
189 if ( schedules[ key ].contains( day ) ){
190 validSchedules += key
191 }
192 }
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700193 return validSchedules
194}
195
196// 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 -0700197def getTestsFromDay( day, tests=[:] ){
198 resultDict = [:]
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700199 if ( tests == [:] ){
200 tests = allTests
201 }
202 validSchedules = getValidSchedules( day )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700203 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700204 scheduleProperty = getTestScheduleProperty( key, "day", tests )
205 for ( b in scheduleProperty.keySet() ){
206 if ( validSchedules.contains( scheduleProperty[ b ] ) ){
207 resultDict.put( key, tests[ key ] )
208 break
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700209 }
210 }
211 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700212 return resultDict
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700213}
214
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700215// **********
216// Node Label
217// **********
218
219// Given a node label and branch, return all tests that run on that node.
220def getTestsFromNodeLabel( nodeLabel, branch, tests=[:] ){
221 nodeLabelTestsResult = [:]
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700222 if ( tests == [:] ){
223 tests = allTests
224 }
225 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700226 branchNodeLabelMap = getTestScheduleProperty( key, "nodeLabel", tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700227 if ( branchNodeLabelMap[ convertBranchToBranchCode( branch ) ] == nodeLabel ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700228 nodeLabelTestsResult.put( key, tests[ key ] )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700229 }
230 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700231 return nodeLabelTestsResult
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700232}
233
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700234// Given a test name and branch, return the node label associated.
235def getNodeLabel( test_name, branch, tests ){
236 if ( tests == [:] ){
237 tests = allTests
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700238 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700239 result = getTestScheduleProperty( test_name, "nodeLabel", tests )
240 if ( result == [:] ){
241 return "UNKNOWN"
242 } else {
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700243 return result[ convertBranchToBranchCode( branch ) ]
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700244 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700245}
246
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700247def getAllNodeLabels( branch, tests ){
248 nodeLabelResult = []
249 if ( tests == [:] ){
250 tests = allTests
251 }
252 for ( test_name in tests.keySet() ){
253 nodeLabel = getNodeLabel( test_name, branch, tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700254 if ( !nodeLabelResult.contains( nodeLabel ) && nodeLabel != null ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700255 nodeLabelResult += nodeLabel
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700256 }
257 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700258 return nodeLabelResult
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700259}
260
Jon Hall6af749d2018-05-29 12:59:47 -0700261return this