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