Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2016 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 21 | |
| 22 | def checkRouteNum( main, routeNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 23 | import time |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 24 | main.step( "Check routes installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 25 | wait = int( main.params['timers']['PathAvailable'] ) |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 26 | main.log.info( "Route number expected:" ) |
| 27 | main.log.info( routeNumExpected ) |
| 28 | main.log.info( "Route number from ONOS CLI:" ) |
| 29 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 30 | routeNumActual = main.Cluster.active( 0 ).CLI.ipv4RouteNumber() |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 31 | if routeNumActual != routeNumExpected: |
| 32 | time.sleep( wait ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 33 | routeNumActual = main.Cluster.active( 0 ).CLI.ipv4RouteNumber() |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 34 | main.log.info( routeNumActual ) |
| 35 | utilities.assertEquals( \ |
| 36 | expect = routeNumExpected, actual = routeNumActual, |
pingping-lin | b3ebd3f | 2015-09-28 22:17:05 -0700 | [diff] [blame] | 37 | onpass = "Route number is correct!", |
| 38 | onfail = "Route number is wrong!" ) |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 39 | |
| 40 | def checkM2SintentNum( main, intentNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 41 | import time |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 42 | main.step( "Check M2S intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 43 | wait = int( main.params['timers']['PathAvailable'] ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 44 | jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat = True, summary = True, |
| 45 | TYPE = "multiPointToSinglePoint" ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 46 | try: |
| 47 | intentNumActual = jsonResult['installed'] |
| 48 | except TypeError as e: |
| 49 | intentNumActual = -1 |
| 50 | main.log.error( e ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 51 | if intentNumActual != intentNumExpected: |
| 52 | time.sleep( wait ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 53 | jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat = True, summary = True, |
| 54 | TYPE = "multiPointToSinglePoint" ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 55 | try: |
| 56 | intentNumActual = jsonResult['installed'] |
| 57 | except TypeError as e: |
| 58 | intentNumActual = -1 |
| 59 | main.log.error( e ) |
| 60 | main.log.info( "Intent number expected: {}".format( intentNumExpected ) ) |
| 61 | main.log.info( "Intent number from ONOS CLI: {}".format( intentNumActual ) ) |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 62 | utilities.assertEquals( \ |
| 63 | expect = intentNumExpected, actual = intentNumActual, |
pingping-lin | b3ebd3f | 2015-09-28 22:17:05 -0700 | [diff] [blame] | 64 | onpass = "M2S intent number is correct!", |
| 65 | onfail = "M2S intent number is wrong!" ) |
pingping-lin | 4f80c49 | 2015-09-15 14:34:42 -0700 | [diff] [blame] | 66 | |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 67 | def checkP2PintentNum( main, intentNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 68 | import time |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 69 | main.step( "Check P2P intents installed" ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 70 | wait = int( main.params['timers']['PathAvailable'] ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 71 | jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat = True, summary = True, |
| 72 | TYPE = "pointToPoint" ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 73 | try: |
| 74 | intentNumActual = jsonResult['installed'] |
| 75 | except TypeError as e: |
| 76 | intentNumActual = -1 |
| 77 | main.log.error( e ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 78 | |
| 79 | if intentNumActual != intentNumExpected: |
| 80 | time.sleep( wait ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 81 | jsonResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat = True, summary = True, |
| 82 | TYPE = "pointToPoint" ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 83 | try: |
| 84 | intentNumActual = jsonResult['installed'] |
| 85 | except TypeError as e: |
| 86 | intentNumActual = -1 |
| 87 | main.log.error( e ) |
| 88 | main.log.info( "Intent number expected: {}".format( intentNumExpected ) ) |
| 89 | main.log.info( "Intent number from ONOS CLI: {}".format( intentNumActual ) ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 90 | utilities.assertEquals( \ |
| 91 | expect = intentNumExpected, actual = intentNumActual, |
pingping-lin | b3ebd3f | 2015-09-28 22:17:05 -0700 | [diff] [blame] | 92 | onpass = "P2P intent number is correct!", |
| 93 | onfail = "P2P intent number is wrong!" ) |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 94 | |
| 95 | def checkFlowNum( main, switch, flowNumExpected ): |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 96 | import time |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 97 | main.step( "Check flow entry number in " + switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 98 | wait = int( main.params['timers']['PathAvailable'] ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 99 | main.log.info( "Flow number expected: {}".format( flowNumExpected ) ) |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 100 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 101 | if flowNumActual != flowNumExpected : |
| 102 | time.sleep( wait ) |
| 103 | flowNumActual = main.Mininet.getSwitchFlowCount( switch ) |
Jon Hall | 2aa1656 | 2017-05-23 11:26:46 -0700 | [diff] [blame] | 104 | main.log.info( "Flow number actual: {}".format( flowNumActual ) ) |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 105 | utilities.assertEquals( \ |
| 106 | expect = flowNumExpected, actual = flowNumActual, |
pingping-lin | b3ebd3f | 2015-09-28 22:17:05 -0700 | [diff] [blame] | 107 | onpass = "Flow number in " + switch + " is correct!", |
| 108 | onfail = "Flow number in " + switch + " is wrong!" ) |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 109 | |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 110 | |
alison | e4121a9 | 2016-11-22 16:31:36 -0800 | [diff] [blame] | 111 | def pingSpeakerToPeer( main, speakers = [ "spk1" ], |
| 112 | peers = [ "peer64514", "peer64515", "peer64516" ], |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 113 | expectAllSuccess = True ): |
| 114 | """ |
| 115 | Carry out ping test between each BGP speaker and peer pair |
| 116 | Optional argument: |
| 117 | * speakers - BGP speakers |
| 118 | * peers - BGP peers |
| 119 | * expectAllSuccess - boolean indicating if you expect all results |
| 120 | succeed if True, otherwise expect all results fail if False |
| 121 | """ |
| 122 | if len( speakers ) == 0: |
| 123 | main.log.error( "Parameter speakers can not be empty." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 124 | main.cleanAndExit() |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 125 | if len( peers ) == 0: |
| 126 | main.log.error( "Parameter speakers can not be empty." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 127 | main.cleanAndExit() |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 128 | |
| 129 | if expectAllSuccess: |
pingping-lin | 060d287 | 2015-09-29 18:16:29 -0700 | [diff] [blame] | 130 | main.step( "BGP speakers ping peers, expect all tests to succeed" ) |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 131 | else: |
pingping-lin | 060d287 | 2015-09-29 18:16:29 -0700 | [diff] [blame] | 132 | main.step( "BGP speakers ping peers, expect all tests to fail" ) |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 133 | |
| 134 | result = True |
| 135 | if expectAllSuccess: |
| 136 | for speaker in speakers: |
| 137 | for peer in peers: |
| 138 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 139 | target = peer ) |
| 140 | result = result and ( tmpResult == main.TRUE ) |
| 141 | else: |
| 142 | for speaker in speakers: |
| 143 | for peer in peers: |
| 144 | tmpResult = main.Mininet.pingHost( src = speaker, |
| 145 | target = peer ) |
| 146 | |
| 147 | utilities.assert_equals( expect = True, actual = result, |
| 148 | onpass = "Ping test results are expected", |
| 149 | onfail = "Ping test results are Not expected" ) |
| 150 | |
| 151 | if result == False: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 152 | main.cleanAndExit() |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 153 | |
| 154 | |
alison | e4121a9 | 2016-11-22 16:31:36 -0800 | [diff] [blame] | 155 | def pingHostToHost( main, |
| 156 | hosts = [ "h64514", "h64515", "h64516" ], |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 157 | expectAllSuccess = True ): |
| 158 | """ |
| 159 | Carry out ping test between each BGP host pair |
| 160 | Optional argument: |
| 161 | * hosts - hosts behind BGP peer routers |
| 162 | * expectAllSuccess - boolean indicating if you expect all results |
| 163 | succeed if True, otherwise expect all results fail if False |
| 164 | """ |
Jon Hall | 6e9897d | 2016-02-29 14:41:32 -0800 | [diff] [blame] | 165 | main.step( "Check ping between each host pair, expect all to succede=" + |
| 166 | str( expectAllSuccess ) ) |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 167 | if len( hosts ) == 0: |
| 168 | main.log.error( "Parameter hosts can not be empty." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 169 | main.cleanAndExit() |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 170 | |
| 171 | result = True |
| 172 | if expectAllSuccess: |
| 173 | for srcHost in hosts: |
| 174 | for targetHost in hosts: |
| 175 | if srcHost != targetHost: |
| 176 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 177 | target = targetHost ) |
| 178 | result = result and ( tmpResult == main.TRUE ) |
| 179 | else: |
| 180 | for srcHost in hosts: |
| 181 | for targetHost in hosts: |
| 182 | if srcHost != targetHost: |
| 183 | tmpResult = main.Mininet.pingHost( src = srcHost, |
| 184 | target = targetHost ) |
| 185 | result = result and ( tmpResult == main.FALSE ) |
| 186 | |
| 187 | utilities.assert_equals( expect = True, actual = result, |
| 188 | onpass = "Ping test results are expected", |
| 189 | onfail = "Ping test results are Not expected" ) |
| 190 | |
pingping-lin | 581a366 | 2015-09-29 17:43:39 -0700 | [diff] [blame] | 191 | ''' |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 192 | if result == False: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 193 | main.cleanAndExit() |
pingping-lin | 581a366 | 2015-09-29 17:43:39 -0700 | [diff] [blame] | 194 | ''' |
pingping-lin | 829428d | 2015-09-22 20:50:00 -0700 | [diff] [blame] | 195 | |