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