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. |
| 120 | // Example: converts onos-1.x to onos-1.15 |
| 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 | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 132 | // given a branch, returns the corresponding branch code (hack) |
| 133 | // Example: given "onos-1.15", returns "onos-1.x" |
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 | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 136 | return branch |
Jeremy Ronquillo | 94c0e27 | 2019-06-11 13:51:10 -0700 | [diff] [blame] | 137 | } else if ( branch.substring( 0, 1 ) == "o" ) { |
| 138 | return branch.substring( 0, 6 ) + ".x" |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 139 | } else { |
| 140 | return "onos-" + branch.substring( 0, 1 ) + ".x" |
| 141 | } |
| 142 | } |
| 143 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 144 | // given a branch without a prefix, returns the branch with the "onos-" prefix |
| 145 | def addPrefixToBranch( branchNoPrefix ){ |
| 146 | if ( branchNoPrefix == "master" ){ |
| 147 | return "master" |
| 148 | } else { |
| 149 | return "onos-" + branchNoPrefix |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // 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] | 154 | def removePrefixFromBranch( branchWithPrefix ){ |
| 155 | return branchWithPrefix.minus( "onos-" ) |
| 156 | } |
| 157 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 158 | // ************* |
| 159 | // Test Category |
| 160 | // ************* |
| 161 | |
| 162 | // given a test category ("FUNC", "HA", etc.), returns all tests associated with that category |
| 163 | def getTestsFromCategory( category, tests=[:] ){ |
| 164 | testsFromCategoryResult = [:] |
| 165 | if ( tests == [:] ){ |
| 166 | tests = allTests |
| 167 | } |
| 168 | for ( String test_name in tests.keySet() ){ |
| 169 | if ( getCategoryOfTest( test_name ) == category ){ |
| 170 | testsFromCategoryResult.put( test_name, tests[ test_name ] ) |
| 171 | } |
| 172 | } |
| 173 | return testsFromCategoryResult |
| 174 | } |
| 175 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 176 | // 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] | 177 | def getCategoryOfTest( test_name, tests=[:] ){ |
| 178 | if ( tests == [:] ){ |
| 179 | tests = allTests |
| 180 | } |
| 181 | return tests[ test_name ][ "category" ] |
| 182 | } |
| 183 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 184 | // returns all categories of all tests, or the given test list |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 185 | def getAllTestCategories( tests=[:] ){ |
| 186 | testCategoriesResult = [] |
| 187 | if ( tests == [:] ){ |
| 188 | tests = allTests |
| 189 | } |
| 190 | for ( String test_name in tests.keySet() ){ |
| 191 | category = getCategoryOfTest( test_name, tests ) |
| 192 | if ( !testCategoriesResult.contains( category ) ){ |
| 193 | testCategoriesResult += category |
| 194 | } |
| 195 | } |
| 196 | return testCategoriesResult |
| 197 | } |
| 198 | |
| 199 | // ******************** |
| 200 | // Test Schedule / Days |
| 201 | // ******************** |
| 202 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 203 | // given a day, returns schedules that contain that day |
| 204 | def getValidSchedules( day ){ |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 205 | validSchedules = [] |
| 206 | for ( String key in schedules.keySet() ){ |
| 207 | if ( schedules[ key ].contains( day ) ){ |
| 208 | validSchedules += key |
| 209 | } |
| 210 | } |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 211 | return validSchedules |
| 212 | } |
| 213 | |
Jeremy Ronquillo | edb663b | 2019-06-26 14:09:38 -0700 | [diff] [blame] | 214 | // 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] | 215 | def getTestsFromDay( day, tests=[:] ){ |
| 216 | resultDict = [:] |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 217 | if ( tests == [:] ){ |
| 218 | tests = allTests |
| 219 | } |
| 220 | validSchedules = getValidSchedules( day ) |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 221 | for ( String key in tests.keySet() ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 222 | scheduleProperty = getTestScheduleProperty( key, "day", tests ) |
| 223 | for ( b in scheduleProperty.keySet() ){ |
| 224 | if ( validSchedules.contains( scheduleProperty[ b ] ) ){ |
| 225 | resultDict.put( key, tests[ key ] ) |
| 226 | break |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 230 | return resultDict |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 233 | // ********** |
| 234 | // Node Label |
| 235 | // ********** |
| 236 | |
| 237 | // Given a node label and branch, return all tests that run on that node. |
| 238 | def getTestsFromNodeLabel( nodeLabel, branch, tests=[:] ){ |
| 239 | nodeLabelTestsResult = [:] |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 240 | if ( tests == [:] ){ |
| 241 | tests = allTests |
| 242 | } |
| 243 | for ( String key in tests.keySet() ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 244 | branchNodeLabelMap = getTestScheduleProperty( key, "nodeLabel", tests ) |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 245 | if ( branchNodeLabelMap[ convertBranchToBranchCode( branch ) ] == nodeLabel ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 246 | nodeLabelTestsResult.put( key, tests[ key ] ) |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 249 | return nodeLabelTestsResult |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 252 | // Given a test name and branch, return the node label associated. |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 253 | def getNodeLabel( test_name, branch, tests=[:] ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 254 | if ( tests == [:] ){ |
| 255 | tests = allTests |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 256 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 257 | result = getTestScheduleProperty( test_name, "nodeLabel", tests ) |
| 258 | if ( result == [:] ){ |
| 259 | return "UNKNOWN" |
| 260 | } else { |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 261 | return result[ convertBranchToBranchCode( branch ) ] |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 262 | } |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Jeremy Ronquillo | 21c29fc | 2019-06-05 11:15:24 -0700 | [diff] [blame] | 265 | // given a branch, returns all nodeLabels from all tests, or a given test list |
| 266 | def getAllNodeLabels( branch, tests=[:] ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 267 | nodeLabelResult = [] |
| 268 | if ( tests == [:] ){ |
| 269 | tests = allTests |
| 270 | } |
| 271 | for ( test_name in tests.keySet() ){ |
| 272 | nodeLabel = getNodeLabel( test_name, branch, tests ) |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 273 | if ( !nodeLabelResult.contains( nodeLabel ) && nodeLabel != null ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 274 | nodeLabelResult += nodeLabel |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 275 | } |
| 276 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 277 | return nodeLabelResult |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 280 | return this |