Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2 | Description: This test is to determine if ONOS can handle |
| 3 | a minority of it's nodes restarting |
| 4 | |
| 5 | List of test cases: |
| 6 | CASE1: Compile ONOS and push it to the test machines |
| 7 | CASE2: Assign mastership to controllers |
| 8 | CASE3: Assign intents |
| 9 | CASE4: Ping across added host intents |
| 10 | CASE5: Reading state of ONOS |
| 11 | CASE6: The Failure case. |
| 12 | CASE7: Check state after control plane failure |
| 13 | CASE8: Compare topo |
| 14 | CASE9: Link s3-s28 down |
| 15 | CASE10: Link s3-s28 up |
| 16 | CASE11: Switch down |
| 17 | CASE12: Switch up |
| 18 | CASE13: Clean up |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 19 | CASE14: start election app on all onos nodes |
| 20 | CASE15: Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 21 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 22 | |
| 23 | |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 24 | class HATestMinorityRestart: |
| 25 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 26 | def __init__( self ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 27 | self.default = '' |
| 28 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 29 | def CASE1( self, main ): |
| 30 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 31 | CASE1 is to compile ONOS and push it to the test machines |
| 32 | |
| 33 | Startup sequence: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 34 | cell <name> |
| 35 | onos-verify-cell |
| 36 | NOTE: temporary - onos-remove-raft-logs |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 37 | onos-uninstall |
| 38 | start mininet |
| 39 | git pull |
| 40 | mvn clean install |
| 41 | onos-package |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 42 | onos-install -f |
| 43 | onos-wait-for-start |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 44 | start cli sessions |
| 45 | start tcpdump |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 46 | """ |
| 47 | main.log.report( |
| 48 | "ONOS HA test: Restart minority of ONOS nodes - initialization" ) |
| 49 | main.case( "Setting up test environment" ) |
| 50 | # TODO: save all the timers and output them for plotting |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 51 | |
| 52 | # load some vairables from the params file |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 53 | PULLCODE = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 54 | if main.params[ 'Git' ] == 'True': |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 55 | PULLCODE = True |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 56 | gitBranch = main.params[ 'branch' ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 57 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 58 | |
| 59 | # set global variables |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 60 | global ONOS1Ip |
| 61 | global ONOS1Port |
| 62 | global ONOS2Ip |
| 63 | global ONOS2Port |
| 64 | global ONOS3Ip |
| 65 | global ONOS3Port |
| 66 | global ONOS4Ip |
| 67 | global ONOS4Port |
| 68 | global ONOS5Ip |
| 69 | global ONOS5Port |
| 70 | global ONOS6Ip |
| 71 | global ONOS6Port |
| 72 | global ONOS7Ip |
| 73 | global ONOS7Port |
| 74 | global numControllers |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 75 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 76 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 77 | ONOS1Port = main.params[ 'CTRL' ][ 'port1' ] |
| 78 | ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ] |
| 79 | ONOS2Port = main.params[ 'CTRL' ][ 'port2' ] |
| 80 | ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ] |
| 81 | ONOS3Port = main.params[ 'CTRL' ][ 'port3' ] |
| 82 | ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ] |
| 83 | ONOS4Port = main.params[ 'CTRL' ][ 'port4' ] |
| 84 | ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ] |
| 85 | ONOS5Port = main.params[ 'CTRL' ][ 'port5' ] |
| 86 | ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ] |
| 87 | ONOS6Port = main.params[ 'CTRL' ][ 'port6' ] |
| 88 | ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ] |
| 89 | ONOS7Port = main.params[ 'CTRL' ][ 'port7' ] |
| 90 | numControllers = int( main.params[ 'num_controllers' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 91 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 92 | main.step( "Applying cell variable to environment" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 93 | cellResult = main.ONOSbench.setCell( cellName ) |
| 94 | verifyResult = main.ONOSbench.verifyCell() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 95 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 96 | # FIXME:this is short term fix |
| 97 | main.log.report( "Removing raft logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 98 | main.ONOSbench.onosRemoveRaftLogs() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 99 | main.log.report( "Uninstalling ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 100 | main.ONOSbench.onosUninstall( ONOS1Ip ) |
| 101 | main.ONOSbench.onosUninstall( ONOS2Ip ) |
| 102 | main.ONOSbench.onosUninstall( ONOS3Ip ) |
| 103 | main.ONOSbench.onosUninstall( ONOS4Ip ) |
| 104 | main.ONOSbench.onosUninstall( ONOS5Ip ) |
| 105 | main.ONOSbench.onosUninstall( ONOS6Ip ) |
| 106 | main.ONOSbench.onosUninstall( ONOS7Ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 107 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 108 | cleanInstallResult = main.TRUE |
| 109 | gitPullResult = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 110 | |
Jon Hall | 97f3175 | 2015-02-04 12:01:04 -0800 | [diff] [blame] | 111 | main.step( "Starting Mininet" ) |
| 112 | main.Mininet1.startNet( ) |
| 113 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 114 | main.step( "Compiling the latest version of ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 115 | if PULLCODE: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 116 | main.step( "Git checkout and pull " + gitBranch ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 117 | main.ONOSbench.gitCheckout( gitBranch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 118 | gitPullResult = main.ONOSbench.gitPull() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 119 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 120 | main.step( "Using mvn clean & install" ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 121 | cleanInstallResult = main.ONOSbench.cleanInstall() |
| 122 | else: |
| 123 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 124 | "clean install" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 125 | main.ONOSbench.getVersion( report=True ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 126 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 127 | main.step( "Creating ONOS package" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 128 | packageResult = main.ONOSbench.onosPackage() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 129 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 130 | main.step( "Installing ONOS package" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 131 | onos1InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 132 | node=ONOS1Ip ) |
| 133 | onos2InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 134 | node=ONOS2Ip ) |
| 135 | onos3InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 136 | node=ONOS3Ip ) |
| 137 | onos4InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 138 | node=ONOS4Ip ) |
| 139 | onos5InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 140 | node=ONOS5Ip ) |
| 141 | onos6InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 142 | node=ONOS6Ip ) |
| 143 | onos7InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 144 | node=ONOS7Ip ) |
| 145 | onosInstallResult = onos1InstallResult and onos2InstallResult\ |
| 146 | and onos3InstallResult and onos4InstallResult\ |
| 147 | and onos5InstallResult and onos6InstallResult\ |
| 148 | and onos7InstallResult |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 149 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 150 | main.step( "Checking if ONOS is up yet" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 151 | for i in range( 2 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 152 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 153 | if not onos1Isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 154 | main.log.report( "ONOS1 didn't start!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 155 | main.ONOSbench.onosStop( ONOS1Ip ) |
| 156 | main.ONOSbench.onosStart( ONOS1Ip ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 157 | onos2Isup = main.ONOSbench.isup( ONOS2Ip ) |
| 158 | if not onos2Isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 159 | main.log.report( "ONOS2 didn't start!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 160 | main.ONOSbench.onosStop( ONOS2Ip ) |
| 161 | main.ONOSbench.onosStart( ONOS2Ip ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 162 | onos3Isup = main.ONOSbench.isup( ONOS3Ip ) |
| 163 | if not onos3Isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 164 | main.log.report( "ONOS3 didn't start!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 165 | main.ONOSbench.onosStop( ONOS3Ip ) |
| 166 | main.ONOSbench.onosStart( ONOS3Ip ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 167 | onos4Isup = main.ONOSbench.isup( ONOS4Ip ) |
| 168 | if not onos4Isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 169 | main.log.report( "ONOS4 didn't start!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 170 | main.ONOSbench.onosStop( ONOS4Ip ) |
| 171 | main.ONOSbench.onosStart( ONOS4Ip ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 172 | onos5Isup = main.ONOSbench.isup( ONOS5Ip ) |
| 173 | if not onos5Isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 174 | main.log.report( "ONOS5 didn't start!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 175 | main.ONOSbench.onosStop( ONOS5Ip ) |
| 176 | main.ONOSbench.onosStart( ONOS5Ip ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 177 | onos6Isup = main.ONOSbench.isup( ONOS6Ip ) |
| 178 | if not onos6Isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 179 | main.log.report( "ONOS6 didn't start!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 180 | main.ONOSbench.onosStop( ONOS6Ip ) |
| 181 | main.ONOSbench.onosStart( ONOS6Ip ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 182 | onos7Isup = main.ONOSbench.isup( ONOS7Ip ) |
| 183 | if not onos7Isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 184 | main.log.report( "ONOS7 didn't start!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 185 | main.ONOSbench.onosStop( ONOS7Ip ) |
| 186 | main.ONOSbench.onosStart( ONOS7Ip ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 187 | onosIsupResult = onos1Isup and onos2Isup and onos3Isup\ |
| 188 | and onos4Isup and onos5Isup and onos6Isup and onos7Isup |
| 189 | if onosIsupResult == main.TRUE: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 190 | break |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 191 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 192 | cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip ) |
| 193 | cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip ) |
| 194 | cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip ) |
| 195 | cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip ) |
| 196 | cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip ) |
| 197 | cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip ) |
| 198 | cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip ) |
| 199 | cliResults = cliResult1 and cliResult2 and cliResult3 and\ |
| 200 | cliResult4 and cliResult5 and cliResult6 and cliResult7 |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 201 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 202 | main.step( "Start Packet Capture MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 203 | main.Mininet2.startTcpdump( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 204 | str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST ) |
| 205 | + "-MN.pcap", |
| 206 | intf=main.params[ 'MNtcpdump' ][ 'intf' ], |
| 207 | port=main.params[ 'MNtcpdump' ][ 'port' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 208 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 209 | case1Result = ( cleanInstallResult and packageResult and |
| 210 | cellResult and verifyResult and onosInstallResult |
| 211 | and onosIsupResult and cliResults ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 212 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 213 | utilities.assert_equals( expect=main.TRUE, actual=case1Result, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 214 | onpass="Test startup successful", |
| 215 | onfail="Test startup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 216 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 217 | if case1Result == main.FALSE: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 218 | main.cleanup() |
| 219 | main.exit() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 220 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 221 | def CASE2( self, main ): |
| 222 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 223 | Assign mastership to controllers |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 224 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 225 | import re |
| 226 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 227 | main.log.report( "Assigning switches to controllers" ) |
| 228 | main.case( "Assigning Controllers" ) |
| 229 | main.step( "Assign switches to controllers" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 230 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 231 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 232 | main.Mininet1.assignSwController( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 233 | sw=str( i ), |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 234 | count=numControllers, |
| 235 | ip1=ONOS1Ip, port1=ONOS1Port, |
| 236 | ip2=ONOS2Ip, port2=ONOS2Port, |
| 237 | ip3=ONOS3Ip, port3=ONOS3Port, |
| 238 | ip4=ONOS4Ip, port4=ONOS4Port, |
| 239 | ip5=ONOS5Ip, port5=ONOS5Port, |
| 240 | ip6=ONOS6Ip, port6=ONOS6Port, |
| 241 | ip7=ONOS7Ip, port7=ONOS7Port ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 242 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 243 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 244 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 245 | response = main.Mininet1.getSwController( "s" + str( i ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 246 | try: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 247 | main.log.info( str( response ) ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 248 | except Exception: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 249 | main.log.info( repr( response ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 250 | if re.search( "tcp:" + ONOS1Ip, response )\ |
| 251 | and re.search( "tcp:" + ONOS2Ip, response )\ |
| 252 | and re.search( "tcp:" + ONOS3Ip, response )\ |
| 253 | and re.search( "tcp:" + ONOS4Ip, response )\ |
| 254 | and re.search( "tcp:" + ONOS5Ip, response )\ |
| 255 | and re.search( "tcp:" + ONOS6Ip, response )\ |
| 256 | and re.search( "tcp:" + ONOS7Ip, response ): |
| 257 | mastershipCheck = mastershipCheck and main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 258 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 259 | mastershipCheck = main.FALSE |
| 260 | if mastershipCheck == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 261 | main.log.report( "Switch mastership assigned correctly" ) |
| 262 | utilities.assert_equals( |
| 263 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 264 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 265 | onpass="Switch mastership assigned correctly", |
| 266 | onfail="Switches not assigned correctly to controllers" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 267 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 268 | # Manually assign mastership to the controller we want |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 269 | roleCall = main.TRUE |
| 270 | roleCheck = main.TRUE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 271 | try: |
| 272 | # Assign switch |
| 273 | deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' ) |
| 274 | assert deviceId, "No device id for s1 in ONOS" |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 275 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 276 | deviceId, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 277 | ONOS1Ip ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 278 | # Check assignment |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 279 | if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 280 | roleCheck = roleCheck and main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 281 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 282 | roleCheck = roleCheck and main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 283 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 284 | # Assign switch |
| 285 | deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' ) |
| 286 | assert deviceId, "No device id for s28 in ONOS" |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 287 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 288 | deviceId, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 289 | ONOS1Ip ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 290 | # Check assignment |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 291 | if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 292 | roleCheck = roleCheck and main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 293 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 294 | roleCheck = roleCheck and main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 295 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 296 | # Assign switch |
| 297 | deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' ) |
| 298 | assert deviceId, "No device id for s2 in ONOS" |
| 299 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 300 | deviceId, |
| 301 | ONOS2Ip ) |
| 302 | # Check assignment |
| 303 | if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
| 304 | roleCheck = roleCheck and main.TRUE |
| 305 | else: |
| 306 | roleCheck = roleCheck and main.FALSE |
| 307 | |
| 308 | # Assign switch |
| 309 | deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' ) |
| 310 | assert deviceId, "No device id for s3 in ONOS" |
| 311 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 312 | deviceId, |
| 313 | ONOS2Ip ) |
| 314 | # Check assignment |
| 315 | if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
| 316 | roleCheck = roleCheck and main.TRUE |
| 317 | else: |
| 318 | roleCheck = roleCheck and main.FALSE |
| 319 | |
| 320 | # Assign switch |
| 321 | deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' ) |
| 322 | assert deviceId, "No device id for s5 in ONOS" |
| 323 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 324 | deviceId, |
| 325 | ONOS3Ip ) |
| 326 | # Check assignment |
| 327 | if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
| 328 | roleCheck = roleCheck and main.TRUE |
| 329 | else: |
| 330 | roleCheck = roleCheck and main.FALSE |
| 331 | |
| 332 | # Assign switch |
| 333 | deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' ) |
| 334 | assert deviceId, "No device id for s6 in ONOS" |
| 335 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 336 | deviceId, |
| 337 | ONOS3Ip ) |
| 338 | # Check assignment |
| 339 | if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
| 340 | roleCheck = roleCheck and main.TRUE |
| 341 | else: |
| 342 | roleCheck = roleCheck and main.FALSE |
| 343 | |
| 344 | # Assign switch |
| 345 | deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' ) |
| 346 | assert deviceId, "No device id for s4 in ONOS" |
| 347 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 348 | deviceId, |
| 349 | ONOS4Ip ) |
| 350 | # Check assignment |
| 351 | if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
| 352 | roleCheck = roleCheck and main.TRUE |
| 353 | else: |
| 354 | roleCheck = roleCheck and main.FALSE |
| 355 | |
| 356 | for i in range( 8, 18 ): |
| 357 | dpid = '3' + str( i ).zfill( 3 ) |
| 358 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 359 | assert deviceId, "No device id for s%i in ONOS" % i |
| 360 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 361 | deviceId, |
| 362 | ONOS5Ip ) |
| 363 | # Check assignment |
| 364 | if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
| 365 | roleCheck = roleCheck and main.TRUE |
| 366 | else: |
| 367 | roleCheck = roleCheck and main.FALSE |
| 368 | |
| 369 | deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' ) |
| 370 | assert deviceId, "No device id for s7 in ONOS" |
| 371 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 372 | deviceId, |
| 373 | ONOS6Ip ) |
| 374 | # Check assignment |
| 375 | if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
| 376 | roleCheck = roleCheck and main.TRUE |
| 377 | else: |
| 378 | roleCheck = roleCheck and main.FALSE |
| 379 | |
| 380 | for i in range( 18, 28 ): |
| 381 | dpid = '6' + str( i ).zfill( 3 ) |
| 382 | deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' ) |
| 383 | assert deviceId, "No device id for s%i in ONOS" % i |
| 384 | roleCall = roleCall and main.ONOScli1.deviceRole( |
| 385 | deviceId, |
| 386 | ONOS7Ip ) |
| 387 | # Check assignment |
| 388 | if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ): |
| 389 | roleCheck = roleCheck and main.TRUE |
| 390 | else: |
| 391 | roleCheck = roleCheck and main.FALSE |
| 392 | except ( AttributeError, AssertionError ): |
| 393 | main.log.exception( "Something is wrong with ONOS device view" ) |
| 394 | main.log.info( main.ONOScli1.devices() ) |
| 395 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 396 | utilities.assert_equals( |
| 397 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 398 | actual=roleCall, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 399 | onpass="Re-assigned switch mastership to designated controller", |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 400 | onfail="Something wrong with deviceRole calls" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 401 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 402 | utilities.assert_equals( |
| 403 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 404 | actual=roleCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 405 | onpass="Switches were successfully reassigned to designated " + |
| 406 | "controller", |
| 407 | onfail="Switches were not successfully reassigned" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 408 | mastershipCheck = mastershipCheck and roleCall and roleCheck |
| 409 | utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck, |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 410 | onpass="Switch mastership correctly assigned", |
| 411 | onfail="Error in (re)assigning switch" + |
| 412 | " mastership" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 413 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 414 | def CASE3( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 415 | """ |
| 416 | Assign intents |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 417 | """ |
| 418 | import time |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 419 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 420 | main.log.report( "Adding host intents" ) |
| 421 | main.case( "Adding host Intents" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 422 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 423 | main.step( "Discovering Hosts( Via pingall for now )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 424 | # FIXME: Once we have a host discovery mechanism, use that instead |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 425 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 426 | # install onos-app-fwd |
| 427 | main.log.info( "Install reactive forwarding app" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 428 | main.ONOScli1.featureInstall( "onos-app-fwd" ) |
| 429 | main.ONOScli2.featureInstall( "onos-app-fwd" ) |
| 430 | main.ONOScli3.featureInstall( "onos-app-fwd" ) |
| 431 | main.ONOScli4.featureInstall( "onos-app-fwd" ) |
| 432 | main.ONOScli5.featureInstall( "onos-app-fwd" ) |
| 433 | main.ONOScli6.featureInstall( "onos-app-fwd" ) |
| 434 | main.ONOScli7.featureInstall( "onos-app-fwd" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 435 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 436 | # REACTIVE FWD test |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 437 | pingResult = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 438 | time1 = time.time() |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 439 | pingResult = main.Mininet1.pingall() |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 440 | utilities.assert_equals( |
| 441 | expect=main.TRUE, |
| 442 | actual=pingResult, |
| 443 | onpass="Reactive Pingall test passed", |
| 444 | onfail="Reactive Pingall failed, one or more ping pairs failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 445 | time2 = time.time() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 446 | main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 447 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 448 | # uninstall onos-app-fwd |
| 449 | main.log.info( "Uninstall reactive forwarding app" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 450 | main.ONOScli1.featureUninstall( "onos-app-fwd" ) |
| 451 | main.ONOScli2.featureUninstall( "onos-app-fwd" ) |
| 452 | main.ONOScli3.featureUninstall( "onos-app-fwd" ) |
| 453 | main.ONOScli4.featureUninstall( "onos-app-fwd" ) |
| 454 | main.ONOScli5.featureUninstall( "onos-app-fwd" ) |
| 455 | main.ONOScli6.featureUninstall( "onos-app-fwd" ) |
| 456 | main.ONOScli7.featureUninstall( "onos-app-fwd" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 457 | # timeout for fwd flows |
| 458 | time.sleep( 10 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 459 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 460 | main.step( "Add host intents" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 461 | intentIds = [] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 462 | # TODO: move the host numbers to params |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 463 | # Maybe look at all the paths we ping? |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 464 | intentAddResult = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 465 | hostResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 466 | for i in range( 8, 18 ): |
| 467 | main.log.info( "Adding host intent between h" + str( i ) + |
| 468 | " and h" + str( i + 10 ) ) |
| 469 | host1 = "00:00:00:00:00:" + \ |
| 470 | str( hex( i )[ 2: ] ).zfill( 2 ).upper() |
| 471 | host2 = "00:00:00:00:00:" + \ |
| 472 | str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper() |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 473 | # NOTE: getHost can return None |
| 474 | host1Dict = main.ONOScli1.getHost( host1 ) |
| 475 | host2Dict = main.ONOScli1.getHost( host2 ) |
| 476 | host1Id = None |
| 477 | host2Id = None |
| 478 | if host1Dict and host2Dict: |
| 479 | host1Id = host1Dict.get( 'id', None ) |
| 480 | host2Id = host2Dict.get( 'id', None ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 481 | if host1Id and host2Id: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 482 | # Changed onos node to test something |
| 483 | tmpId = main.ONOScli4.addHostIntent( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 484 | host1Id, |
| 485 | host2Id ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 486 | if tmpId: |
| 487 | main.log.info( "Added intent with id: " + tmpId ) |
| 488 | intentIds.append( tmpId ) |
| 489 | else: |
| 490 | main.log.error( "addHostIntent reutrned None" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 491 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 492 | main.log.error( "Error, getHost() failed" ) |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 493 | main.log.warn( json.dumps( json.loads( main.ONOScli1.hosts() ), |
| 494 | sort_keys=True, |
| 495 | indent=4, |
| 496 | separators=( ',', ': ' ) ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 497 | hostResult = main.FALSE |
| 498 | onosIds = main.ONOScli1.getAllIntentsId() |
| 499 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 500 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 501 | for intent in intentIds: |
| 502 | if intent in onosIds: |
| 503 | pass # intent submitted is still in onos |
| 504 | else: |
| 505 | intentAddResult = False |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 506 | # Print the intent states |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 507 | intents = main.ONOScli1.intents() |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 508 | intentStates = [] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 509 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 510 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 511 | count = 0 |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 512 | for intent in json.loads( intents ): # Iter through intents of a node |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 513 | state = intent.get( 'state', None ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 514 | if "INSTALLED" not in state: |
| 515 | installedCheck = False |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 516 | intentId = intent.get( 'id', None ) |
| 517 | intentStates.append( ( intentId, state ) ) |
| 518 | # add submitted intents not in the store |
| 519 | tmplist = [ i for i, s in intentStates ] |
| 520 | missingIntents = False |
| 521 | for i in intentIds: |
| 522 | if i not in tmplist: |
| 523 | intentStates.append( ( i, " - " ) ) |
| 524 | missingIntents = True |
| 525 | intentStates.sort() |
| 526 | for i, s in intentStates: |
| 527 | count += 1 |
| 528 | main.log.info( "%-6s%-15s%-15s" % |
| 529 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 530 | main.ONOScli1.leaders() |
| 531 | main.ONOScli1.partitions() |
| 532 | # for node in nodes: |
| 533 | # node.pendingMap() |
| 534 | pendingMap = main.ONOScli1.pendingMap() |
| 535 | main.ONOScli2.pendingMap() |
| 536 | main.ONOScli3.pendingMap() |
| 537 | main.ONOScli4.pendingMap() |
| 538 | main.ONOScli5.pendingMap() |
| 539 | main.ONOScli6.pendingMap() |
| 540 | main.ONOScli7.pendingMap() |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 541 | intentAddResult = bool( pingResult and hostResult and intentAddResult |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 542 | and not missingIntents and installedCheck ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 543 | utilities.assert_equals( |
| 544 | expect=True, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 545 | actual=intentAddResult, |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 546 | onpass="Pushed host intents to ONOS", |
| 547 | onfail="Error in pushing host intents to ONOS" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 548 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 549 | if not intentAddResult or "key" in pendingMap: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 550 | import time |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 551 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 552 | main.log.info( "Sleeping 60 seconds to see if intents are found" ) |
| 553 | time.sleep( 60 ) |
| 554 | onosIds = main.ONOScli1.getAllIntentsId() |
| 555 | main.log.info( "Submitted intents: " + str( intentIds ) ) |
| 556 | main.log.info( "Intents in ONOS: " + str( onosIds ) ) |
| 557 | # Print the intent states |
| 558 | intents = main.ONOScli1.intents() |
| 559 | intentStates = [] |
| 560 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 561 | count = 0 |
| 562 | for intent in json.loads( intents ): |
| 563 | # Iter through intents of a node |
| 564 | state = intent.get( 'state', None ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 565 | if "INSTALLED" not in state: |
| 566 | installedCheck = False |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 567 | intentId = intent.get( 'id', None ) |
| 568 | intentStates.append( ( intentId, state ) ) |
| 569 | # add submitted intents not in the store |
| 570 | tmplist = [ i for i, s in intentStates ] |
| 571 | for i in intentIds: |
| 572 | if i not in tmplist: |
| 573 | intentStates.append( ( i, " - " ) ) |
| 574 | intentStates.sort() |
| 575 | for i, s in intentStates: |
| 576 | count += 1 |
| 577 | main.log.info( "%-6s%-15s%-15s" % |
| 578 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 579 | main.ONOScli1.leaders() |
| 580 | main.ONOScli1.pendingMap() |
| 581 | main.ONOScli2.pendingMap() |
| 582 | main.ONOScli3.pendingMap() |
| 583 | main.ONOScli4.pendingMap() |
| 584 | main.ONOScli5.pendingMap() |
| 585 | main.ONOScli6.pendingMap() |
| 586 | main.ONOScli7.pendingMap() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 587 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 588 | def CASE4( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 589 | """ |
| 590 | Ping across added host intents |
| 591 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 592 | import json |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 593 | description = " Ping across added host intents" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 594 | main.log.report( description ) |
| 595 | main.case( description ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 596 | PingResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 597 | for i in range( 8, 18 ): |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 598 | ping = main.Mininet1.pingHost( src="h" + str( i ), |
| 599 | target="h" + str( i + 10 ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 600 | PingResult = PingResult and ping |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 601 | if ping == main.FALSE: |
| 602 | main.log.warn( "Ping failed between h" + str( i ) + |
| 603 | " and h" + str( i + 10 ) ) |
| 604 | elif ping == main.TRUE: |
| 605 | main.log.info( "Ping test passed!" ) |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 606 | # Don't set PingResult or you'd override failures |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 607 | if PingResult == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 608 | main.log.report( |
| 609 | "Intents have not been installed correctly, pings failed." ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 610 | # TODO: pretty print |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 611 | main.log.warn( "ONSO1 intents: " ) |
| 612 | main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ), |
| 613 | sort_keys=True, |
| 614 | indent=4, |
| 615 | separators=( ',', ': ' ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 616 | if PingResult == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 617 | main.log.report( |
| 618 | "Intents have been installed correctly and verified by pings" ) |
| 619 | utilities.assert_equals( |
| 620 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 621 | actual=PingResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 622 | onpass="Intents have been installed correctly and pings work", |
| 623 | onfail="Intents have not been installed correctly, pings failed." ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 624 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 625 | installedCheck = True |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 626 | if PingResult is not main.TRUE: |
| 627 | # Print the intent states |
| 628 | intents = main.ONOScli1.intents() |
| 629 | intentStates = [] |
| 630 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 631 | count = 0 |
| 632 | # Iter through intents of a node |
| 633 | for intent in json.loads( intents ): |
| 634 | state = intent.get( 'state', None ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 635 | if "INSTALLED" not in state: |
| 636 | installedCheck = False |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 637 | intentId = intent.get( 'id', None ) |
| 638 | intentStates.append( ( intentId, state ) ) |
| 639 | intentStates.sort() |
| 640 | for i, s in intentStates: |
| 641 | count += 1 |
| 642 | main.log.info( "%-6s%-15s%-15s" % |
| 643 | ( str( count ), str( i ), str( s ) ) ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 644 | main.ONOScli1.leaders() |
| 645 | main.ONOScli1.partitions() |
| 646 | main.ONOScli1.pendingMap() |
| 647 | main.ONOScli2.pendingMap() |
| 648 | main.ONOScli3.pendingMap() |
| 649 | main.ONOScli4.pendingMap() |
| 650 | main.ONOScli5.pendingMap() |
| 651 | main.ONOScli6.pendingMap() |
| 652 | main.ONOScli7.pendingMap() |
| 653 | if not installedCheck: |
| 654 | main.log.info( "Waiting 60 seconds to see if intent states change" ) |
| 655 | time.sleep( 60 ) |
| 656 | # Print the intent states |
| 657 | intents = main.ONOScli1.intents() |
| 658 | intentStates = [] |
| 659 | main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) ) |
| 660 | count = 0 |
| 661 | # Iter through intents of a node |
| 662 | for intent in json.loads( intents ): |
| 663 | state = intent.get( 'state', None ) |
| 664 | if "INSTALLED" not in state: |
| 665 | installedCheck = False |
| 666 | intentId = intent.get( 'id', None ) |
| 667 | intentStates.append( ( intentId, state ) ) |
| 668 | intentStates.sort() |
| 669 | for i, s in intentStates: |
| 670 | count += 1 |
| 671 | main.log.info( "%-6s%-15s%-15s" % |
| 672 | ( str( count ), str( i ), str( s ) ) ) |
| 673 | main.ONOScli1.leaders() |
| 674 | main.ONOScli1.partitions() |
| 675 | main.ONOScli1.pendingMap() |
| 676 | main.ONOScli2.pendingMap() |
| 677 | main.ONOScli3.pendingMap() |
| 678 | main.ONOScli4.pendingMap() |
| 679 | main.ONOScli5.pendingMap() |
| 680 | main.ONOScli6.pendingMap() |
| 681 | main.ONOScli7.pendingMap() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 682 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 683 | def CASE5( self, main ): |
| 684 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 685 | Reading state of ONOS |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 686 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 687 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 688 | # assumes that sts is already in you PYTHONPATH |
| 689 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 690 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 691 | main.log.report( "Setting up and gathering data for current state" ) |
| 692 | main.case( "Setting up and gathering data for current state" ) |
| 693 | # The general idea for this test case is to pull the state of |
| 694 | # ( intents,flows, topology,... ) from each ONOS node |
| 695 | # We can then compare them with eachother and also with past states |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 696 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 697 | main.step( "Get the Mastership of each switch from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 698 | global mastershipState |
| 699 | mastershipState = [] |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 700 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 701 | # Assert that each device has a master |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 702 | ONOS1MasterNotNull = main.ONOScli1.rolesNotNull() |
| 703 | ONOS2MasterNotNull = main.ONOScli2.rolesNotNull() |
| 704 | ONOS3MasterNotNull = main.ONOScli3.rolesNotNull() |
| 705 | ONOS4MasterNotNull = main.ONOScli4.rolesNotNull() |
| 706 | ONOS5MasterNotNull = main.ONOScli5.rolesNotNull() |
| 707 | ONOS6MasterNotNull = main.ONOScli6.rolesNotNull() |
| 708 | ONOS7MasterNotNull = main.ONOScli7.rolesNotNull() |
| 709 | rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\ |
| 710 | ONOS3MasterNotNull and ONOS4MasterNotNull and\ |
| 711 | ONOS5MasterNotNull and ONOS6MasterNotNull and\ |
| 712 | ONOS7MasterNotNull |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 713 | utilities.assert_equals( |
| 714 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 715 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 716 | onpass="Each device has a master", |
| 717 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 718 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 719 | ONOS1Mastership = main.ONOScli1.roles() |
| 720 | ONOS2Mastership = main.ONOScli2.roles() |
| 721 | ONOS3Mastership = main.ONOScli3.roles() |
| 722 | ONOS4Mastership = main.ONOScli4.roles() |
| 723 | ONOS5Mastership = main.ONOScli5.roles() |
| 724 | ONOS6Mastership = main.ONOScli6.roles() |
| 725 | ONOS7Mastership = main.ONOScli7.roles() |
| 726 | if "Error" in ONOS1Mastership or not ONOS1Mastership\ |
| 727 | or "Error" in ONOS2Mastership or not ONOS2Mastership\ |
| 728 | or "Error" in ONOS3Mastership or not ONOS3Mastership\ |
| 729 | or "Error" in ONOS4Mastership or not ONOS4Mastership\ |
| 730 | or "Error" in ONOS5Mastership or not ONOS5Mastership\ |
| 731 | or "Error" in ONOS6Mastership or not ONOS6Mastership\ |
| 732 | or "Error" in ONOS7Mastership or not ONOS7Mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 733 | main.log.report( "Error in getting ONOS roles" ) |
| 734 | main.log.warn( |
| 735 | "ONOS1 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 736 | repr( ONOS1Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 737 | main.log.warn( |
| 738 | "ONOS2 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 739 | repr( ONOS2Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 740 | main.log.warn( |
| 741 | "ONOS3 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 742 | repr( ONOS3Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 743 | main.log.warn( |
| 744 | "ONOS4 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 745 | repr( ONOS4Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 746 | main.log.warn( |
| 747 | "ONOS5 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 748 | repr( ONOS5Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 749 | main.log.warn( |
| 750 | "ONOS6 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 751 | repr( ONOS6Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 752 | main.log.warn( |
| 753 | "ONOS7 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 754 | repr( ONOS7Mastership ) ) |
| 755 | consistentMastership = main.FALSE |
| 756 | elif ONOS1Mastership == ONOS2Mastership\ |
| 757 | and ONOS1Mastership == ONOS3Mastership\ |
| 758 | and ONOS1Mastership == ONOS4Mastership\ |
| 759 | and ONOS1Mastership == ONOS5Mastership\ |
| 760 | and ONOS1Mastership == ONOS6Mastership\ |
| 761 | and ONOS1Mastership == ONOS7Mastership: |
| 762 | mastershipState = ONOS1Mastership |
| 763 | consistentMastership = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 764 | main.log.report( |
| 765 | "Switch roles are consistent across all ONOS nodes" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 766 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 767 | main.log.warn( |
| 768 | "ONOS1 roles: ", |
| 769 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 770 | json.loads( ONOS1Mastership ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 771 | sort_keys=True, |
| 772 | indent=4, |
| 773 | separators=( |
| 774 | ',', |
| 775 | ': ' ) ) ) |
| 776 | main.log.warn( |
| 777 | "ONOS2 roles: ", |
| 778 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 779 | json.loads( ONOS2Mastership ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 780 | sort_keys=True, |
| 781 | indent=4, |
| 782 | separators=( |
| 783 | ',', |
| 784 | ': ' ) ) ) |
| 785 | main.log.warn( |
| 786 | "ONOS3 roles: ", |
| 787 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 788 | json.loads( ONOS3Mastership ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 789 | sort_keys=True, |
| 790 | indent=4, |
| 791 | separators=( |
| 792 | ',', |
| 793 | ': ' ) ) ) |
| 794 | main.log.warn( |
| 795 | "ONOS4 roles: ", |
| 796 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 797 | json.loads( ONOS4Mastership ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 798 | sort_keys=True, |
| 799 | indent=4, |
| 800 | separators=( |
| 801 | ',', |
| 802 | ': ' ) ) ) |
| 803 | main.log.warn( |
| 804 | "ONOS5 roles: ", |
| 805 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 806 | json.loads( ONOS5Mastership ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 807 | sort_keys=True, |
| 808 | indent=4, |
| 809 | separators=( |
| 810 | ',', |
| 811 | ': ' ) ) ) |
| 812 | main.log.warn( |
| 813 | "ONOS6 roles: ", |
| 814 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 815 | json.loads( ONOS6Mastership ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 816 | sort_keys=True, |
| 817 | indent=4, |
| 818 | separators=( |
| 819 | ',', |
| 820 | ': ' ) ) ) |
| 821 | main.log.warn( |
| 822 | "ONOS7 roles: ", |
| 823 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 824 | json.loads( ONOS7Mastership ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 825 | sort_keys=True, |
| 826 | indent=4, |
| 827 | separators=( |
| 828 | ',', |
| 829 | ': ' ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 830 | consistentMastership = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 831 | utilities.assert_equals( |
| 832 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 833 | actual=consistentMastership, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 834 | onpass="Switch roles are consistent across all ONOS nodes", |
| 835 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 836 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 837 | main.step( "Get the intents from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 838 | global intentState |
| 839 | intentState = [] |
| 840 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 841 | ONOS2Intents = main.ONOScli2.intents( jsonFormat=True ) |
| 842 | ONOS3Intents = main.ONOScli3.intents( jsonFormat=True ) |
| 843 | ONOS4Intents = main.ONOScli4.intents( jsonFormat=True ) |
| 844 | ONOS5Intents = main.ONOScli5.intents( jsonFormat=True ) |
| 845 | ONOS6Intents = main.ONOScli6.intents( jsonFormat=True ) |
| 846 | ONOS7Intents = main.ONOScli7.intents( jsonFormat=True ) |
| 847 | intentCheck = main.FALSE |
| 848 | if "Error" in ONOS1Intents or not ONOS1Intents\ |
| 849 | or "Error" in ONOS2Intents or not ONOS2Intents\ |
| 850 | or "Error" in ONOS3Intents or not ONOS3Intents\ |
| 851 | or "Error" in ONOS4Intents or not ONOS4Intents\ |
| 852 | or "Error" in ONOS5Intents or not ONOS5Intents\ |
| 853 | or "Error" in ONOS6Intents or not ONOS6Intents\ |
| 854 | or "Error" in ONOS7Intents or not ONOS7Intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 855 | main.log.report( "Error in getting ONOS intents" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 856 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
| 857 | main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) ) |
| 858 | main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) ) |
| 859 | main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) ) |
| 860 | main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) ) |
| 861 | main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) ) |
| 862 | main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) ) |
| 863 | elif ONOS1Intents == ONOS2Intents\ |
| 864 | and ONOS1Intents == ONOS3Intents\ |
| 865 | and ONOS1Intents == ONOS4Intents\ |
| 866 | and ONOS1Intents == ONOS5Intents\ |
| 867 | and ONOS1Intents == ONOS6Intents\ |
| 868 | and ONOS1Intents == ONOS7Intents: |
| 869 | intentState = ONOS1Intents |
| 870 | intentCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 871 | main.log.report( "Intents are consistent across all ONOS nodes" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 872 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 873 | main.log.warn( |
| 874 | "ONOS1 intents: ", |
| 875 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 876 | json.loads( ONOS1Intents ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 877 | sort_keys=True, |
| 878 | indent=4, |
| 879 | separators=( |
| 880 | ',', |
| 881 | ': ' ) ) ) |
| 882 | main.log.warn( |
| 883 | "ONOS2 intents: ", |
| 884 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 885 | json.loads( ONOS2Intents ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 886 | sort_keys=True, |
| 887 | indent=4, |
| 888 | separators=( |
| 889 | ',', |
| 890 | ': ' ) ) ) |
| 891 | main.log.warn( |
| 892 | "ONOS3 intents: ", |
| 893 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 894 | json.loads( ONOS3Intents ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 895 | sort_keys=True, |
| 896 | indent=4, |
| 897 | separators=( |
| 898 | ',', |
| 899 | ': ' ) ) ) |
| 900 | main.log.warn( |
| 901 | "ONOS4 intents: ", |
| 902 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 903 | json.loads( ONOS4Intents ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 904 | sort_keys=True, |
| 905 | indent=4, |
| 906 | separators=( |
| 907 | ',', |
| 908 | ': ' ) ) ) |
| 909 | main.log.warn( |
| 910 | "ONOS5 intents: ", |
| 911 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 912 | json.loads( ONOS5Intents ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 913 | sort_keys=True, |
| 914 | indent=4, |
| 915 | separators=( |
| 916 | ',', |
| 917 | ': ' ) ) ) |
| 918 | main.log.warn( |
| 919 | "ONOS6 intents: ", |
| 920 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 921 | json.loads( ONOS6Intents ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 922 | sort_keys=True, |
| 923 | indent=4, |
| 924 | separators=( |
| 925 | ',', |
| 926 | ': ' ) ) ) |
| 927 | main.log.warn( |
| 928 | "ONOS7 intents: ", |
| 929 | json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 930 | json.loads( ONOS7Intents ), |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 931 | sort_keys=True, |
| 932 | indent=4, |
| 933 | separators=( |
| 934 | ',', |
| 935 | ': ' ) ) ) |
| 936 | utilities.assert_equals( |
| 937 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 938 | actual=intentCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 939 | onpass="Intents are consistent across all ONOS nodes", |
| 940 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 941 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 942 | main.step( "Get the flows from each controller" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 943 | global flowState |
| 944 | flowState = [] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 945 | flowCheck = main.FALSE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 946 | try: |
| 947 | ONOS1Flows = main.ONOScli1.flows( jsonFormat=True ) |
| 948 | ONOS2Flows = main.ONOScli2.flows( jsonFormat=True ) |
| 949 | ONOS3Flows = main.ONOScli3.flows( jsonFormat=True ) |
| 950 | ONOS4Flows = main.ONOScli4.flows( jsonFormat=True ) |
| 951 | ONOS5Flows = main.ONOScli5.flows( jsonFormat=True ) |
| 952 | ONOS6Flows = main.ONOScli6.flows( jsonFormat=True ) |
| 953 | ONOS7Flows = main.ONOScli7.flows( jsonFormat=True ) |
| 954 | assert ONOS1Flows, "ONOS1 Flows should not be empty" |
| 955 | assert ONOS2Flows, "ONOS2 Flows should not be empty" |
| 956 | assert ONOS3Flows, "ONOS3 Flows should not be empty" |
| 957 | assert ONOS4Flows, "ONOS4 Flows should not be empty" |
| 958 | assert ONOS5Flows, "ONOS5 Flows should not be empty" |
| 959 | assert ONOS6Flows, "ONOS6 Flows should not be empty" |
| 960 | assert ONOS7Flows, "ONOS7 Flows should not be empty" |
| 961 | assert "Error" not in ONOS1Flows, "ONOS1 Flows contains 'Error'" |
| 962 | assert "Error" not in ONOS2Flows, "ONOS2 Flows contains 'Error'" |
| 963 | assert "Error" not in ONOS3Flows, "ONOS3 Flows contains 'Error'" |
| 964 | assert "Error" not in ONOS4Flows, "ONOS4 Flows contains 'Error'" |
| 965 | assert "Error" not in ONOS5Flows, "ONOS5 Flows contains 'Error'" |
| 966 | assert "Error" not in ONOS6Flows, "ONOS6 Flows contains 'Error'" |
| 967 | assert "Error" not in ONOS7Flows, "ONOS7 Flows contains 'Error'" |
| 968 | ONOS1FlowsJson = json.loads( ONOS1Flows ) |
| 969 | ONOS2FlowsJson = json.loads( ONOS2Flows ) |
| 970 | ONOS3FlowsJson = json.loads( ONOS3Flows ) |
| 971 | ONOS4FlowsJson = json.loads( ONOS4Flows ) |
| 972 | ONOS5FlowsJson = json.loads( ONOS5Flows ) |
| 973 | ONOS6FlowsJson = json.loads( ONOS6Flows ) |
| 974 | ONOS7FlowsJson = json.loads( ONOS7Flows ) |
| 975 | except ( ValueError, AssertionError ): # From json.loads, or asserts |
| 976 | main.log.exception( "One or more 'flows' responses from " + |
| 977 | "ONOS couldn't be decoded." ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 978 | main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows ) |
| 979 | main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows ) |
| 980 | main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows ) |
| 981 | main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows ) |
| 982 | main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows ) |
| 983 | main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows ) |
| 984 | main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 985 | else: # No exceptions |
| 986 | if len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\ |
| 987 | and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\ |
| 988 | and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\ |
| 989 | and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\ |
| 990 | and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\ |
| 991 | and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 992 | # TODO: Do a better check, maybe compare flows on switches? |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 993 | # NOTE Possible issue with this not always being set? |
| 994 | flowState = ONOS1Flows |
| 995 | flowCheck = main.TRUE |
| 996 | main.log.report( "Flow count is consistent across all" + |
| 997 | " ONOS nodes" ) |
| 998 | else: |
| 999 | main.log.warn( "ONOS1 flows: " + |
| 1000 | json.dumps( ONOS1FlowsJson, sort_keys=True, |
| 1001 | indent=4, |
| 1002 | separators=( ',', ': ' ) ) ) |
| 1003 | main.log.warn( "ONOS2 flows: " + |
| 1004 | json.dumps( ONOS2FlowsJson, sort_keys=True, |
| 1005 | indent=4, |
| 1006 | separators=( ',', ': ' ) ) ) |
| 1007 | main.log.warn( "ONOS3 flows: " + |
| 1008 | json.dumps( ONOS3FlowsJson, sort_keys=True, |
| 1009 | indent=4, |
| 1010 | separators=( ',', ': ' ) ) ) |
| 1011 | main.log.warn( "ONOS4 flows: " + |
| 1012 | json.dumps( ONOS4FlowsJson, sort_keys=True, |
| 1013 | indent=4, |
| 1014 | separators=( ',', ': ' ) ) ) |
| 1015 | main.log.warn( "ONOS5 flows: " + |
| 1016 | json.dumps( ONOS5FlowsJson, sort_keys=True, |
| 1017 | indent=4, |
| 1018 | separators=( ',', ': ' ) ) ) |
| 1019 | main.log.warn( "ONOS6 flows: " + |
| 1020 | json.dumps( ONOS6FlowsJson, sort_keys=True, |
| 1021 | indent=4, |
| 1022 | separators=( ',', ': ' ) ) ) |
| 1023 | main.log.warn( "ONOS7 flows: " + |
| 1024 | json.dumps( ONOS7FlowsJson, sort_keys=True, |
| 1025 | indent=4, |
| 1026 | separators=( ',', ': ' ) ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1027 | utilities.assert_equals( |
| 1028 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1029 | actual=flowCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1030 | onpass="The flow count is consistent across all ONOS nodes", |
| 1031 | onfail="ONOS nodes have different flow counts" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1032 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1033 | main.step( "Get the OF Table entries" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1034 | global flows |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1035 | flows = [] |
| 1036 | for i in range( 1, 29 ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1037 | flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1038 | if flowCheck == main.FALSE: |
| 1039 | for table in flows: |
| 1040 | main.log.warn( table ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1041 | # TODO: Compare switch flow tables with ONOS flow tables |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1042 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1043 | main.step( "Start continuous pings" ) |
| 1044 | main.Mininet2.pingLong( |
| 1045 | src=main.params[ 'PING' ][ 'source1' ], |
| 1046 | target=main.params[ 'PING' ][ 'target1' ], |
| 1047 | pingTime=500 ) |
| 1048 | main.Mininet2.pingLong( |
| 1049 | src=main.params[ 'PING' ][ 'source2' ], |
| 1050 | target=main.params[ 'PING' ][ 'target2' ], |
| 1051 | pingTime=500 ) |
| 1052 | main.Mininet2.pingLong( |
| 1053 | src=main.params[ 'PING' ][ 'source3' ], |
| 1054 | target=main.params[ 'PING' ][ 'target3' ], |
| 1055 | pingTime=500 ) |
| 1056 | main.Mininet2.pingLong( |
| 1057 | src=main.params[ 'PING' ][ 'source4' ], |
| 1058 | target=main.params[ 'PING' ][ 'target4' ], |
| 1059 | pingTime=500 ) |
| 1060 | main.Mininet2.pingLong( |
| 1061 | src=main.params[ 'PING' ][ 'source5' ], |
| 1062 | target=main.params[ 'PING' ][ 'target5' ], |
| 1063 | pingTime=500 ) |
| 1064 | main.Mininet2.pingLong( |
| 1065 | src=main.params[ 'PING' ][ 'source6' ], |
| 1066 | target=main.params[ 'PING' ][ 'target6' ], |
| 1067 | pingTime=500 ) |
| 1068 | main.Mininet2.pingLong( |
| 1069 | src=main.params[ 'PING' ][ 'source7' ], |
| 1070 | target=main.params[ 'PING' ][ 'target7' ], |
| 1071 | pingTime=500 ) |
| 1072 | main.Mininet2.pingLong( |
| 1073 | src=main.params[ 'PING' ][ 'source8' ], |
| 1074 | target=main.params[ 'PING' ][ 'target8' ], |
| 1075 | pingTime=500 ) |
| 1076 | main.Mininet2.pingLong( |
| 1077 | src=main.params[ 'PING' ][ 'source9' ], |
| 1078 | target=main.params[ 'PING' ][ 'target9' ], |
| 1079 | pingTime=500 ) |
| 1080 | main.Mininet2.pingLong( |
| 1081 | src=main.params[ 'PING' ][ 'source10' ], |
| 1082 | target=main.params[ 'PING' ][ 'target10' ], |
| 1083 | pingTime=500 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1084 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1085 | main.step( "Create TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1086 | ctrls = [] |
| 1087 | count = 1 |
| 1088 | while True: |
| 1089 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1090 | if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]: |
| 1091 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 1092 | temp = temp + ( "ONOS" + str( count ), ) |
| 1093 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 1094 | temp = temp + \ |
| 1095 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 1096 | ctrls.append( temp ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1097 | count = count + 1 |
| 1098 | else: |
| 1099 | break |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1100 | MNTopo = TestONTopology( |
| 1101 | main.Mininet1, |
| 1102 | ctrls ) # can also add Intent API info for intent operations |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1103 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1104 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1105 | devices = [] |
| 1106 | devices.append( main.ONOScli1.devices() ) |
| 1107 | devices.append( main.ONOScli2.devices() ) |
| 1108 | devices.append( main.ONOScli3.devices() ) |
| 1109 | devices.append( main.ONOScli4.devices() ) |
| 1110 | devices.append( main.ONOScli5.devices() ) |
| 1111 | devices.append( main.ONOScli6.devices() ) |
| 1112 | devices.append( main.ONOScli7.devices() ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1113 | hosts = [] |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1114 | hosts.append( json.loads( main.ONOScli1.hosts() ) ) |
| 1115 | hosts.append( json.loads( main.ONOScli2.hosts() ) ) |
| 1116 | hosts.append( json.loads( main.ONOScli3.hosts() ) ) |
| 1117 | hosts.append( json.loads( main.ONOScli4.hosts() ) ) |
| 1118 | hosts.append( json.loads( main.ONOScli5.hosts() ) ) |
| 1119 | hosts.append( json.loads( main.ONOScli6.hosts() ) ) |
| 1120 | hosts.append( json.loads( main.ONOScli7.hosts() ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1121 | ports = [] |
| 1122 | ports.append( main.ONOScli1.ports() ) |
| 1123 | ports.append( main.ONOScli2.ports() ) |
| 1124 | ports.append( main.ONOScli3.ports() ) |
| 1125 | ports.append( main.ONOScli4.ports() ) |
| 1126 | ports.append( main.ONOScli5.ports() ) |
| 1127 | ports.append( main.ONOScli6.ports() ) |
| 1128 | ports.append( main.ONOScli7.ports() ) |
| 1129 | links = [] |
| 1130 | links.append( main.ONOScli1.links() ) |
| 1131 | links.append( main.ONOScli2.links() ) |
| 1132 | links.append( main.ONOScli3.links() ) |
| 1133 | links.append( main.ONOScli4.links() ) |
| 1134 | links.append( main.ONOScli5.links() ) |
| 1135 | links.append( main.ONOScli6.links() ) |
| 1136 | links.append( main.ONOScli7.links() ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1137 | clusters = [] |
| 1138 | clusters.append( main.ONOScli1.clusters() ) |
| 1139 | clusters.append( main.ONOScli2.clusters() ) |
| 1140 | clusters.append( main.ONOScli3.clusters() ) |
| 1141 | clusters.append( main.ONOScli4.clusters() ) |
| 1142 | clusters.append( main.ONOScli5.clusters() ) |
| 1143 | clusters.append( main.ONOScli6.clusters() ) |
| 1144 | clusters.append( main.ONOScli7.clusters() ) |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 1145 | # Compare json objects for hosts and dataplane clusters |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1146 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1147 | # hosts |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1148 | consistentHostsResult = main.TRUE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1149 | for controller in range( len( hosts ) ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1150 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1151 | if "Error" not in hosts[ controller ]: |
| 1152 | if hosts[ controller ] == hosts[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1153 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1154 | else: # hosts not consistent |
| 1155 | main.log.report( "hosts from ONOS" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1156 | controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1157 | " is inconsistent with ONOS1" ) |
| 1158 | main.log.warn( repr( hosts[ controller ] ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1159 | consistentHostsResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1160 | |
| 1161 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1162 | main.log.report( "Error in getting ONOS hosts from ONOS" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1163 | controllerStr ) |
| 1164 | consistentHostsResult = main.FALSE |
| 1165 | main.log.warn( "ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1166 | " hosts response: " + |
| 1167 | repr( hosts[ controller ] ) ) |
| 1168 | utilities.assert_equals( |
| 1169 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1170 | actual=consistentHostsResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1171 | onpass="Hosts view is consistent across all ONOS nodes", |
| 1172 | onfail="ONOS nodes have different views of hosts" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1173 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1174 | ipResult = main.TRUE |
| 1175 | for controller in range( 0, len( hosts ) ): |
| 1176 | controllerStr = str( controller + 1 ) |
| 1177 | for host in hosts[ controller ]: |
| 1178 | if host.get( 'ips', [] ) == []: |
| 1179 | main.log.error( |
| 1180 | "DEBUG:Error with host ips on controller" + |
| 1181 | controllerStr + ": " + str( host ) ) |
| 1182 | ipResult = main.FALSE |
| 1183 | utilities.assert_equals( |
| 1184 | expect=main.TRUE, |
| 1185 | actual=ipResult, |
| 1186 | onpass="The ips of the hosts aren't empty", |
| 1187 | onfail="The ip of at least one host is missing" ) |
| 1188 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1189 | # Strongly connected clusters of devices |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1190 | consistentClustersResult = main.TRUE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1191 | for controller in range( len( clusters ) ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1192 | if "Error" not in clusters[ controller ]: |
| 1193 | if clusters[ controller ] == clusters[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1194 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1195 | else: # clusters not consistent |
| 1196 | main.log.report( "clusters from ONOS" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1197 | controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1198 | " is inconsistent with ONOS1" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1199 | consistentClustersResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1200 | |
| 1201 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1202 | main.log.report( "Error in getting dataplane clusters " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1203 | "from ONOS" + controllerStr ) |
| 1204 | consistentClustersResult = main.FALSE |
| 1205 | main.log.warn( "ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1206 | " clusters response: " + |
| 1207 | repr( clusters[ controller ] ) ) |
| 1208 | utilities.assert_equals( |
| 1209 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1210 | actual=consistentClustersResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1211 | onpass="Clusters view is consistent across all ONOS nodes", |
| 1212 | onfail="ONOS nodes have different views of clusters" ) |
| 1213 | # there should always only be one cluster |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1214 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1215 | clusterResults = main.FALSE |
| 1216 | if numClusters == 1: |
| 1217 | clusterResults = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1218 | utilities.assert_equals( |
| 1219 | expect=1, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1220 | actual=numClusters, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1221 | onpass="ONOS shows 1 SCC", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1222 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1223 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1224 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1225 | devicesResults = main.TRUE |
| 1226 | portsResults = main.TRUE |
| 1227 | linksResults = main.TRUE |
| 1228 | for controller in range( numControllers ): |
| 1229 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1230 | if devices[ controller ] or "Error" not in devices[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1231 | currentDevicesResult = main.Mininet1.compareSwitches( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1232 | MNTopo, |
| 1233 | json.loads( |
| 1234 | devices[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1235 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1236 | currentDevicesResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1237 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1238 | actual=currentDevicesResult, |
| 1239 | onpass="ONOS" + controllerStr + |
| 1240 | " Switches view is correct", |
| 1241 | onfail="ONOS" + controllerStr + |
| 1242 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1243 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1244 | if ports[ controller ] or "Error" not in ports[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1245 | currentPortsResult = main.Mininet1.comparePorts( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1246 | MNTopo, |
| 1247 | json.loads( |
| 1248 | ports[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1249 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1250 | currentPortsResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1251 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1252 | actual=currentPortsResult, |
| 1253 | onpass="ONOS" + controllerStr + |
| 1254 | " ports view is correct", |
| 1255 | onfail="ONOS" + controllerStr + |
| 1256 | " ports view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1257 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1258 | if links[ controller ] or "Error" not in links[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1259 | currentLinksResult = main.Mininet1.compareLinks( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1260 | MNTopo, |
| 1261 | json.loads( |
| 1262 | links[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1263 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1264 | currentLinksResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1265 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1266 | actual=currentLinksResult, |
| 1267 | onpass="ONOS" + controllerStr + |
| 1268 | " links view is correct", |
| 1269 | onfail="ONOS" + controllerStr + |
| 1270 | " links view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1271 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1272 | devicesResults = devicesResults and currentDevicesResult |
| 1273 | portsResults = portsResults and currentPortsResult |
| 1274 | linksResults = linksResults and currentLinksResult |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1275 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1276 | topoResult = devicesResults and portsResults and linksResults\ |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1277 | and consistentHostsResult and consistentClustersResult\ |
| 1278 | and clusterResults and ipResult |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1279 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1280 | onpass="Topology Check Test successful", |
| 1281 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1282 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1283 | finalAssert = main.TRUE |
| 1284 | finalAssert = finalAssert and topoResult and flowCheck \ |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1285 | and intentCheck and consistentMastership and rolesNotNull |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1286 | utilities.assert_equals( expect=main.TRUE, actual=finalAssert, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1287 | onpass="State check successful", |
| 1288 | onfail="State check NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1289 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1290 | def CASE6( self, main ): |
| 1291 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1292 | The Failure case. |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1293 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1294 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1295 | main.log.report( "Killing 3 ONOS nodes" ) |
| 1296 | main.log.case( "Restart minority of ONOS nodes" ) |
| 1297 | # TODO: Randomize these nodes |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1298 | main.ONOSbench.onosKill( ONOS1Ip ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1299 | time.sleep( 10 ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1300 | main.ONOSbench.onosKill( ONOS2Ip ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1301 | time.sleep( 10 ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1302 | main.ONOSbench.onosKill( ONOS3Ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1303 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1304 | main.step( "Checking if ONOS is up yet" ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1305 | count = 0 |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1306 | onosIsupResult = main.FALSE |
| 1307 | while onosIsupResult == main.FALSE and count < 10: |
| 1308 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 1309 | onos2Isup = main.ONOSbench.isup( ONOS2Ip ) |
| 1310 | onos3Isup = main.ONOSbench.isup( ONOS3Ip ) |
| 1311 | onosIsupResult = onos1Isup and onos2Isup and onos3Isup |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1312 | count = count + 1 |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1313 | # TODO: if it becomes an issue, we can retry this step a few times |
| 1314 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1315 | cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip ) |
| 1316 | cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip ) |
| 1317 | cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip ) |
| 1318 | cliResults = cliResult1 and cliResult2 and cliResult3 |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1319 | |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1320 | # Grab the time of restart so we chan check how long the gossip |
| 1321 | # protocol has had time to work |
| 1322 | main.restartTime = time.time() |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1323 | caseResults = main.TRUE and onosIsupResult and cliResults |
| 1324 | utilities.assert_equals( expect=main.TRUE, actual=caseResults, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1325 | onpass="ONOS restart successful", |
| 1326 | onfail="ONOS restart NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1327 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1328 | def CASE7( self, main ): |
| 1329 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1330 | Check state after ONOS failure |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1331 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1332 | import json |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1333 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1334 | main.case( "Running ONOS Constant State Tests" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1335 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1336 | # Assert that each device has a master |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1337 | ONOS1MasterNotNull = main.ONOScli1.rolesNotNull() |
| 1338 | ONOS2MasterNotNull = main.ONOScli2.rolesNotNull() |
| 1339 | ONOS3MasterNotNull = main.ONOScli3.rolesNotNull() |
| 1340 | ONOS4MasterNotNull = main.ONOScli4.rolesNotNull() |
| 1341 | ONOS5MasterNotNull = main.ONOScli5.rolesNotNull() |
| 1342 | ONOS6MasterNotNull = main.ONOScli6.rolesNotNull() |
| 1343 | ONOS7MasterNotNull = main.ONOScli7.rolesNotNull() |
| 1344 | rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\ |
| 1345 | ONOS3MasterNotNull and ONOS4MasterNotNull and\ |
| 1346 | ONOS5MasterNotNull and ONOS6MasterNotNull and\ |
| 1347 | ONOS7MasterNotNull |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1348 | utilities.assert_equals( |
| 1349 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1350 | actual=rolesNotNull, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1351 | onpass="Each device has a master", |
| 1352 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1353 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1354 | main.step( "Check if switch roles are consistent across all nodes" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1355 | ONOS1Mastership = main.ONOScli1.roles() |
| 1356 | ONOS2Mastership = main.ONOScli2.roles() |
| 1357 | ONOS3Mastership = main.ONOScli3.roles() |
| 1358 | ONOS4Mastership = main.ONOScli4.roles() |
| 1359 | ONOS5Mastership = main.ONOScli5.roles() |
| 1360 | ONOS6Mastership = main.ONOScli6.roles() |
| 1361 | ONOS7Mastership = main.ONOScli7.roles() |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1362 | if "Error" in ONOS1Mastership or not ONOS1Mastership\ |
| 1363 | or "Error" in ONOS2Mastership or not ONOS2Mastership\ |
| 1364 | or "Error" in ONOS3Mastership or not ONOS3Mastership\ |
| 1365 | or "Error" in ONOS4Mastership or not ONOS4Mastership\ |
| 1366 | or "Error" in ONOS5Mastership or not ONOS5Mastership\ |
| 1367 | or "Error" in ONOS6Mastership or not ONOS6Mastership\ |
| 1368 | or "Error" in ONOS7Mastership or not ONOS7Mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1369 | main.log.error( "Error in getting ONOS mastership" ) |
| 1370 | main.log.warn( "ONOS1 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1371 | repr( ONOS1Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1372 | main.log.warn( "ONOS2 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1373 | repr( ONOS2Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1374 | main.log.warn( "ONOS3 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1375 | repr( ONOS3Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1376 | main.log.warn( "ONOS4 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1377 | repr( ONOS4Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1378 | main.log.warn( "ONOS5 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1379 | repr( ONOS5Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1380 | main.log.warn( "ONOS6 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1381 | repr( ONOS6Mastership ) ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1382 | main.log.warn( "ONOS7 mastership response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1383 | repr( ONOS7Mastership ) ) |
| 1384 | consistentMastership = main.FALSE |
| 1385 | elif ONOS1Mastership == ONOS2Mastership\ |
| 1386 | and ONOS1Mastership == ONOS3Mastership\ |
| 1387 | and ONOS1Mastership == ONOS4Mastership\ |
| 1388 | and ONOS1Mastership == ONOS5Mastership\ |
| 1389 | and ONOS1Mastership == ONOS6Mastership\ |
| 1390 | and ONOS1Mastership == ONOS7Mastership: |
| 1391 | consistentMastership = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1392 | main.log.report( |
| 1393 | "Switch roles are consistent across all ONOS nodes" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1394 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1395 | main.log.warn( "ONOS1 roles: ", json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1396 | json.loads( ONOS1Mastership ), sort_keys=True, indent=4, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1397 | separators=( ',', ': ' ) ) ) |
| 1398 | main.log.warn( "ONOS2 roles: ", json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1399 | json.loads( ONOS2Mastership ), sort_keys=True, indent=4, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1400 | separators=( ',', ': ' ) ) ) |
| 1401 | main.log.warn( "ONOS3 roles: ", json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1402 | json.loads( ONOS3Mastership ), sort_keys=True, indent=4, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1403 | separators=( ',', ': ' ) ) ) |
| 1404 | main.log.warn( "ONOS4 roles: ", json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1405 | json.loads( ONOS4Mastership ), sort_keys=True, indent=4, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1406 | separators=( ',', ': ' ) ) ) |
| 1407 | main.log.warn( "ONOS5 roles: ", json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1408 | json.loads( ONOS5Mastership ), sort_keys=True, indent=4, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1409 | separators=( ',', ': ' ) ) ) |
| 1410 | main.log.warn( "ONOS6 roles: ", json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1411 | json.loads( ONOS6Mastership ), sort_keys=True, indent=4, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1412 | separators=( ',', ': ' ) ) ) |
| 1413 | main.log.warn( "ONOS7 roles: ", json.dumps( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1414 | json.loads( ONOS7Mastership ), sort_keys=True, indent=4, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1415 | separators=( ',', ': ' ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1416 | consistentMastership = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1417 | utilities.assert_equals( |
| 1418 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1419 | actual=consistentMastership, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1420 | onpass="Switch roles are consistent across all ONOS nodes", |
| 1421 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1422 | |
| 1423 | description2 = "Compare switch roles from before failure" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1424 | main.step( description2 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1425 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1426 | currentJson = json.loads( ONOS1Mastership ) |
| 1427 | oldJson = json.loads( mastershipState ) |
| 1428 | mastershipCheck = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1429 | for i in range( 1, 29 ): |
| 1430 | switchDPID = str( |
| 1431 | main.Mininet1.getSwitchDPID( |
| 1432 | switch="s" + |
| 1433 | str( i ) ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1434 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1435 | current = [ switch[ 'master' ] for switch in currentJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1436 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1437 | old = [ switch[ 'master' ] for switch in oldJson |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1438 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1439 | if current == old: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1440 | mastershipCheck = mastershipCheck and main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1441 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1442 | main.log.warn( "Mastership of switch %s changed" % switchDPID ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1443 | mastershipCheck = main.FALSE |
| 1444 | if mastershipCheck == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1445 | main.log.report( "Mastership of Switches was not changed" ) |
| 1446 | utilities.assert_equals( |
| 1447 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1448 | actual=mastershipCheck, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1449 | onpass="Mastership of Switches was not changed", |
| 1450 | onfail="Mastership of some switches changed" ) |
| 1451 | # NOTE: we expect mastership to change on controller failure |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1452 | mastershipCheck = consistentMastership |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1453 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1454 | main.step( "Get the intents and compare across all nodes" ) |
| 1455 | ONOS1Intents = main.ONOScli1.intents( jsonFormat=True ) |
| 1456 | ONOS2Intents = main.ONOScli2.intents( jsonFormat=True ) |
| 1457 | ONOS3Intents = main.ONOScli3.intents( jsonFormat=True ) |
| 1458 | ONOS4Intents = main.ONOScli4.intents( jsonFormat=True ) |
| 1459 | ONOS5Intents = main.ONOScli5.intents( jsonFormat=True ) |
| 1460 | ONOS6Intents = main.ONOScli6.intents( jsonFormat=True ) |
| 1461 | ONOS7Intents = main.ONOScli7.intents( jsonFormat=True ) |
| 1462 | intentCheck = main.FALSE |
| 1463 | if "Error" in ONOS1Intents or not ONOS1Intents\ |
| 1464 | or "Error" in ONOS2Intents or not ONOS2Intents\ |
| 1465 | or "Error" in ONOS3Intents or not ONOS3Intents\ |
| 1466 | or "Error" in ONOS4Intents or not ONOS4Intents\ |
| 1467 | or "Error" in ONOS5Intents or not ONOS5Intents\ |
| 1468 | or "Error" in ONOS6Intents or not ONOS6Intents\ |
| 1469 | or "Error" in ONOS7Intents or not ONOS7Intents: |
| 1470 | main.log.report( "Error in getting ONOS intents" ) |
| 1471 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) ) |
| 1472 | main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) ) |
| 1473 | main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) ) |
| 1474 | main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) ) |
| 1475 | main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) ) |
| 1476 | main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) ) |
| 1477 | main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) ) |
| 1478 | elif ONOS1Intents == ONOS2Intents\ |
| 1479 | and ONOS1Intents == ONOS3Intents\ |
| 1480 | and ONOS1Intents == ONOS4Intents\ |
| 1481 | and ONOS1Intents == ONOS5Intents\ |
| 1482 | and ONOS1Intents == ONOS6Intents\ |
| 1483 | and ONOS1Intents == ONOS7Intents: |
| 1484 | intentCheck = main.TRUE |
| 1485 | main.log.report( "Intents are consistent across all ONOS nodes" ) |
| 1486 | else: |
| 1487 | main.log.warn( "ONOS1 intents: " ) |
| 1488 | print json.dumps( json.loads( ONOS1Intents ), sort_keys=True, |
| 1489 | indent=4, separators=( ',', ': ' ) ) |
| 1490 | main.log.warn( "ONOS2 intents: " ) |
| 1491 | print json.dumps( json.loads( ONOS2Intents ), sort_keys=True, |
| 1492 | indent=4, separators=( ',', ': ' ) ) |
| 1493 | main.log.warn( "ONOS3 intents: " ) |
| 1494 | print json.dumps( json.loads( ONOS3Intents ), sort_keys=True, |
| 1495 | indent=4, separators=( ',', ': ' ) ) |
| 1496 | main.log.warn( "ONOS4 intents: " ) |
| 1497 | print json.dumps( json.loads( ONOS4Intents ), sort_keys=True, |
| 1498 | indent=4, separators=( ',', ': ' ) ) |
| 1499 | main.log.warn( "ONOS5 intents: " ) |
| 1500 | print json.dumps( json.loads( ONOS5Intents ), sort_keys=True, |
| 1501 | indent=4, separators=( ',', ': ' ) ) |
| 1502 | main.log.warn( "ONOS6 intents: " ) |
| 1503 | print json.dumps( json.loads( ONOS6Intents ), sort_keys=True, |
| 1504 | indent=4, separators=( ',', ': ' ) ) |
| 1505 | main.log.warn( "ONOS7 intents: " ) |
| 1506 | print json.dumps( json.loads( ONOS7Intents ), sort_keys=True, |
| 1507 | indent=4, separators=( ',', ': ' ) ) |
| 1508 | utilities.assert_equals( |
| 1509 | expect=main.TRUE, |
| 1510 | actual=intentCheck, |
| 1511 | onpass="Intents are consistent across all ONOS nodes", |
| 1512 | onfail="ONOS nodes have different views of intents" ) |
| 1513 | # Print the intent states |
| 1514 | intents = [] |
| 1515 | intents.append( ONOS1Intents ) |
| 1516 | intents.append( ONOS2Intents ) |
| 1517 | intents.append( ONOS3Intents ) |
| 1518 | intents.append( ONOS4Intents ) |
| 1519 | intents.append( ONOS5Intents ) |
| 1520 | intents.append( ONOS6Intents ) |
| 1521 | intents.append( ONOS7Intents ) |
| 1522 | intentStates = [] |
| 1523 | for node in intents: # Iter through ONOS nodes |
| 1524 | nodeStates = [] |
| 1525 | # Iter through intents of a node |
| 1526 | for intent in json.loads( node ): |
| 1527 | nodeStates.append( intent[ 'state' ] ) |
| 1528 | intentStates.append( nodeStates ) |
| 1529 | out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ] |
| 1530 | main.log.info( dict( out ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1531 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1532 | # NOTE: Store has no durability, so intents are lost across system |
| 1533 | # restarts |
| 1534 | main.step( "Compare current intents with intents before the failure" ) |
| 1535 | # NOTE: this requires case 5 to pass for intentState to be set. |
| 1536 | # maybe we should stop the test if that fails? |
| 1537 | sameIntents = main.TRUE |
| 1538 | if intentState and intentState == ONOS1Intents: |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1539 | sameIntents = main.TRUE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1540 | main.log.report( "Intents are consistent with before failure" ) |
| 1541 | # TODO: possibly the states have changed? we may need to figure out |
| 1542 | # what the aceptable states are |
| 1543 | else: |
| 1544 | try: |
| 1545 | main.log.warn( "ONOS1 intents: " ) |
| 1546 | print json.dumps( json.loads( ONOS1Intents ), |
| 1547 | sort_keys=True, indent=4, |
| 1548 | separators=( ',', ': ' ) ) |
Jon Hall | 88e498c | 2015-03-06 09:54:35 -0800 | [diff] [blame] | 1549 | except Exception: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1550 | pass |
| 1551 | sameIntents = main.FALSE |
| 1552 | utilities.assert_equals( |
| 1553 | expect=main.TRUE, |
| 1554 | actual=sameIntents, |
| 1555 | onpass="Intents are consistent with before failure", |
| 1556 | onfail="The Intents changed during failure" ) |
| 1557 | intentCheck = intentCheck and sameIntents |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1558 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1559 | main.step( "Get the OF Table entries and compare to before " + |
| 1560 | "component failure" ) |
| 1561 | FlowTables = main.TRUE |
| 1562 | flows2 = [] |
| 1563 | for i in range( 28 ): |
| 1564 | main.log.info( "Checking flow table on s" + str( i + 1 ) ) |
| 1565 | tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) ) |
| 1566 | flows2.append( tmpFlows ) |
| 1567 | tempResult = main.Mininet2.flowComp( |
| 1568 | flow1=flows[ i ], |
| 1569 | flow2=tmpFlows ) |
| 1570 | FlowTables = FlowTables and tempResult |
| 1571 | if FlowTables == main.FALSE: |
| 1572 | main.log.info( "Differences in flow table for switch: s" + |
| 1573 | str( i + 1 ) ) |
| 1574 | if FlowTables == main.TRUE: |
| 1575 | main.log.report( "No changes were found in the flow tables" ) |
| 1576 | utilities.assert_equals( |
| 1577 | expect=main.TRUE, |
| 1578 | actual=FlowTables, |
| 1579 | onpass="No changes were found in the flow tables", |
| 1580 | onfail="Changes were found in the flow tables" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1581 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1582 | main.step( "Check the continuous pings to ensure that no packets " + |
| 1583 | "were dropped during component failure" ) |
| 1584 | # FIXME: This check is always failing. Investigate cause |
| 1585 | # NOTE: this may be something to do with file permsissions |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1586 | # or slight change in format |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1587 | main.Mininet2.pingKill( |
| 1588 | main.params[ 'TESTONUSER' ], |
| 1589 | main.params[ 'TESTONIP' ] ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1590 | LossInPings = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1591 | # NOTE: checkForLoss returns main.FALSE with 0% packet loss |
| 1592 | for i in range( 8, 18 ): |
| 1593 | main.log.info( |
| 1594 | "Checking for a loss in pings along flow from s" + |
| 1595 | str( i ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1596 | LossInPings = main.Mininet2.checkForLoss( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1597 | "/tmp/ping.h" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1598 | str( i ) ) or LossInPings |
| 1599 | if LossInPings == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1600 | main.log.info( "Loss in ping detected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1601 | elif LossInPings == main.ERROR: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1602 | main.log.info( "There are multiple mininet process running" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1603 | elif LossInPings == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1604 | main.log.info( "No Loss in the pings" ) |
| 1605 | main.log.report( "No loss of dataplane connectivity" ) |
| 1606 | utilities.assert_equals( |
| 1607 | expect=main.FALSE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1608 | actual=LossInPings, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1609 | onpass="No Loss of connectivity", |
| 1610 | onfail="Loss of dataplane connectivity detected" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1611 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1612 | # Test of LeadershipElection |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1613 | leaderList = [] |
| 1614 | leaderResult = main.TRUE |
| 1615 | for controller in range( 1, numControllers + 1 ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1616 | # loop through ONOScli handlers |
| 1617 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1618 | leaderN = node.electionTestLeader() |
| 1619 | leaderList.append( leaderN ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1620 | if leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1621 | # error in response |
| 1622 | main.log.report( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1623 | "electionTestLeader function, check the" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1624 | " error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1625 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1626 | elif leaderN is None: |
| 1627 | main.log.report( "ONOS" + str( controller ) + |
| 1628 | " shows no leader for the election-app was" + |
| 1629 | " elected after the old one died" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1630 | leaderResult = main.FALSE |
| 1631 | elif leaderN == ONOS1Ip or leaderN == ONOS2Ip or\ |
| 1632 | leaderN == ONOS3Ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1633 | main.log.report( "ONOS" + str( controller ) + |
| 1634 | " shows " + str( leaderN ) + |
| 1635 | " as leader for the election-app, but it " + |
| 1636 | "was restarted" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1637 | leaderResult = main.FALSE |
| 1638 | if len( set( leaderList ) ) != 1: |
| 1639 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1640 | main.log.error( |
| 1641 | "Inconsistent view of leader for the election test app" ) |
| 1642 | # TODO: print the list |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1643 | if leaderResult: |
| 1644 | main.log.report( "Leadership election tests passed( consistent " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1645 | "view of leader across listeners and a new " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1646 | "leader was re-elected if applicable )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1647 | utilities.assert_equals( |
| 1648 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1649 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1650 | onpass="Leadership election passed", |
| 1651 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1652 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1653 | result = ( mastershipCheck and intentCheck and FlowTables and |
| 1654 | ( not LossInPings ) and rolesNotNull and leaderResult ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1655 | result = int( result ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1656 | if result == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1657 | main.log.report( "Constant State Tests Passed" ) |
| 1658 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1659 | onpass="Constant State Tests Passed", |
| 1660 | onfail="Constant state tests failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1661 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1662 | def CASE8( self, main ): |
| 1663 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1664 | Compare topo |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1665 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1666 | import sys |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1667 | # FIXME add this path to params |
| 1668 | sys.path.append( "/home/admin/sts" ) |
| 1669 | # assumes that sts is already in you PYTHONPATH |
| 1670 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1671 | import json |
| 1672 | import time |
| 1673 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1674 | description = "Compare ONOS Topology view to Mininet topology" |
| 1675 | main.case( description ) |
| 1676 | main.log.report( description ) |
| 1677 | main.step( "Create TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1678 | ctrls = [] |
| 1679 | count = 1 |
| 1680 | while True: |
| 1681 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1682 | if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]: |
| 1683 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 1684 | temp = temp + ( "ONOS" + str( count ), ) |
| 1685 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 1686 | temp = temp + \ |
| 1687 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 1688 | ctrls.append( temp ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1689 | count = count + 1 |
| 1690 | else: |
| 1691 | break |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1692 | MNTopo = TestONTopology( |
| 1693 | main.Mininet1, |
| 1694 | ctrls ) # can also add Intent API info for intent operations |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1695 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1696 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1697 | devicesResults = main.TRUE |
| 1698 | portsResults = main.TRUE |
| 1699 | linksResults = main.TRUE |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1700 | hostsResults = main.TRUE |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1701 | topoResult = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1702 | elapsed = 0 |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1703 | count = 0 |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1704 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1705 | startTime = time.time() |
Jon Hall | 21270ac | 2015-02-16 17:59:55 -0800 | [diff] [blame] | 1706 | # Give time for Gossip to work |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1707 | while topoResult == main.FALSE and elapsed < 60: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1708 | count = count + 1 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1709 | if count > 1: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1710 | # TODO: Depricate STS usage |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1711 | MNTopo = TestONTopology( main.Mininet1, ctrls ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1712 | cliStart = time.time() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1713 | devices = [] |
| 1714 | devices.append( main.ONOScli1.devices() ) |
| 1715 | devices.append( main.ONOScli2.devices() ) |
| 1716 | devices.append( main.ONOScli3.devices() ) |
| 1717 | devices.append( main.ONOScli4.devices() ) |
| 1718 | devices.append( main.ONOScli5.devices() ) |
| 1719 | devices.append( main.ONOScli6.devices() ) |
| 1720 | devices.append( main.ONOScli7.devices() ) |
| 1721 | hosts = [] |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1722 | hosts.append( json.loads( main.ONOScli1.hosts() ) ) |
| 1723 | hosts.append( json.loads( main.ONOScli2.hosts() ) ) |
| 1724 | hosts.append( json.loads( main.ONOScli3.hosts() ) ) |
| 1725 | hosts.append( json.loads( main.ONOScli4.hosts() ) ) |
| 1726 | hosts.append( json.loads( main.ONOScli5.hosts() ) ) |
| 1727 | hosts.append( json.loads( main.ONOScli6.hosts() ) ) |
| 1728 | hosts.append( json.loads( main.ONOScli7.hosts() ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1729 | ipResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1730 | for controller in range( 0, len( hosts ) ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1731 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1732 | for host in hosts[ controller ]: |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1733 | if host is None or host.get( 'ips', [] ) == []: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1734 | main.log.error( |
| 1735 | "DEBUG:Error with host ips on controller" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1736 | controllerStr + ": " + str( host ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1737 | ipResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1738 | ports = [] |
| 1739 | ports.append( main.ONOScli1.ports() ) |
| 1740 | ports.append( main.ONOScli2.ports() ) |
| 1741 | ports.append( main.ONOScli3.ports() ) |
| 1742 | ports.append( main.ONOScli4.ports() ) |
| 1743 | ports.append( main.ONOScli5.ports() ) |
| 1744 | ports.append( main.ONOScli6.ports() ) |
| 1745 | ports.append( main.ONOScli7.ports() ) |
| 1746 | links = [] |
| 1747 | links.append( main.ONOScli1.links() ) |
| 1748 | links.append( main.ONOScli2.links() ) |
| 1749 | links.append( main.ONOScli3.links() ) |
| 1750 | links.append( main.ONOScli4.links() ) |
| 1751 | links.append( main.ONOScli5.links() ) |
| 1752 | links.append( main.ONOScli6.links() ) |
| 1753 | links.append( main.ONOScli7.links() ) |
| 1754 | clusters = [] |
| 1755 | clusters.append( main.ONOScli1.clusters() ) |
| 1756 | clusters.append( main.ONOScli2.clusters() ) |
| 1757 | clusters.append( main.ONOScli3.clusters() ) |
| 1758 | clusters.append( main.ONOScli4.clusters() ) |
| 1759 | clusters.append( main.ONOScli5.clusters() ) |
| 1760 | clusters.append( main.ONOScli6.clusters() ) |
| 1761 | clusters.append( main.ONOScli7.clusters() ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1762 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1763 | elapsed = time.time() - startTime |
| 1764 | cliTime = time.time() - cliStart |
| 1765 | print "CLI time: " + str( cliTime ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1766 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1767 | for controller in range( numControllers ): |
| 1768 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1769 | if devices[ controller ] or "Error" not in devices[ |
| 1770 | controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1771 | currentDevicesResult = main.Mininet1.compareSwitches( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1772 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1773 | json.loads( devices[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1774 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1775 | currentDevicesResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1776 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1777 | actual=currentDevicesResult, |
| 1778 | onpass="ONOS" + controllerStr + |
| 1779 | " Switches view is correct", |
| 1780 | onfail="ONOS" + controllerStr + |
| 1781 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1782 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1783 | if ports[ controller ] or "Error" not in ports[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1784 | currentPortsResult = main.Mininet1.comparePorts( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1785 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1786 | json.loads( ports[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1787 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1788 | currentPortsResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1789 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1790 | actual=currentPortsResult, |
| 1791 | onpass="ONOS" + controllerStr + |
| 1792 | " ports view is correct", |
| 1793 | onfail="ONOS" + controllerStr + |
| 1794 | " ports view is incorrect" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1795 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1796 | if links[ controller ] or "Error" not in links[ controller ]: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1797 | currentLinksResult = main.Mininet1.compareLinks( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1798 | MNTopo, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1799 | json.loads( links[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1800 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1801 | currentLinksResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1802 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1803 | actual=currentLinksResult, |
| 1804 | onpass="ONOS" + controllerStr + |
| 1805 | " links view is correct", |
| 1806 | onfail="ONOS" + controllerStr + |
| 1807 | " links view is incorrect" ) |
| 1808 | |
| 1809 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 1810 | currentHostsResult = main.Mininet1.compareHosts( |
| 1811 | MNTopo, hosts[ controller ] ) |
| 1812 | else: |
| 1813 | currentHostsResult = main.FALSE |
| 1814 | utilities.assert_equals( expect=main.TRUE, |
| 1815 | actual=currentHostsResult, |
| 1816 | onpass="ONOS" + controllerStr + |
| 1817 | " hosts exist in Mininet", |
| 1818 | onfail="ONOS" + controllerStr + |
| 1819 | " hosts don't match Mininet" ) |
| 1820 | |
| 1821 | devicesResults = devicesResults and currentDevicesResult |
| 1822 | portsResults = portsResults and currentPortsResult |
| 1823 | linksResults = linksResults and currentLinksResult |
| 1824 | hostsResults = hostsResults and currentHostsResult |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1825 | |
Jon Hall | 529a37f | 2015-01-28 10:02:00 -0800 | [diff] [blame] | 1826 | # Compare json objects for hosts and dataplane clusters |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1827 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1828 | # hosts |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1829 | consistentHostsResult = main.TRUE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1830 | for controller in range( len( hosts ) ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1831 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1832 | if "Error" not in hosts[ controller ]: |
| 1833 | if hosts[ controller ] == hosts[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1834 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1835 | else: # hosts not consistent |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1836 | main.log.report( "hosts from ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1837 | " is inconsistent with ONOS1" ) |
| 1838 | main.log.warn( repr( hosts[ controller ] ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1839 | consistentHostsResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1840 | |
| 1841 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1842 | main.log.report( "Error in getting ONOS hosts from ONOS" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1843 | controllerStr ) |
| 1844 | consistentHostsResult = main.FALSE |
| 1845 | main.log.warn( "ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1846 | " hosts response: " + |
| 1847 | repr( hosts[ controller ] ) ) |
| 1848 | utilities.assert_equals( |
| 1849 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1850 | actual=consistentHostsResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1851 | onpass="Hosts view is consistent across all ONOS nodes", |
| 1852 | onfail="ONOS nodes have different views of hosts" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1853 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1854 | # Strongly connected clusters of devices |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1855 | consistentClustersResult = main.TRUE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1856 | for controller in range( len( clusters ) ): |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1857 | controllerStr = str( controller + 1 ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1858 | if "Error" not in clusters[ controller ]: |
| 1859 | if clusters[ controller ] == clusters[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1860 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1861 | else: # clusters not consistent |
| 1862 | main.log.report( "clusters from ONOS" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1863 | controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1864 | " is inconsistent with ONOS1" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1865 | consistentClustersResult = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1866 | |
| 1867 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1868 | main.log.report( "Error in getting dataplane clusters " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1869 | "from ONOS" + controllerStr ) |
| 1870 | consistentClustersResult = main.FALSE |
| 1871 | main.log.warn( "ONOS" + controllerStr + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1872 | " clusters response: " + |
| 1873 | repr( clusters[ controller ] ) ) |
| 1874 | utilities.assert_equals( |
| 1875 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1876 | actual=consistentClustersResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1877 | onpass="Clusters view is consistent across all ONOS nodes", |
| 1878 | onfail="ONOS nodes have different views of clusters" ) |
| 1879 | # there should always only be one cluster |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1880 | numClusters = len( json.loads( clusters[ 0 ] ) ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1881 | clusterResults = main.FALSE |
| 1882 | if numClusters == 1: |
| 1883 | clusterResults = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1884 | utilities.assert_equals( |
| 1885 | expect=1, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1886 | actual=numClusters, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1887 | onpass="ONOS shows 1 SCC", |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1888 | onfail="ONOS shows " + str( numClusters ) + " SCCs" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1889 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1890 | topoResult = ( devicesResults and portsResults and linksResults |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1891 | and hostsResults and consistentHostsResult |
| 1892 | and consistentClustersResult and clusterResults |
| 1893 | and ipResult ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1894 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1895 | topoResult = topoResult and int( count <= 2 ) |
| 1896 | note = "note it takes about " + str( int( cliTime ) ) + \ |
| 1897 | " seconds for the test to make all the cli calls to fetch " +\ |
| 1898 | "the topology from each ONOS instance" |
Jon Hall | 1b8f54a | 2015-02-04 13:24:20 -0800 | [diff] [blame] | 1899 | main.log.info( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1900 | "Very crass estimate for topology discovery/convergence( " + |
| 1901 | str( note ) + " ): " + str( elapsed ) + " seconds, " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1902 | str( count ) + " tries" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1903 | utilities.assert_equals( expect=main.TRUE, actual=topoResult, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1904 | onpass="Topology Check Test successful", |
| 1905 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1906 | if topoResult == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1907 | main.log.report( "ONOS topology view matches Mininet topology" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1908 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1909 | def CASE9( self, main ): |
| 1910 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1911 | Link s3-s28 down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1912 | """ |
| 1913 | import time |
| 1914 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1915 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1916 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1917 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1918 | description = "Turn off a link to ensure that Link Discovery " +\ |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1919 | "is working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1920 | main.log.report( description ) |
| 1921 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1922 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1923 | main.step( "Kill Link between s3 and s28" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1924 | LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1925 | main.log.info( "Waiting " + str( linkSleep ) + |
| 1926 | " seconds for link down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1927 | time.sleep( linkSleep ) |
| 1928 | utilities.assert_equals( expect=main.TRUE, actual=LinkDown, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1929 | onpass="Link down succesful", |
| 1930 | onfail="Failed to bring link down" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1931 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1932 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1933 | def CASE10( self, main ): |
| 1934 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1935 | Link s3-s28 up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1936 | """ |
| 1937 | import time |
| 1938 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1939 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1940 | linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1941 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1942 | description = "Restore a link to ensure that Link Discovery is " + \ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 1943 | "working properly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1944 | main.log.report( description ) |
| 1945 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1946 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1947 | main.step( "Bring link between s3 and s28 back up" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1948 | LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1949 | main.log.info( "Waiting " + str( linkSleep ) + |
| 1950 | " seconds for link up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1951 | time.sleep( linkSleep ) |
| 1952 | utilities.assert_equals( expect=main.TRUE, actual=LinkUp, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1953 | onpass="Link up succesful", |
| 1954 | onfail="Failed to bring link up" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1955 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1956 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1957 | def CASE11( self, main ): |
| 1958 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1959 | Switch Down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1960 | """ |
| 1961 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1962 | import time |
| 1963 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1964 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1965 | |
| 1966 | description = "Killing a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1967 | main.log.report( description ) |
| 1968 | main.case( description ) |
| 1969 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1970 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1971 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1972 | # TODO: Make this switch parameterizable |
| 1973 | main.step( "Kill " + switch ) |
| 1974 | main.log.report( "Deleting " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1975 | main.Mininet1.delSwitch( switch ) |
| 1976 | main.log.info( "Waiting " + str( switchSleep ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1977 | " seconds for switch down to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1978 | time.sleep( switchSleep ) |
| 1979 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1980 | # Peek at the deleted switch |
| 1981 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1982 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1983 | if device and device[ 'available' ] is False: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1984 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1985 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 1986 | onpass="Kill switch succesful", |
| 1987 | onfail="Failed to kill switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1988 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1989 | def CASE12( self, main ): |
| 1990 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1991 | Switch Up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1992 | """ |
| 1993 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1994 | import time |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1995 | |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 1996 | switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1997 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1998 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
| 1999 | links = main.params[ 'kill' ][ 'links' ].split() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2000 | description = "Adding a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2001 | main.log.report( description ) |
| 2002 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2003 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2004 | main.step( "Add back " + switch ) |
| 2005 | main.log.report( "Adding back " + switch ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2006 | main.Mininet1.addSwitch( switch, dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2007 | # TODO: New dpid or same? Ask Thomas? |
| 2008 | for peer in links: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2009 | main.Mininet1.addLink( switch, peer ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2010 | main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ], |
| 2011 | count=numControllers, |
| 2012 | ip1=ONOS1Ip, |
| 2013 | port1=ONOS1Port, |
| 2014 | ip2=ONOS2Ip, |
| 2015 | port2=ONOS2Port, |
| 2016 | ip3=ONOS3Ip, |
| 2017 | port3=ONOS3Port, |
| 2018 | ip4=ONOS4Ip, |
| 2019 | port4=ONOS4Port, |
| 2020 | ip5=ONOS5Ip, |
| 2021 | port5=ONOS5Port, |
| 2022 | ip6=ONOS6Ip, |
| 2023 | port6=ONOS6Port, |
| 2024 | ip7=ONOS7Ip, |
| 2025 | port7=ONOS7Port ) |
| 2026 | main.log.info( "Waiting " + str( switchSleep ) + |
| 2027 | " seconds for switch up to be discovered" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2028 | time.sleep( switchSleep ) |
| 2029 | device = main.ONOScli1.getDevice( dpid=switchDPID ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2030 | # Peek at the deleted switch |
| 2031 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2032 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2033 | if device and device[ 'available' ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2034 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2035 | utilities.assert_equals( expect=main.TRUE, actual=result, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2036 | onpass="add switch succesful", |
| 2037 | onfail="Failed to add switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2038 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2039 | def CASE13( self, main ): |
| 2040 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2041 | Clean up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2042 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2043 | import os |
| 2044 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2045 | # TODO: make use of this elsewhere |
| 2046 | ips = [] |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2047 | ips.append( ONOS1Ip ) |
| 2048 | ips.append( ONOS2Ip ) |
| 2049 | ips.append( ONOS3Ip ) |
| 2050 | ips.append( ONOS4Ip ) |
| 2051 | ips.append( ONOS5Ip ) |
| 2052 | ips.append( ONOS6Ip ) |
| 2053 | ips.append( ONOS7Ip ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2054 | |
| 2055 | # printing colors to terminal |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2056 | colors = {} |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2057 | colors[ 'cyan' ] = '\033[96m' |
| 2058 | colors[ 'purple' ] = '\033[95m' |
| 2059 | colors[ 'blue' ] = '\033[94m' |
| 2060 | colors[ 'green' ] = '\033[92m' |
| 2061 | colors[ 'yellow' ] = '\033[93m' |
| 2062 | colors[ 'red' ] = '\033[91m' |
| 2063 | colors[ 'end' ] = '\033[0m' |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2064 | description = "Test Cleanup" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2065 | main.log.report( description ) |
| 2066 | main.case( description ) |
| 2067 | main.step( "Killing tcpdumps" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2068 | main.Mininet2.stopTcpdump() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2069 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2070 | main.step( "Checking ONOS Logs for errors" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2071 | for i in range( 7 ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2072 | print colors[ 'purple' ] + "Checking logs for errors on " + \ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2073 | "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ] |
| 2074 | print main.ONOSbench.checkLogs( ips[ i ] ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2075 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2076 | main.step( "Copying MN pcap and ONOS log files to test station" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2077 | testname = main.TEST |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2078 | teststationUser = main.params[ 'TESTONUSER' ] |
| 2079 | teststationIP = main.params[ 'TESTONIP' ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2080 | # NOTE: MN Pcap file is being saved to ~/packet_captures |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2081 | # scp this file as MN and TestON aren't necessarily the same vm |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2082 | # FIXME: scp |
| 2083 | # mn files |
| 2084 | # TODO: Load these from params |
| 2085 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2086 | logFolder = "/opt/onos/log/" |
| 2087 | logFiles = [ "karaf.log", "karaf.log.1" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2088 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2089 | dstDir = "~/packet_captures/" |
| 2090 | for f in logFiles: |
| 2091 | for i in range( 7 ): |
| 2092 | main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" + |
| 2093 | logFolder + f + " " + |
| 2094 | teststationUser + "@" + |
| 2095 | teststationIP + ":" + |
| 2096 | dstDir + str( testname ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2097 | "-ONOS" + str( i + 1 ) + "-" + |
| 2098 | f ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2099 | main.ONOSbench.handle.expect( "\$" ) |
| 2100 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2101 | # std*.log's |
| 2102 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2103 | logFolder = "/opt/onos/var/" |
| 2104 | logFiles = [ "stderr.log", "stdout.log" ] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2105 | # NOTE: must end in / |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2106 | dstDir = "~/packet_captures/" |
| 2107 | for f in logFiles: |
| 2108 | for i in range( 7 ): |
| 2109 | main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" + |
| 2110 | logFolder + f + " " + |
| 2111 | teststationUser + "@" + |
| 2112 | teststationIP + ":" + |
| 2113 | dstDir + str( testname ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2114 | "-ONOS" + str( i + 1 ) + "-" + |
| 2115 | f ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2116 | main.ONOSbench.handle.expect( "\$" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2117 | # sleep so scp can finish |
| 2118 | time.sleep( 10 ) |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2119 | main.Mininet1.stopNet() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2120 | main.step( "Packing and rotating pcap archives" ) |
| 2121 | os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2122 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2123 | # TODO: actually check something here |
| 2124 | utilities.assert_equals( expect=main.TRUE, actual=main.TRUE, |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2125 | onpass="Test cleanup successful", |
| 2126 | onfail="Test cleanup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2127 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2128 | def CASE14( self, main ): |
| 2129 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2130 | start election app on all onos nodes |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2131 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2132 | leaderResult = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2133 | # install app on onos 1 |
| 2134 | main.log.info( "Install leadership election app" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2135 | main.ONOScli1.featureInstall( "onos-app-election" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2136 | # wait for election |
| 2137 | # check for leader |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2138 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2139 | # verify leader is ONOS1 |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2140 | if leader == ONOS1Ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2141 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2142 | pass |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2143 | elif leader is None: |
| 2144 | # No leader elected |
| 2145 | main.log.report( "No leader was elected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2146 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2147 | elif leader == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2148 | # error in response |
| 2149 | # TODO: add check for "Command not found:" in the driver, this |
| 2150 | # means the app isn't loaded |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2151 | main.log.report( "Something is wrong with electionTestLeader" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2152 | " function, check the error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2153 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2154 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2155 | # error in response |
| 2156 | main.log.report( |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2157 | "Unexpected response from electionTestLeader function:'" + |
| 2158 | str( leader ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2159 | "'" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2160 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2161 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2162 | # install on other nodes and check for leader. |
| 2163 | # Should be onos1 and each app should show the same leader |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2164 | for controller in range( 2, numControllers + 1 ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2165 | # loop through ONOScli handlers |
| 2166 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2167 | node.featureInstall( "onos-app-election" ) |
| 2168 | leaderN = node.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2169 | # verify leader is ONOS1 |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2170 | if leaderN == ONOS1Ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2171 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2172 | pass |
| 2173 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2174 | # error in response |
| 2175 | # TODO: add check for "Command not found:" in the driver, this |
| 2176 | # means the app isn't loaded |
| 2177 | main.log.report( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2178 | "electionTestLeader function, check the" + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2179 | " error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2180 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2181 | elif leader != leaderN: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2182 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2183 | main.log.report( "ONOS" + str( controller ) + " sees " + |
| 2184 | str( leaderN ) + |
| 2185 | " as the leader of the election app. Leader" + |
| 2186 | " should be " + |
| 2187 | str( leader ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2188 | if leaderResult: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2189 | main.log.report( "Leadership election tests passed( consistent " + |
| 2190 | "view of leader across listeners and a leader " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2191 | "was elected )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2192 | utilities.assert_equals( |
| 2193 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2194 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2195 | onpass="Leadership election passed", |
| 2196 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2197 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2198 | def CASE15( self, main ): |
| 2199 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2200 | Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2201 | """ |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2202 | leaderResult = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2203 | description = "Check that Leadership Election is still functional" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2204 | main.log.report( description ) |
| 2205 | main.case( description ) |
| 2206 | main.step( "Find current leader and withdraw" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2207 | leader = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2208 | # TODO: do some sanity checking on leader before using it |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2209 | withdrawResult = main.FALSE |
| 2210 | if leader == ONOS1Ip: |
| 2211 | oldLeader = getattr( main, "ONOScli1" ) |
| 2212 | elif leader == ONOS2Ip: |
| 2213 | oldLeader = getattr( main, "ONOScli2" ) |
| 2214 | elif leader == ONOS3Ip: |
| 2215 | oldLeader = getattr( main, "ONOScli3" ) |
| 2216 | elif leader == ONOS4Ip: |
| 2217 | oldLeader = getattr( main, "ONOScli4" ) |
| 2218 | elif leader == ONOS5Ip: |
| 2219 | oldLeader = getattr( main, "ONOScli5" ) |
| 2220 | elif leader == ONOS6Ip: |
| 2221 | oldLeader = getattr( main, "ONOScli6" ) |
| 2222 | elif leader == ONOS7Ip: |
| 2223 | oldLeader = getattr( main, "ONOScli7" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2224 | elif leader is None or leader == main.FALSE: |
| 2225 | main.log.report( |
| 2226 | "Leader for the election app should be an ONOS node," + |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2227 | "instead got '" + str( leader ) + "'" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2228 | leaderResult = main.FALSE |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2229 | oldLeader = None |
| 2230 | else: |
| 2231 | main.log.error( "Leader election --- why am I HERE?!?") |
| 2232 | if oldLeader: |
| 2233 | withdrawResult = oldLeader.electionTestWithdraw() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2234 | utilities.assert_equals( |
| 2235 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2236 | actual=withdrawResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2237 | onpass="App was withdrawn from election", |
| 2238 | onfail="App was not withdrawn from election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2239 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2240 | main.step( "Make sure new leader is elected" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2241 | leaderList = [] |
| 2242 | for controller in range( 1, numControllers + 1 ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2243 | # loop through ONOScli handlers |
| 2244 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2245 | leaderList.append( node.electionTestLeader() ) |
| 2246 | for leaderN in leaderList: |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2247 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2248 | main.log.report( |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2249 | "ONOS" + str( controller ) + |
| 2250 | " still sees " + str( leader ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2251 | " as leader after they withdrew" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2252 | leaderResult = main.FALSE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2253 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2254 | # error in response |
| 2255 | # TODO: add check for "Command not found:" in the driver, this |
| 2256 | # means the app isn't loaded |
| 2257 | main.log.report( "Something is wrong with " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2258 | "electionTestLeader function, " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2259 | "check the error logs" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2260 | leaderResult = main.FALSE |
| 2261 | consistentLeader = main.FALSE |
| 2262 | if len( set( leaderList ) ) == 1: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2263 | main.log.info( "Each Election-app sees '" + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2264 | str( leaderList[ 0 ] ) + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2265 | "' as the leader" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2266 | consistentLeader = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2267 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2268 | main.log.report( |
| 2269 | "Inconsistent responses for leader of Election-app:" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2270 | for n in range( len( leaderList ) ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2271 | main.log.report( "ONOS" + str( n + 1 ) + " response: " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2272 | str( leaderList[ n ] ) ) |
| 2273 | if leaderResult: |
| 2274 | main.log.report( "Leadership election tests passed( consistent " + |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2275 | "view of leader across listeners and a new " + |
| 2276 | "leader was elected when the old leader " + |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2277 | "resigned )" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2278 | utilities.assert_equals( |
| 2279 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2280 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2281 | onpass="Leadership election passed", |
| 2282 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2283 | |
Jon Hall | 58c76b7 | 2015-02-23 11:09:24 -0800 | [diff] [blame] | 2284 | main.step( "Run for election on old leader( just so everyone " + |
| 2285 | "is in the hat )" ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2286 | if oldLeader: |
| 2287 | runResult = oldLeader.electionTestRun() |
| 2288 | else: |
| 2289 | runResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2290 | utilities.assert_equals( |
| 2291 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2292 | actual=runResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2293 | onpass="App re-ran for election", |
| 2294 | onfail="App failed to run for election" ) |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2295 | if consistentLeader == main.TRUE: |
| 2296 | afterRun = main.ONOScli1.electionTestLeader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2297 | # verify leader didn't just change |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2298 | if afterRun == leaderList[ 0 ]: |
| 2299 | leaderResult = main.TRUE |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2300 | else: |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2301 | leaderResult = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2302 | # TODO: assert on run and withdraw results? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2303 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2304 | utilities.assert_equals( |
| 2305 | expect=main.TRUE, |
Jon Hall | 8f89dda | 2015-01-22 16:03:33 -0800 | [diff] [blame] | 2306 | actual=leaderResult, |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2307 | onpass="Leadership election passed", |
| 2308 | onfail="Something went wrong with Leadership election after " + |
| 2309 | "the old leader re-ran for election" ) |