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 | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 26 | def init(){ |
Jeremy Ronquillo | bc631c1 | 2019-05-21 15:29:04 -0700 | [diff] [blame] | 27 | def tests_buffer = readTrusted( "TestON/JenkinsFile/dependencies/tests.json" ) |
| 28 | def schedules_buffer = readTrusted( "TestON/JenkinsFile/dependencies/schedule.json" ) |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 29 | def branches_buffer = readTrusted( "TestON/JenkinsFile/dependencies/branches.json" ) |
Jeremy Ronquillo | 266b92e | 2019-05-21 15:45:20 -0700 | [diff] [blame] | 30 | allTests = readJSON text: tests_buffer |
| 31 | schedules = readJSON text: schedules_buffer |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 32 | branches = readJSON text: branches_buffer |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 33 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 34 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 35 | // *************** |
| 36 | // General Methods |
| 37 | // *************** |
| 38 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 39 | // returns the entire set of TestON tests from the json file |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 40 | def getAllTests(){ |
| 41 | return allTests |
| 42 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 43 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 44 | // returns the entire set of schedules from the json file |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 45 | def getSchedules(){ |
| 46 | return schedules |
| 47 | } |
| 48 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 49 | // returns a list of days corresponding to the given schedule code |
| 50 | def convertScheduleKeyToDays( sch ){ |
| 51 | return schedules[ sch ] |
| 52 | } |
| 53 | |
| 54 | // given a test dictionary, returns a list of tests as a string |
| 55 | def 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 | |
| 63 | def getTestsFromStringList( list ){ |
| 64 | testsResult = [:] |
| 65 | for ( item in list ){ |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 66 | if ( allTests.keySet().contains( item ) ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 67 | 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 |
| 75 | def 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 Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 88 | def getAllBranches(){ |
| 89 | return branches |
| 90 | } |
| 91 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 92 | // ******** |
| 93 | // Branches |
| 94 | // ******** |
| 95 | |
| 96 | // given a day, returns all branches that are run on that day |
| 97 | def getBranchesFromDay( day, tests=[:] ){ |
| 98 | branchesFromDayResult = [] |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 99 | if ( tests == [:] ){ |
| 100 | tests = allTests |
| 101 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 102 | validSchedules = getValidSchedules( day ) |
| 103 | |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 104 | for ( String key in tests.keySet() ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 105 | for ( subDict in tests[ key ][ "schedules" ] ){ |
| 106 | sch = subDict[ "day" ] |
| 107 | if ( validSchedules.contains( sch ) && !branchesFromDayResult.contains( sch ) ){ |
Jeremy Ronquillo | 31ed901 | 2019-06-11 14:28:59 -0700 | [diff] [blame] | 108 | branchesFromDayResult += convertBranchCodeToBranch( subDict[ "branch" ], false ) |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 109 | } |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 110 | } |
| 111 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 112 | return branchesFromDayResult |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 115 | // Converts a branch code to an actual ONOS branch. |
| 116 | // Example: converts onos-1.x to onos-1.15 |
| 117 | def 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 Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 128 | def convertBranchToBranchCode( branch ){ |
Jeremy Ronquillo | 94c0e27 | 2019-06-11 13:51:10 -0700 | [diff] [blame] | 129 | if ( branch == "master" ){ |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 130 | return branch |
Jeremy Ronquillo | 94c0e27 | 2019-06-11 13:51:10 -0700 | [diff] [blame] | 131 | } else if ( branch.substring( 0, 1 ) == "o" ) { |
| 132 | return branch.substring( 0, 6 ) + ".x" |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 133 | } else { |
| 134 | return "onos-" + branch.substring( 0, 1 ) + ".x" |
| 135 | } |
| 136 | } |
| 137 | |
Jeremy Ronquillo | 31ed901 | 2019-06-11 14:28:59 -0700 | [diff] [blame] | 138 | def removePrefixFromBranch( branchWithPrefix ){ |
| 139 | return branchWithPrefix.minus( "onos-" ) |
| 140 | } |
| 141 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 142 | // ************* |
| 143 | // Test Category |
| 144 | // ************* |
| 145 | |
| 146 | // given a test category ("FUNC", "HA", etc.), returns all tests associated with that category |
| 147 | def 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 | |
| 160 | def getCategoryOfTest( test_name, tests=[:] ){ |
| 161 | if ( tests == [:] ){ |
| 162 | tests = allTests |
| 163 | } |
| 164 | return tests[ test_name ][ "category" ] |
| 165 | } |
| 166 | |
| 167 | def 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 Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 185 | // given a day, returns schedules that contain that day |
| 186 | def getValidSchedules( day ){ |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 187 | validSchedules = [] |
| 188 | for ( String key in schedules.keySet() ){ |
| 189 | if ( schedules[ key ].contains( day ) ){ |
| 190 | validSchedules += key |
| 191 | } |
| 192 | } |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 193 | return validSchedules |
| 194 | } |
| 195 | |
| 196 | // given a day and branch, 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] | 197 | def getTestsFromDay( day, tests=[:] ){ |
| 198 | resultDict = [:] |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 199 | if ( tests == [:] ){ |
| 200 | tests = allTests |
| 201 | } |
| 202 | validSchedules = getValidSchedules( day ) |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 203 | for ( String key in tests.keySet() ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 204 | 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 Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 212 | return resultDict |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 215 | // ********** |
| 216 | // Node Label |
| 217 | // ********** |
| 218 | |
| 219 | // Given a node label and branch, return all tests that run on that node. |
| 220 | def getTestsFromNodeLabel( nodeLabel, branch, tests=[:] ){ |
| 221 | nodeLabelTestsResult = [:] |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 222 | if ( tests == [:] ){ |
| 223 | tests = allTests |
| 224 | } |
| 225 | for ( String key in tests.keySet() ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 226 | branchNodeLabelMap = getTestScheduleProperty( key, "nodeLabel", tests ) |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 227 | if ( branchNodeLabelMap[ convertBranchToBranchCode( branch ) ] == nodeLabel ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 228 | nodeLabelTestsResult.put( key, tests[ key ] ) |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 231 | return nodeLabelTestsResult |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 234 | // Given a test name and branch, return the node label associated. |
| 235 | def getNodeLabel( test_name, branch, tests ){ |
| 236 | if ( tests == [:] ){ |
| 237 | tests = allTests |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 238 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 239 | result = getTestScheduleProperty( test_name, "nodeLabel", tests ) |
| 240 | if ( result == [:] ){ |
| 241 | return "UNKNOWN" |
| 242 | } else { |
Jeremy Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 243 | return result[ convertBranchToBranchCode( branch ) ] |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 244 | } |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 247 | def 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 Ronquillo | a5aa7c1 | 2019-06-04 10:26:36 -0700 | [diff] [blame] | 254 | if ( !nodeLabelResult.contains( nodeLabel ) && nodeLabel != null ){ |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 255 | nodeLabelResult += nodeLabel |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 256 | } |
| 257 | } |
Jeremy Ronquillo | 96e2bd3 | 2019-05-28 15:40:18 -0700 | [diff] [blame] | 258 | return nodeLabelResult |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Jon Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 261 | return this |