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 | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 35 | // returns the entire set of TestON tests from the json file |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 36 | def getAllTests(){ |
| 37 | return allTests |
| 38 | } |
Devin Lim | f517519 | 2018-05-14 19:13:22 -0700 | [diff] [blame] | 39 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 40 | // returns the entire set of schedules from the json file |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 41 | def getSchedules(){ |
| 42 | return schedules |
| 43 | } |
| 44 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 45 | def getAllBranches(){ |
| 46 | return branches |
| 47 | } |
| 48 | |
| 49 | // given a test category ("FUNC", "HA", etc.), returns all tests associated with that category |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 50 | def 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 Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 63 | // given a day, returns schedules that contain that day |
| 64 | def getValidSchedules( day ){ |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 65 | validSchedules = [] |
| 66 | for ( String key in schedules.keySet() ){ |
| 67 | if ( schedules[ key ].contains( day ) ){ |
| 68 | validSchedules += key |
| 69 | } |
| 70 | } |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 71 | return validSchedules |
| 72 | } |
| 73 | |
| 74 | // given a day and branch, returns all tests that run on the given day on the given branch |
| 75 | def getTestsFromDay( day, branch, tests=[:] ){ |
| 76 | result = [:] |
| 77 | if ( tests == [:] ){ |
| 78 | tests = allTests |
| 79 | } |
| 80 | validSchedules = getValidSchedules( day ) |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 81 | 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 Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 90 | // given a day, returns all branches that are run on that day |
| 91 | def 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 Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 110 | def 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 Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 121 | // returns the test list as a string |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 122 | def getTestListAsString( tests ){ |
| 123 | result = "" |
Jeremy Ronquillo | e81fb41 | 2019-05-22 10:03:05 -0700 | [diff] [blame] | 124 | for ( String test in tests.keySet() ){ |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 125 | result += test + "," |
| 126 | } |
| 127 | return result[ 0..-2 ] |
| 128 | } |
| 129 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 130 | // returns the schedule for a given test |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 131 | def getTestSchedule( test ){ |
| 132 | return allTests[ test ][ "schedule" ] |
| 133 | } |
| 134 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 135 | // returns a list of days from the given schedule |
Jeremy Ronquillo | 64eeeb1 | 2019-05-13 11:19:46 -0700 | [diff] [blame] | 136 | def convertScheduleKeyToDays( sch ){ |
| 137 | return schedules[ sch ] |
Jeremy Ronquillo | 14ecc17 | 2018-03-05 09:57:17 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Jeremy Ronquillo | a37920b | 2019-05-23 14:34:25 -0700 | [diff] [blame^] | 140 | def 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 Hall | 6af749d | 2018-05-29 12:59:47 -0700 | [diff] [blame] | 151 | return this |