blob: 4d263c6b5842a0cd473a5919a291f47e29e182b8 [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 ) ){
108 branchesFromDayResult += convertBranchCodeToBranch( subDict[ "branch" ] )
109 }
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 Ronquillo96e2bd32019-05-28 15:40:18 -0700138// *************
139// Test Category
140// *************
141
142// given a test category ("FUNC", "HA", etc.), returns all tests associated with that category
143def getTestsFromCategory( category, tests=[:] ){
144 testsFromCategoryResult = [:]
145 if ( tests == [:] ){
146 tests = allTests
147 }
148 for ( String test_name in tests.keySet() ){
149 if ( getCategoryOfTest( test_name ) == category ){
150 testsFromCategoryResult.put( test_name, tests[ test_name ] )
151 }
152 }
153 return testsFromCategoryResult
154}
155
156def getCategoryOfTest( test_name, tests=[:] ){
157 if ( tests == [:] ){
158 tests = allTests
159 }
160 return tests[ test_name ][ "category" ]
161}
162
163def getAllTestCategories( tests=[:] ){
164 testCategoriesResult = []
165 if ( tests == [:] ){
166 tests = allTests
167 }
168 for ( String test_name in tests.keySet() ){
169 category = getCategoryOfTest( test_name, tests )
170 if ( !testCategoriesResult.contains( category ) ){
171 testCategoriesResult += category
172 }
173 }
174 return testCategoriesResult
175}
176
177// ********************
178// Test Schedule / Days
179// ********************
180
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700181// given a day, returns schedules that contain that day
182def getValidSchedules( day ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700183 validSchedules = []
184 for ( String key in schedules.keySet() ){
185 if ( schedules[ key ].contains( day ) ){
186 validSchedules += key
187 }
188 }
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700189 return validSchedules
190}
191
192// 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 -0700193def getTestsFromDay( day, tests=[:] ){
194 resultDict = [:]
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700195 if ( tests == [:] ){
196 tests = allTests
197 }
198 validSchedules = getValidSchedules( day )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700199 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700200 scheduleProperty = getTestScheduleProperty( key, "day", tests )
201 for ( b in scheduleProperty.keySet() ){
202 if ( validSchedules.contains( scheduleProperty[ b ] ) ){
203 resultDict.put( key, tests[ key ] )
204 break
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700205 }
206 }
207 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700208 return resultDict
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700209}
210
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700211// **********
212// Node Label
213// **********
214
215// Given a node label and branch, return all tests that run on that node.
216def getTestsFromNodeLabel( nodeLabel, branch, tests=[:] ){
217 nodeLabelTestsResult = [:]
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700218 if ( tests == [:] ){
219 tests = allTests
220 }
221 for ( String key in tests.keySet() ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700222 branchNodeLabelMap = getTestScheduleProperty( key, "nodeLabel", tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700223 if ( branchNodeLabelMap[ convertBranchToBranchCode( branch ) ] == nodeLabel ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700224 nodeLabelTestsResult.put( key, tests[ key ] )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700225 }
226 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700227 return nodeLabelTestsResult
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700228}
229
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700230// Given a test name and branch, return the node label associated.
231def getNodeLabel( test_name, branch, tests ){
232 if ( tests == [:] ){
233 tests = allTests
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700234 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700235 result = getTestScheduleProperty( test_name, "nodeLabel", tests )
236 if ( result == [:] ){
237 return "UNKNOWN"
238 } else {
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700239 return result[ convertBranchToBranchCode( branch ) ]
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700240 }
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700241}
242
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700243def getAllNodeLabels( branch, tests ){
244 nodeLabelResult = []
245 if ( tests == [:] ){
246 tests = allTests
247 }
248 for ( test_name in tests.keySet() ){
249 nodeLabel = getNodeLabel( test_name, branch, tests )
Jeremy Ronquilloa5aa7c12019-06-04 10:26:36 -0700250 if ( !nodeLabelResult.contains( nodeLabel ) && nodeLabel != null ){
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700251 nodeLabelResult += nodeLabel
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700252 }
253 }
Jeremy Ronquillo96e2bd32019-05-28 15:40:18 -0700254 return nodeLabelResult
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700255}
256
Jon Hall6af749d2018-05-29 12:59:47 -0700257return this