blob: 6ee04857135e4cbf93db9d22cfdaa61e2822d9c2 [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 Ronquilloa37920b2019-05-23 14:34:25 -070035// returns the entire set of TestON tests from the json file
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070036def getAllTests(){
37 return allTests
38}
Devin Limf5175192018-05-14 19:13:22 -070039
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070040// returns the entire set of schedules from the json file
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070041def getSchedules(){
42 return schedules
43}
44
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070045def getAllBranches(){
46 return branches
47}
48
49// given a test category ("FUNC", "HA", etc.), returns all tests associated with that category
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070050def getTestsFromCategory( category, tests=[:] ){
51 result = [:]
52 if ( tests == [:] ){
53 tests = allTests
54 }
55 for ( String key in tests.keySet() ){
56 if ( tests[ key ][ "category" ] == category ){
57 result.put( key, tests[ key ] )
58 }
59 }
60 return result
61}
62
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070063// given a day, returns schedules that contain that day
64def getValidSchedules( day ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070065 validSchedules = []
66 for ( String key in schedules.keySet() ){
67 if ( schedules[ key ].contains( day ) ){
68 validSchedules += key
69 }
70 }
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070071 return validSchedules
72}
73
74// given a day and branch, returns all tests that run on the given day on the given branch
75def getTestsFromDay( day, branch, tests=[:] ){
76 result = [:]
77 if ( tests == [:] ){
78 tests = allTests
79 }
80 validSchedules = getValidSchedules( day )
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -070081 for ( String key in tests.keySet() ){
82 schedule = tests[ key ][ "schedule" ][ branch ]
83 if ( validSchedules.contains( schedule ) ){
84 result.put( key, tests[ key ] )
85 }
86 }
87 return result
88}
89
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -070090// given a day, returns all branches that are run on that day
91def getBranchesFromDay( day, tests=[:] ){
92 result = []
93 if ( tests == [:] ){
94 tests = allTests
95 }
96 validSchedules = getValidSchedules( day )
97
98 for ( String key in tests.keySet() ){
99 for ( String branch in tests[ key ][ "schedule" ].keySet() ){
100 sch = tests[ key ][ "schedule" ][ branch ]
101 if ( validSchedules.contains( sch ) && !result.contains( sch ) ){
102 result += convertBranchCodeToBranch( branch )
103 }
104 }
105 }
106 return result
107}
108
109// given a nodeLabel ("vm", "bm", etc.), returns all tests that run on that node.
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700110def getTestsFromNodeLabel( nodeLabel, tests=[:] ){
111 if ( tests == [:] ){
112 tests = allTests
113 }
114 for ( String key in tests.keySet() ){
115 if ( tests[ key ][ "nodeLabel" ] == nodeLabel ){
116 result.put( key, tests[ key ] )
117 }
118 }
119}
120
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700121// returns the test list as a string
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700122def getTestListAsString( tests ){
123 result = ""
Jeremy Ronquilloe81fb412019-05-22 10:03:05 -0700124 for ( String test in tests.keySet() ){
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700125 result += test + ","
126 }
127 return result[ 0..-2 ]
128}
129
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700130// returns the schedule for a given test
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700131def getTestSchedule( test ){
132 return allTests[ test ][ "schedule" ]
133}
134
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700135// returns a list of days from the given schedule
Jeremy Ronquillo64eeeb12019-05-13 11:19:46 -0700136def convertScheduleKeyToDays( sch ){
137 return schedules[ sch ]
Jeremy Ronquillo14ecc172018-03-05 09:57:17 -0800138}
139
Jeremy Ronquilloa37920b2019-05-23 14:34:25 -0700140def convertBranchCodeToBranch( branch_code, withPrefix=true ){
141 for ( String branch_type in branches.keySet() ){
142 for ( String b in branches[ branch_type ].keySet() ){
143 if ( branch_code == b ){
144 return withPrefix ? ( "onos-" + branches[ branch_type ][ b ] ) : branches[ branch_type ][ b ]
145 }
146 }
147 }
148 return branch_code
149}
150
Jon Hall6af749d2018-05-29 12:59:47 -0700151return this