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