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