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