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