Devin Lim | e1346f4 | 2018-05-15 15:41:36 -0700 | [diff] [blame] | 1 | #!groovy |
| 2 | |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 3 | // Copyright 2019 Open Networking Foundation (ONF) |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 4 | // |
| 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 Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 22 | allTests = [:] |
| 23 | schedules = [:] |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 24 | branches = [:] |
Jeremy Ronquillo | 14ecc17 | 2018-03-05 09:57:17 -0800 | [diff] [blame] | 25 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 26 | // read all json files and save as maps |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 27 | def init(){ |
Jeremy Ronquillo | bc631c1 | 2019-05-21 15:29:04 -0700 | [diff] [blame] | 28 | def tests_buffer = readTrusted( "TestON/JenkinsFile/dependencies/tests.json" ) |
| 29 | def schedules_buffer = readTrusted( "TestON/JenkinsFile/dependencies/schedule.json" ) |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 30 | def branches_buffer = readTrusted( "TestON/JenkinsFile/dependencies/branches.json" ) |
Jeremy Ronquillo | 266b92e | 2019-05-21 15:45:20 -0700 | [diff] [blame] | 31 | allTests = readJSON text: tests_buffer |
| 32 | schedules = readJSON text: schedules_buffer |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 33 | branches = readJSON text: branches_buffer |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 34 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 35 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 36 | // *************** |
| 37 | // General Methods |
| 38 | // *************** |
| 39 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 40 | // returns the entire set of TestON tests from the json file |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 41 | def getAllTests(){ |
| 42 | return allTests |
| 43 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 44 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 45 | // returns the entire set of schedules from the json file |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 46 | def getSchedules(){ |
| 47 | return schedules |
| 48 | } |
| 49 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 50 | // returns a list of days corresponding to the given schedule code |
| 51 | def convertScheduleKeyToDays( sch ){ |
| 52 | return schedules[ sch ] |
| 53 | } |
| 54 | |
| 55 | // given a test dictionary, returns a list of tests as a string |
| 56 | def 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 Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 64 | // given a list of tests as a string, returns the list of tests as a map, similar formatted to tests.json |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 65 | def getTestsFromStringList( list ){ |
| 66 | testsResult = [:] |
| 67 | for ( item in list ){ |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 68 | if ( allTests.keySet().contains( item ) ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 69 | 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 |
| 77 | def 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 Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 90 | // ******** |
| 91 | // Branches |
| 92 | // ******** |
| 93 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 94 | // returns all branches from branches.json |
| 95 | def getAllBranches(){ |
| 96 | return branches |
| 97 | } |
| 98 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 99 | // given a day, returns all branches that are run on that day |
| 100 | def getBranchesFromDay( day, tests=[:] ){ |
| 101 | branchesFromDayResult = [] |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 102 | if ( tests == [:] ){ |
| 103 | tests = allTests |
| 104 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 105 | validSchedules = getValidSchedules( day ) |
| 106 | |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 107 | for ( String key in tests.keySet() ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 108 | for ( subDict in tests[ key ][ "schedules" ] ){ |
| 109 | sch = subDict[ "day" ] |
Jeremy Ronquillo | edb663b | 2019-06-26 14:09:38 -0700 | [diff] [blame] | 110 | new_branch = convertBranchCodeToBranch( subDict[ "branch" ], false ) |
| 111 | if ( validSchedules.contains( sch ) && !branchesFromDayResult.contains( new_branch ) ){ |
| 112 | branchesFromDayResult += new_branch |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 113 | } |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 116 | return branchesFromDayResult |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 119 | // Converts a branch code to an actual ONOS branch. |
Jeremy Ronquillo | f5482c9 | 2020-12-09 16:30:49 -0800 | [diff] [blame] | 120 | // Example: converts onos-LTS1 to onos-1.15 |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 121 | def 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 Ronquillo | f5482c9 | 2020-12-09 16:30:49 -0800 | [diff] [blame] | 132 | // given a branch, returns the corresponding branch code |
| 133 | // Example: given "onos-1.15", returns "onos-LTS1" |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 134 | def convertBranchToBranchCode( branch ){ |
Jeremy Ronquillo | 94c0e27 | 2019-06-11 13:51:10 -0700 | [diff] [blame] | 135 | if ( branch == "master" ){ |
Jeremy Ronquillo | f5482c9 | 2020-12-09 16:30:49 -0800 | [diff] [blame] | 136 | return branch |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 137 | } |
Jeremy Ronquillo | f5482c9 | 2020-12-09 16:30:49 -0800 | [diff] [blame] | 138 | for ( String branch_type in branches.keySet() ){ |
| 139 | for ( String b in branches[ branch_type ].keySet() ){ |
| 140 | if ( branches[ branch_type ][ b ] == branch ){ |
| 141 | return b |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | return "UNKNOWN" |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 148 | // given a branch without a prefix, returns the branch with the "onos-" prefix |
| 149 | def addPrefixToBranch( branchNoPrefix ){ |
| 150 | if ( branchNoPrefix == "master" ){ |
| 151 | return "master" |
| 152 | } else { |
| 153 | return "onos-" + branchNoPrefix |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // given a branch with the prefix "onos-", returns the branch without the prefix |
Jeremy Ronquillo | 31ed901 | 2019-06-11 14:28:59 -0700 | [diff] [blame] | 158 | def removePrefixFromBranch( branchWithPrefix ){ |
| 159 | return branchWithPrefix.minus( "onos-" ) |
| 160 | } |
| 161 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 162 | // ************* |
| 163 | // Test Category |
| 164 | // ************* |
| 165 | |
| 166 | // given a test category ("FUNC", "HA", etc.), returns all tests associated with that category |
| 167 | def getTestsFromCategory( category, tests=[:] ){ |
| 168 | testsFromCategoryResult = [:] |
| 169 | if ( tests == [:] ){ |
| 170 | tests = allTests |
| 171 | } |
| 172 | for ( String test_name in tests.keySet() ){ |
| 173 | if ( getCategoryOfTest( test_name ) == category ){ |
| 174 | testsFromCategoryResult.put( test_name, tests[ test_name ] ) |
| 175 | } |
| 176 | } |
| 177 | return testsFromCategoryResult |
| 178 | } |
| 179 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 180 | // given the test name, returns the category (FUNC, HA, etc.) of that test |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 181 | def getCategoryOfTest( test_name, tests=[:] ){ |
| 182 | if ( tests == [:] ){ |
| 183 | tests = allTests |
| 184 | } |
| 185 | return tests[ test_name ][ "category" ] |
| 186 | } |
| 187 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 188 | // returns all categories of all tests, or the given test list |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 189 | def getAllTestCategories( tests=[:] ){ |
| 190 | testCategoriesResult = [] |
| 191 | if ( tests == [:] ){ |
| 192 | tests = allTests |
| 193 | } |
| 194 | for ( String test_name in tests.keySet() ){ |
| 195 | category = getCategoryOfTest( test_name, tests ) |
| 196 | if ( !testCategoriesResult.contains( category ) ){ |
| 197 | testCategoriesResult += category |
| 198 | } |
| 199 | } |
| 200 | return testCategoriesResult |
| 201 | } |
| 202 | |
| 203 | // ******************** |
| 204 | // Test Schedule / Days |
| 205 | // ******************** |
| 206 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 207 | // given a day, returns schedules that contain that day |
| 208 | def getValidSchedules( day ){ |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 209 | validSchedules = [] |
| 210 | for ( String key in schedules.keySet() ){ |
| 211 | if ( schedules[ key ].contains( day ) ){ |
| 212 | validSchedules += key |
| 213 | } |
| 214 | } |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 215 | return validSchedules |
| 216 | } |
| 217 | |
Jeremy Ronquillo | edb663b | 2019-06-26 14:09:38 -0700 | [diff] [blame] | 218 | // given a day, returns all tests that run on the given day on the given branch |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 219 | def getTestsFromDay( day, tests=[:] ){ |
| 220 | resultDict = [:] |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 221 | if ( tests == [:] ){ |
| 222 | tests = allTests |
| 223 | } |
| 224 | validSchedules = getValidSchedules( day ) |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 225 | for ( String key in tests.keySet() ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 226 | scheduleProperty = getTestScheduleProperty( key, "day", tests ) |
| 227 | for ( b in scheduleProperty.keySet() ){ |
| 228 | if ( validSchedules.contains( scheduleProperty[ b ] ) ){ |
| 229 | resultDict.put( key, tests[ key ] ) |
| 230 | break |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 234 | return resultDict |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 237 | // ********** |
| 238 | // Node Label |
| 239 | // ********** |
| 240 | |
| 241 | // Given a node label and branch, return all tests that run on that node. |
| 242 | def getTestsFromNodeLabel( nodeLabel, branch, tests=[:] ){ |
| 243 | nodeLabelTestsResult = [:] |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 244 | if ( tests == [:] ){ |
| 245 | tests = allTests |
| 246 | } |
| 247 | for ( String key in tests.keySet() ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 248 | branchNodeLabelMap = getTestScheduleProperty( key, "nodeLabel", tests ) |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 249 | if ( branchNodeLabelMap[ convertBranchToBranchCode( branch ) ] == nodeLabel ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 250 | nodeLabelTestsResult.put( key, tests[ key ] ) |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 253 | return nodeLabelTestsResult |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 256 | // Given a test name and branch, return the node label associated. |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 257 | def getNodeLabel( test_name, branch, tests=[:] ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 258 | if ( tests == [:] ){ |
| 259 | tests = allTests |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 260 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 261 | result = getTestScheduleProperty( test_name, "nodeLabel", tests ) |
| 262 | if ( result == [:] ){ |
| 263 | return "UNKNOWN" |
| 264 | } else { |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 265 | return result[ convertBranchToBranchCode( branch ) ] |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 266 | } |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 269 | // given a branch, returns all nodeLabels from all tests, or a given test list |
| 270 | def getAllNodeLabels( branch, tests=[:] ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 271 | nodeLabelResult = [] |
| 272 | if ( tests == [:] ){ |
| 273 | tests = allTests |
| 274 | } |
| 275 | for ( test_name in tests.keySet() ){ |
| 276 | nodeLabel = getNodeLabel( test_name, branch, tests ) |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 277 | if ( !nodeLabelResult.contains( nodeLabel ) && nodeLabel != null ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 278 | nodeLabelResult += nodeLabel |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 279 | } |
| 280 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 281 | return nodeLabelResult |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 284 | return this |