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