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