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 a single |
| 3 | instance ONOS 'cluster' can handle a restart |
| 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. Since this is the Sanity test, we do nothing. |
| 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 | 48cf3ce | 2015-01-12 15:43:18 -0800 | [diff] [blame] | 22 | class HATestSingleInstanceRestart: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 23 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 24 | def __init__( self ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 25 | self.default = '' |
| 26 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 27 | def CASE1( self, main ): |
| 28 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 29 | CASE1 is to compile ONOS and push it to the test machines |
| 30 | |
| 31 | Startup sequence: |
| 32 | git pull |
| 33 | mvn clean install |
| 34 | onos-package |
| 35 | cell <name> |
| 36 | onos-verify-cell |
| 37 | NOTE: temporary - onos-remove-raft-logs |
| 38 | onos-install -f |
| 39 | onos-wait-for-start |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 40 | """ |
| 41 | main.log.report( "ONOS Single node cluster restart " + |
| 42 | "HA test - initialization" ) |
| 43 | main.case( "Setting up test environment" ) |
| 44 | # TODO: save all the timers and output them for plotting |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 45 | |
| 46 | # load some vairables from the params file |
| 47 | PULL_CODE = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 48 | if main.params[ 'Git' ] == 'True': |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 49 | PULL_CODE = True |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 50 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 51 | cell_name = main.params[ 'ENV' ][ 'cellName' ] |
| 52 | |
| 53 | # set global variables |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 54 | global ONOS1_ip |
| 55 | global ONOS1_port |
| 56 | global ONOS2_ip |
| 57 | global ONOS2_port |
| 58 | global ONOS3_ip |
| 59 | global ONOS3_port |
| 60 | global ONOS4_ip |
| 61 | global ONOS4_port |
| 62 | global ONOS5_ip |
| 63 | global ONOS5_port |
| 64 | global ONOS6_ip |
| 65 | global ONOS6_port |
| 66 | global ONOS7_ip |
| 67 | global ONOS7_port |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 68 | global num_controllers |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 69 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 70 | ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 71 | ONOS1_port = main.params[ 'CTRL' ][ 'port1' ] |
| 72 | ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ] |
| 73 | ONOS2_port = main.params[ 'CTRL' ][ 'port2' ] |
| 74 | ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ] |
| 75 | ONOS3_port = main.params[ 'CTRL' ][ 'port3' ] |
| 76 | ONOS4_ip = main.params[ 'CTRL' ][ 'ip4' ] |
| 77 | ONOS4_port = main.params[ 'CTRL' ][ 'port4' ] |
| 78 | ONOS5_ip = main.params[ 'CTRL' ][ 'ip5' ] |
| 79 | ONOS5_port = main.params[ 'CTRL' ][ 'port5' ] |
| 80 | ONOS6_ip = main.params[ 'CTRL' ][ 'ip6' ] |
| 81 | ONOS6_port = main.params[ 'CTRL' ][ 'port6' ] |
| 82 | ONOS7_ip = main.params[ 'CTRL' ][ 'ip7' ] |
| 83 | ONOS7_port = main.params[ 'CTRL' ][ 'port7' ] |
| 84 | num_controllers = int( main.params[ 'num_controllers' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 85 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 86 | main.step( "Applying cell variable to environment" ) |
| 87 | cell_result = main.ONOSbench.set_cell( cell_name ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 88 | verify_result = main.ONOSbench.verify_cell() |
| 89 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 90 | # FIXME:this is short term fix |
| 91 | main.log.report( "Removing raft logs" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 92 | main.ONOSbench.onos_remove_raft_logs() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 93 | main.log.report( "Uninstalling ONOS" ) |
| 94 | main.ONOSbench.onos_uninstall( ONOS1_ip ) |
| 95 | main.ONOSbench.onos_uninstall( ONOS2_ip ) |
| 96 | main.ONOSbench.onos_uninstall( ONOS3_ip ) |
| 97 | main.ONOSbench.onos_uninstall( ONOS4_ip ) |
| 98 | main.ONOSbench.onos_uninstall( ONOS5_ip ) |
| 99 | main.ONOSbench.onos_uninstall( ONOS6_ip ) |
| 100 | main.ONOSbench.onos_uninstall( ONOS7_ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 101 | |
| 102 | clean_install_result = main.TRUE |
| 103 | git_pull_result = main.TRUE |
| 104 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 105 | main.step( "Compiling the latest version of ONOS" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 106 | if PULL_CODE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 107 | # TODO Configure branch in params |
| 108 | main.step( "Git checkout and pull master" ) |
| 109 | main.ONOSbench.git_checkout( "master" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 110 | git_pull_result = main.ONOSbench.git_pull() |
| 111 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 112 | main.step( "Using mvn clean & install" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 113 | clean_install_result = main.TRUE |
| 114 | if git_pull_result == main.TRUE: |
| 115 | clean_install_result = main.ONOSbench.clean_install() |
| 116 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 117 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 118 | "clean install" ) |
| 119 | main.ONOSbench.get_version( 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 | cell_result = main.ONOSbench.set_cell( "SingleHA" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 122 | verify_result = main.ONOSbench.verify_cell() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 123 | main.step( "Creating ONOS package" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 124 | package_result = main.ONOSbench.onos_package() |
| 125 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 126 | main.step( "Installing ONOS package" ) |
| 127 | onos1_install_result = main.ONOSbench.onos_install( options="-f", |
| 128 | node=ONOS1_ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 129 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 130 | main.step( "Checking if ONOS is up yet" ) |
| 131 | # TODO check bundle:list? |
| 132 | for i in range( 2 ): |
| 133 | onos1_isup = main.ONOSbench.isup( ONOS1_ip ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 134 | if onos1_isup: |
| 135 | break |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 136 | if not onos1_isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 137 | main.log.report( "ONOS1 didn't start!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 138 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 139 | cli_result = main.ONOScli1.start_onos_cli( ONOS1_ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 140 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 141 | main.step( "Start Packet Capture MN" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 142 | main.Mininet2.start_tcpdump( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 143 | str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST ) |
| 144 | + "-MN.pcap", |
| 145 | intf=main.params[ 'MNtcpdump' ][ 'intf' ], |
| 146 | port=main.params[ 'MNtcpdump' ][ 'port' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 147 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 148 | case1_result = ( clean_install_result and package_result and |
| 149 | cell_result and verify_result and onos1_install_result |
| 150 | and onos1_isup and cli_result ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 151 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 152 | utilities.assert_equals( expect=main.TRUE, actual=case1_result, |
| 153 | onpass="Test startup successful", |
| 154 | onfail="Test startup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 155 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 156 | if case1_result == main.FALSE: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 157 | main.cleanup() |
| 158 | main.exit() |
| 159 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 160 | def CASE2( self, main ): |
| 161 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 162 | Assign mastership to controllers |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 163 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 164 | import re |
| 165 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 166 | main.log.report( "Assigning switches to controllers" ) |
| 167 | main.case( "Assigning Controllers" ) |
| 168 | main.step( "Assign switches to controllers" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 169 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 170 | for i in range( 1, 29 ): |
| 171 | main.Mininet1.assign_sw_controller( |
| 172 | sw=str( i ), |
| 173 | ip1=ONOS1_ip, port1=ONOS1_port ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 174 | |
| 175 | mastership_check = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 176 | for i in range( 1, 29 ): |
| 177 | response = main.Mininet1.get_sw_controller( "s" + str( i ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 178 | try: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 179 | main.log.info( str( response ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 180 | except: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 181 | main.log.info( repr( response ) ) |
| 182 | if re.search( "tcp:" + ONOS1_ip, response ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 183 | mastership_check = mastership_check and main.TRUE |
| 184 | else: |
| 185 | mastership_check = main.FALSE |
| 186 | if mastership_check == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 187 | main.log.report( "Switch mastership assigned correctly" ) |
| 188 | utilities.assert_equals( |
| 189 | expect=main.TRUE, |
| 190 | actual=mastership_check, |
| 191 | onpass="Switch mastership assigned correctly", |
| 192 | onfail="Switches not assigned correctly to controllers" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 193 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 194 | def CASE3( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 195 | """ |
| 196 | Assign intents |
| 197 | |
| 198 | """ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 199 | # FIXME: we must reinstall intents until we have a persistant |
| 200 | # datastore! |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 201 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 202 | main.log.report( "Adding host intents" ) |
| 203 | main.case( "Adding host Intents" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 204 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 205 | main.step( "Discovering Hosts( Via pingall for now)" ) |
| 206 | # FIXME: Once we have a host discovery mechanism, use that instead |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 207 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 208 | # install onos-app-fwd |
| 209 | main.log.info( "Install reactive forwarding app" ) |
| 210 | main.ONOScli1.feature_install( "onos-app-fwd" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 211 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 212 | # REACTIVE FWD test |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 213 | ping_result = main.FALSE |
| 214 | time1 = time.time() |
| 215 | ping_result = main.Mininet1.pingall() |
| 216 | time2 = time.time() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 217 | main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 218 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 219 | # uninstall onos-app-fwd |
| 220 | main.log.info( "Uninstall reactive forwarding app" ) |
| 221 | main.ONOScli1.feature_uninstall( "onos-app-fwd" ) |
| 222 | # timeout for fwd flows |
| 223 | time.sleep( 10 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 224 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 225 | main.step( "Add host intents" ) |
| 226 | # TODO: move the host numbers to params |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 227 | intent_add_result = True |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 228 | for i in range( 8, 18 ): |
| 229 | main.log.info( "Adding host intent between h" + str( i ) + |
| 230 | " and h" + str( i + 10 ) ) |
| 231 | host1 = "00:00:00:00:00:" + \ |
| 232 | str( hex( i )[ 2: ] ).zfill( 2 ).upper() |
| 233 | host2 = "00:00:00:00:00:" + \ |
| 234 | str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper() |
| 235 | host1_id = main.ONOScli1.get_host( host1 )[ 'id' ] |
| 236 | host2_id = main.ONOScli1.get_host( host2 )[ 'id' ] |
| 237 | # NOTE: get host can return None |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 238 | if host1_id and host2_id: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 239 | tmp_result = main.ONOScli1.add_host_intent( |
| 240 | host1_id, |
| 241 | host2_id ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 242 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 243 | main.log.error( "Error, get_host() failed" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 244 | tmp_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 245 | intent_add_result = bool( ping_result and intent_add_result |
| 246 | and tmp_result ) |
| 247 | utilities.assert_equals( |
| 248 | expect=True, |
| 249 | actual=intent_add_result, |
| 250 | onpass="Switch mastership correctly assigned", |
| 251 | onfail="Error in (re)assigning switch mastership" ) |
| 252 | # TODO Check if intents all exist in datastore |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 253 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 254 | def CASE4( self, main ): |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 255 | """ |
| 256 | Ping across added host intents |
| 257 | """ |
| 258 | description = " Ping across added host intents" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 259 | main.log.report( description ) |
| 260 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 261 | Ping_Result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 262 | for i in range( 8, 18 ): |
| 263 | ping = main.Mininet1.pingHost( |
| 264 | src="h" + str( i ), target="h" + str( i + 10 ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 265 | Ping_Result = Ping_Result and ping |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 266 | if ping == main.FALSE: |
| 267 | main.log.warn( "Ping failed between h" + str( i ) + |
| 268 | " and h" + str( i + 10 ) ) |
| 269 | elif ping == main.TRUE: |
| 270 | main.log.info( "Ping test passed!" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 271 | Ping_Result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 272 | if Ping_Result == main.FALSE: |
| 273 | main.log.report( |
| 274 | "Intents have not been installed correctly, pings failed." ) |
| 275 | if Ping_Result == main.TRUE: |
| 276 | main.log.report( |
| 277 | "Intents have been installed correctly and verified by pings" ) |
| 278 | utilities.assert_equals( |
| 279 | expect=main.TRUE, |
| 280 | actual=Ping_Result, |
| 281 | onpass="Intents have been installed correctly and pings work", |
| 282 | onfail="Intents have not been installed correctly, pings failed." ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 283 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 284 | def CASE5( self, main ): |
| 285 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 286 | Reading state of ONOS |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 287 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 288 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 289 | # assumes that sts is already in you PYTHONPATH |
| 290 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 291 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 292 | main.log.report( "Setting up and gathering data for current state" ) |
| 293 | main.case( "Setting up and gathering data for current state" ) |
| 294 | # The general idea for this test case is to pull the state of |
| 295 | # ( intents,flows, topology,... ) from each ONOS node |
| 296 | # We can then compare them with eachother and also with past states |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 297 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 298 | main.step( "Get the Mastership of each switch from each controller" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 299 | global mastership_state |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 300 | mastership_state = [] |
| 301 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 302 | # Assert that each device has a master |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 303 | roles_not_null = main.ONOScli1.roles_not_null() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 304 | utilities.assert_equals( |
| 305 | expect=main.TRUE, |
| 306 | actual=roles_not_null, |
| 307 | onpass="Each device has a master", |
| 308 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 309 | |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 310 | ONOS1_mastership = main.ONOScli1.roles() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 311 | # TODO: Make this a meaningful check |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 312 | if "Error" in ONOS1_mastership or not ONOS1_mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 313 | main.log.report( "Error in getting ONOS roles" ) |
| 314 | main.log.warn( |
| 315 | "ONOS1 mastership response: " + |
| 316 | repr( ONOS1_mastership ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 317 | consistent_mastership = main.FALSE |
| 318 | else: |
| 319 | mastership_state = ONOS1_mastership |
| 320 | consistent_mastership = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 321 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 322 | main.step( "Get the intents from each controller" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 323 | global intent_state |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 324 | intent_state = [] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 325 | ONOS1_intents = main.ONOScli1.intents( json_format=True ) |
| 326 | intent_check = main.FALSE |
| 327 | if "Error" in ONOS1_intents or not ONOS1_intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 328 | main.log.report( "Error in getting ONOS intents" ) |
| 329 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 330 | else: |
| 331 | intent_check = main.TRUE |
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 | main.step( "Get the flows from each controller" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 334 | global flow_state |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 335 | flow_state = [] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 336 | ONOS1_flows = main.ONOScli1.flows( json_format=True ) |
| 337 | flow_check = main.FALSE |
| 338 | if "Error" in ONOS1_flows or not ONOS1_flows: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 339 | main.log.report( "Error in getting ONOS intents" ) |
| 340 | main.log.warn( "ONOS1 flows repsponse: " + ONOS1_flows ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 341 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 342 | # TODO: Do a better check, maybe compare flows on switches? |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 343 | flow_state = ONOS1_flows |
| 344 | flow_check = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 345 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 346 | main.step( "Get the OF Table entries" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 347 | global flows |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 348 | flows = [] |
| 349 | for i in range( 1, 29 ): |
| 350 | flows.append( main.Mininet2.get_flowTable( 1.3, "s" + str( i ) ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 351 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 352 | # TODO: Compare switch flow tables with ONOS flow tables |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 353 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 354 | main.step( "Create TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 355 | ctrls = [] |
| 356 | count = 1 |
| 357 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 358 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 359 | temp = temp + ( "ONOS" + str( count ), ) |
| 360 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 361 | temp = temp + \ |
| 362 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 363 | ctrls.append( temp ) |
| 364 | MNTopo = TestONTopology( |
| 365 | main.Mininet1, |
| 366 | ctrls ) # can also add Intent API info for intent operations |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 367 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 368 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 369 | devices = [] |
| 370 | devices.append( main.ONOScli1.devices() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 371 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 372 | hosts = [] |
| 373 | hosts.append( main.ONOScli1.hosts() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 374 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 375 | ports = [] |
| 376 | ports.append( main.ONOScli1.ports() ) |
| 377 | links = [] |
| 378 | links.append( main.ONOScli1.links() ) |
| 379 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 380 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 381 | devices_results = main.TRUE |
| 382 | ports_results = main.TRUE |
| 383 | links_results = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 384 | for controller in range( num_controllers ): |
| 385 | controller_str = str( controller + 1 ) |
| 386 | if devices[ controller ] or "Error" not in devices[ controller ]: |
| 387 | current_devices_result = main.Mininet1.compare_switches( |
| 388 | MNTopo, |
| 389 | json.loads( |
| 390 | devices[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 391 | else: |
| 392 | current_devices_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 393 | utilities.assert_equals( expect=main.TRUE, |
| 394 | actual=current_devices_result, |
| 395 | onpass="ONOS" + controller_str + |
| 396 | " Switches view is correct", |
| 397 | onfail="ONOS" + controller_str + |
| 398 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 399 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 400 | if ports[ controller ] or "Error" not in ports[ controller ]: |
| 401 | current_ports_result = main.Mininet1.compare_ports( |
| 402 | MNTopo, |
| 403 | json.loads( |
| 404 | ports[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 405 | else: |
| 406 | current_ports_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 407 | utilities.assert_equals( expect=main.TRUE, |
| 408 | actual=current_ports_result, |
| 409 | onpass="ONOS" + controller_str + |
| 410 | " ports view is correct", |
| 411 | onfail="ONOS" + controller_str + |
| 412 | " ports view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 413 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 414 | if links[ controller ] or "Error" not in links[ controller ]: |
| 415 | current_links_result = main.Mininet1.compare_links( |
| 416 | MNTopo, |
| 417 | json.loads( |
| 418 | links[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 419 | else: |
| 420 | current_links_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 421 | utilities.assert_equals( expect=main.TRUE, |
| 422 | actual=current_links_result, |
| 423 | onpass="ONOS" + controller_str + |
| 424 | " links view is correct", |
| 425 | onfail="ONOS" + controller_str + |
| 426 | " links view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 427 | |
| 428 | devices_results = devices_results and current_devices_result |
| 429 | ports_results = ports_results and current_ports_result |
| 430 | links_results = links_results and current_links_result |
| 431 | |
| 432 | topo_result = devices_results and ports_results and links_results |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 433 | utilities.assert_equals( expect=main.TRUE, actual=topo_result, |
| 434 | onpass="Topology Check Test successful", |
| 435 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 436 | |
| 437 | final_assert = main.TRUE |
| 438 | final_assert = final_assert and topo_result and flow_check \ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 439 | and intent_check and consistent_mastership and roles_not_null |
| 440 | utilities.assert_equals( expect=main.TRUE, actual=final_assert, |
| 441 | onpass="State check successful", |
| 442 | onfail="State check NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 443 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 444 | def CASE6( self, main ): |
| 445 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 446 | The Failure case. |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 447 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 448 | import time |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 449 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 450 | main.log.report( "Restart ONOS node" ) |
| 451 | main.log.case( "Restart ONOS node" ) |
| 452 | main.ONOSbench.onos_kill( ONOS1_ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 453 | start = time.time() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 454 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 455 | main.step( "Checking if ONOS is up yet" ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 456 | count = 0 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 457 | while count < 10: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 458 | onos1_isup = main.ONOSbench.isup( ONOS1_ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 459 | if onos1_isup == main.TRUE: |
| 460 | elapsed = time.time() - start |
| 461 | break |
| 462 | else: |
| 463 | count = count + 1 |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 464 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 465 | cli_result = main.ONOScli1.start_onos_cli( ONOS1_ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 466 | |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 467 | case_results = main.TRUE and onos1_isup and cli_result |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 468 | utilities.assert_equals( expect=main.TRUE, actual=case_results, |
| 469 | onpass="ONOS restart successful", |
| 470 | onfail="ONOS restart NOT successful" ) |
| 471 | main.log.info( |
| 472 | "ESTIMATE: ONOS took %s seconds to restart" % |
| 473 | str( elapsed ) ) |
| 474 | time.sleep( 5 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 475 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 476 | def CASE7( self, main ): |
| 477 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 478 | Check state after ONOS failure |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 479 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 480 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 481 | main.case( "Running ONOS Constant State Tests" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 482 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 483 | # Assert that each device has a master |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 484 | roles_not_null = main.ONOScli1.roles_not_null() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 485 | utilities.assert_equals( |
| 486 | expect=main.TRUE, |
| 487 | actual=roles_not_null, |
| 488 | onpass="Each device has a master", |
| 489 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 490 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 491 | main.step( "Check if switch roles are consistent across all nodes" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 492 | ONOS1_mastership = main.ONOScli1.roles() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 493 | # FIXME: Refactor this whole case for single instance |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 494 | if "Error" in ONOS1_mastership or not ONOS1_mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 495 | main.log.report( "Error in getting ONOS mastership" ) |
| 496 | main.log.warn( |
| 497 | "ONOS1 mastership response: " + |
| 498 | repr( ONOS1_mastership ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 499 | consistent_mastership = main.FALSE |
| 500 | else: |
| 501 | consistent_mastership = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 502 | main.log.report( |
| 503 | "Switch roles are consistent across all ONOS nodes" ) |
| 504 | utilities.assert_equals( |
| 505 | expect=main.TRUE, |
| 506 | actual=consistent_mastership, |
| 507 | onpass="Switch roles are consistent across all ONOS nodes", |
| 508 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 509 | |
| 510 | description2 = "Compare switch roles from before failure" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 511 | main.step( description2 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 512 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 513 | current_json = json.loads( ONOS1_mastership ) |
| 514 | old_json = json.loads( mastership_state ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 515 | mastership_check = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 516 | for i in range( 1, 29 ): |
| 517 | switchDPID = str( |
| 518 | main.Mininet1.getSwitchDPID( |
| 519 | switch="s" + |
| 520 | str( i ) ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 521 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 522 | current = [ switch[ 'master' ] for switch in current_json |
| 523 | if switchDPID in switch[ 'id' ] ] |
| 524 | old = [ switch[ 'master' ] for switch in old_json |
| 525 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 526 | if current == old: |
| 527 | mastership_check = mastership_check and main.TRUE |
| 528 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 529 | main.log.warn( "Mastership of switch %s changed" % switchDPID ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 530 | mastership_check = main.FALSE |
| 531 | if mastership_check == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 532 | main.log.report( "Mastership of Switches was not changed" ) |
| 533 | utilities.assert_equals( |
| 534 | expect=main.TRUE, |
| 535 | actual=mastership_check, |
| 536 | onpass="Mastership of Switches was not changed", |
| 537 | onfail="Mastership of some switches changed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 538 | mastership_check = mastership_check and consistent_mastership |
| 539 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 540 | main.step( "Get the intents and compare across all nodes" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 541 | ONOS1_intents = main.ONOScli1.intents( json_format=True ) |
| 542 | intent_check = main.FALSE |
| 543 | if "Error" in ONOS1_intents or not ONOS1_intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 544 | main.log.report( "Error in getting ONOS intents" ) |
| 545 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 546 | else: |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 547 | intent_check = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 548 | main.log.report( "Intents are consistent across all ONOS nodes" ) |
| 549 | utilities.assert_equals( |
| 550 | expect=main.TRUE, |
| 551 | actual=intent_check, |
| 552 | onpass="Intents are consistent across all ONOS nodes", |
| 553 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 554 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 555 | # NOTE: Hazelcast has no durability, so intents are lost across system |
| 556 | # restarts |
| 557 | """ |
| 558 | main.step( "Compare current intents with intents before the failure" ) |
| 559 | # NOTE: this requires case 5 to pass for intent_state to be set. |
| 560 | # maybe we should stop the test if that fails? |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 561 | if intent_state == ONOS1_intents: |
| 562 | same_intents = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 563 | main.log.report( "Intents are consistent with before failure" ) |
| 564 | # TODO: possibly the states have changed? we may need to figure out |
| 565 | # what the aceptable states are |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 566 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 567 | try: |
| 568 | main.log.warn( "ONOS1 intents: " ) |
| 569 | print json.dumps( json.loads( ONOS1_intents ), |
| 570 | sort_keys=True, indent=4, |
| 571 | separators=( ',', ': ' ) ) |
| 572 | except: |
| 573 | pass |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 574 | same_intents = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 575 | utilities.assert_equals( |
| 576 | expect=main.TRUE, |
| 577 | actual=same_intents, |
| 578 | onpass="Intents are consistent with before failure", |
| 579 | onfail="The Intents changed during failure" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 580 | intent_check = intent_check and same_intents |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 581 | """ |
| 582 | main.step( "Get the OF Table entries and compare to before " + |
| 583 | "component failure" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 584 | Flow_Tables = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 585 | flows2 = [] |
| 586 | for i in range( 28 ): |
| 587 | main.log.info( "Checking flow table on s" + str( i + 1 ) ) |
| 588 | tmp_flows = main.Mininet2.get_flowTable( 1.3, "s" + str( i + 1 ) ) |
| 589 | flows2.append( tmp_flows ) |
| 590 | temp_result = main.Mininet2.flow_comp( |
| 591 | flow1=flows[ i ], |
| 592 | flow2=tmp_flows ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 593 | Flow_Tables = Flow_Tables and temp_result |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 594 | if Flow_Tables == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 595 | main.log.info( "Differences in flow table for switch: s" + |
| 596 | str( i + 1 ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 597 | if Flow_Tables == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 598 | main.log.report( "No changes were found in the flow tables" ) |
| 599 | utilities.assert_equals( |
| 600 | expect=main.TRUE, |
| 601 | actual=Flow_Tables, |
| 602 | onpass="No changes were found in the flow tables", |
| 603 | onfail="Changes were found in the flow tables" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 604 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 605 | # Test of LeadershipElection |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 606 | |
| 607 | leader = ONOS1_ip |
| 608 | leader_result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 609 | for controller in range( 1, num_controllers + 1 ): |
| 610 | # loop through ONOScli handlers |
| 611 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 612 | leaderN = node.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 613 | # verify leader is ONOS1 |
| 614 | # NOTE even though we restarted ONOS, it is the only one so onos 1 |
| 615 | # must be leader |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 616 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 617 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 618 | pass |
| 619 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 620 | # error in response |
| 621 | main.log.report( "Something is wrong with " + |
| 622 | "election_test_leader function, check the" + |
| 623 | " error logs" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 624 | leader_result = main.FALSE |
| 625 | elif leader != leaderN: |
| 626 | leader_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 627 | main.log.report( "ONOS" + str( controller ) + |
| 628 | " sees " + str( leaderN ) + |
| 629 | " as the leader of the election app." + |
| 630 | " Leader should be " + str( leader ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 631 | if leader_result: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 632 | main.log.report( "Leadership election tests passed(consistent " + |
| 633 | "view of leader across listeners and a new " + |
| 634 | "leader was re-elected if applicable)" ) |
| 635 | utilities.assert_equals( |
| 636 | expect=main.TRUE, |
| 637 | actual=leader_result, |
| 638 | onpass="Leadership election passed", |
| 639 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 640 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 641 | result = ( mastership_check and intent_check and Flow_Tables and |
| 642 | roles_not_null and leader_result ) |
| 643 | result = int( result ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 644 | if result == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 645 | main.log.report( "Constant State Tests Passed" ) |
| 646 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 647 | onpass="Constant State Tests Passed", |
| 648 | onfail="Constant state tests failed" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 649 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 650 | def CASE8( self, main ): |
| 651 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 652 | Compare topo |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 653 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 654 | import sys |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 655 | # FIXME add this path to params |
| 656 | sys.path.append( "/home/admin/sts" ) |
| 657 | # assumes that sts is already in you PYTHONPATH |
| 658 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 659 | import json |
| 660 | import time |
| 661 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 662 | description = "Compare ONOS Topology view to Mininet topology" |
| 663 | main.case( description ) |
| 664 | main.log.report( description ) |
| 665 | main.step( "Create TestONTopology object" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 666 | ctrls = [] |
| 667 | count = 1 |
| 668 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 669 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 670 | temp = temp + ( "ONOS" + str( count ), ) |
| 671 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 672 | temp = temp + \ |
| 673 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 674 | ctrls.append( temp ) |
| 675 | MNTopo = TestONTopology( |
| 676 | main.Mininet1, |
| 677 | ctrls ) # can also add Intent API info for intent operations |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 678 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 679 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 680 | devices_results = main.TRUE |
| 681 | ports_results = main.TRUE |
| 682 | links_results = main.TRUE |
| 683 | topo_result = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 684 | elapsed = 0 |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 685 | count = 0 |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 686 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 687 | start_time = time.time() |
| 688 | while topo_result == main.FALSE and elapsed < 60: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 689 | count = count + 1 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 690 | if count > 1: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 691 | MNTopo = TestONTopology( |
| 692 | main.Mininet1, |
| 693 | ctrls ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 694 | cli_start = time.time() |
| 695 | devices = [] |
| 696 | devices.append( main.ONOScli1.devices() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 697 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 698 | hosts = [] |
| 699 | hosts.append( main.ONOScli1.hosts() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 700 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 701 | ports = [] |
| 702 | ports.append( main.ONOScli1.ports() ) |
| 703 | links = [] |
| 704 | links.append( main.ONOScli1.links() ) |
| 705 | elapsed = time.time() - start_time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 706 | cli_time = time.time() - cli_start |
| 707 | print "CLI time: " + str( cli_time ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 708 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 709 | for controller in range( num_controllers ): |
| 710 | controller_str = str( controller + 1 ) |
| 711 | if devices[ controller ] or "Error" not in devices[ |
| 712 | controller ]: |
| 713 | current_devices_result = main.Mininet1.compare_switches( |
| 714 | MNTopo, |
| 715 | json.loads( |
| 716 | devices[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 717 | else: |
| 718 | current_devices_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 719 | utilities.assert_equals( expect=main.TRUE, |
| 720 | actual=current_devices_result, |
| 721 | onpass="ONOS" + controller_str + |
| 722 | " Switches view is correct", |
| 723 | onfail="ONOS" + controller_str + |
| 724 | " Switches view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 725 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 726 | if ports[ controller ] or "Error" not in ports[ controller ]: |
| 727 | current_ports_result = main.Mininet1.compare_ports( |
| 728 | MNTopo, |
| 729 | json.loads( |
| 730 | ports[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 731 | else: |
| 732 | current_ports_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 733 | utilities.assert_equals( expect=main.TRUE, |
| 734 | actual=current_ports_result, |
| 735 | onpass="ONOS" + controller_str + |
| 736 | " ports view is correct", |
| 737 | onfail="ONOS" + controller_str + |
| 738 | " ports view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 739 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 740 | if links[ controller ] or "Error" not in links[ controller ]: |
| 741 | current_links_result = main.Mininet1.compare_links( |
| 742 | MNTopo, |
| 743 | json.loads( |
| 744 | links[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 745 | else: |
| 746 | current_links_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 747 | utilities.assert_equals( expect=main.TRUE, |
| 748 | actual=current_links_result, |
| 749 | onpass="ONOS" + controller_str + |
| 750 | " links view is correct", |
| 751 | onfail="ONOS" + controller_str + |
| 752 | " links view is incorrect" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 753 | devices_results = devices_results and current_devices_result |
| 754 | ports_results = ports_results and current_ports_result |
| 755 | links_results = links_results and current_links_result |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 756 | topo_result = devices_results and ports_results and links_results |
| 757 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 758 | topo_result = topo_result and int( count <= 2 ) |
| 759 | note = "note it takes about " + str( int( cli_time ) ) + \ |
| 760 | " seconds for the test to make all the cli calls to fetch " +\ |
| 761 | "the topology from each ONOS instance" |
| 762 | main.log.report( |
| 763 | "Very crass estimate for topology discovery/convergence(" + |
| 764 | str( note ) + "): " + str( elapsed ) + " seconds, " + |
| 765 | str( count ) + " tries" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 766 | if elapsed > 60: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 767 | main.log.report( "Giving up on topology convergence" ) |
| 768 | utilities.assert_equals( expect=main.TRUE, actual=topo_result, |
| 769 | onpass="Topology Check Test successful", |
| 770 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 771 | if topo_result == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 772 | main.log.report( "ONOS topology view matches Mininet topology" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 773 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 774 | def CASE9( self, main ): |
| 775 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 776 | Link s3-s28 down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 777 | """ |
| 778 | import time |
| 779 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 780 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 781 | link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 782 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 783 | description = "Turn off a link to ensure that Link Discovery " +\ |
| 784 | "is working properly" |
| 785 | main.log.report( description ) |
| 786 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 787 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 788 | main.step( "Kill Link between s3 and s28" ) |
| 789 | Link_Down = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" ) |
| 790 | main.log.info( |
| 791 | "Waiting " + |
| 792 | str( link_sleep ) + |
| 793 | " seconds for link down to be discovered" ) |
| 794 | time.sleep( link_sleep ) |
| 795 | utilities.assert_equals( expect=main.TRUE, actual=Link_Down, |
| 796 | onpass="Link down succesful", |
| 797 | onfail="Failed to bring link down" ) |
| 798 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 799 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 800 | def CASE10( self, main ): |
| 801 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 802 | Link s3-s28 up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 803 | """ |
| 804 | import time |
| 805 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 806 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 807 | link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 808 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 809 | description = "Restore a link to ensure that Link Discovery is " + \ |
| 810 | "working properly" |
| 811 | main.log.report( description ) |
| 812 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 813 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 814 | main.step( "Bring link between s3 and s28 back up" ) |
| 815 | Link_Up = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" ) |
| 816 | main.log.info( |
| 817 | "Waiting " + |
| 818 | str( link_sleep ) + |
| 819 | " seconds for link up to be discovered" ) |
| 820 | time.sleep( link_sleep ) |
| 821 | utilities.assert_equals( expect=main.TRUE, actual=Link_Up, |
| 822 | onpass="Link up succesful", |
| 823 | onfail="Failed to bring link up" ) |
| 824 | # TODO do some sort of check here |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 825 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 826 | def CASE11( self, main ): |
| 827 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 828 | Switch Down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 829 | """ |
| 830 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 831 | import time |
| 832 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 833 | switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 834 | |
| 835 | description = "Killing a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 836 | main.log.report( description ) |
| 837 | main.case( description ) |
| 838 | switch = main.params[ 'kill' ][ 'switch' ] |
| 839 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 840 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 841 | # TODO: Make this switch parameterizable |
| 842 | main.step( "Kill " + switch ) |
| 843 | main.log.report( "Deleting " + switch ) |
| 844 | main.Mininet1.del_switch( switch ) |
| 845 | main.log.info( "Waiting " + str( switch_sleep ) + |
| 846 | " seconds for switch down to be discovered" ) |
| 847 | time.sleep( switch_sleep ) |
| 848 | device = main.ONOScli1.get_device( dpid=switchDPID ) |
| 849 | # Peek at the deleted switch |
| 850 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 851 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 852 | if device and device[ 'available' ] is False: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 853 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 854 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 855 | onpass="Kill switch succesful", |
| 856 | onfail="Failed to kill switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 857 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 858 | def CASE12( self, main ): |
| 859 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 860 | Switch Up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 861 | """ |
| 862 | # NOTE: You should probably run a topology check after this |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 863 | import time |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 864 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 865 | switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 866 | switch = main.params[ 'kill' ][ 'switch' ] |
| 867 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
| 868 | links = main.params[ 'kill' ][ 'links' ].split() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 869 | description = "Adding a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 870 | main.log.report( description ) |
| 871 | main.case( description ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 872 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 873 | main.step( "Add back " + switch ) |
| 874 | main.log.report( "Adding back " + switch ) |
| 875 | main.Mininet1.add_switch( switch, dpid=switchDPID ) |
| 876 | # TODO: New dpid or same? Ask Thomas? |
| 877 | for peer in links: |
| 878 | main.Mininet1.add_link( switch, peer ) |
| 879 | main.Mininet1.assign_sw_controller( sw=switch.split( 's' )[ 1 ], |
| 880 | ip1=ONOS1_ip, port1=ONOS1_port ) |
| 881 | main.log.info( |
| 882 | "Waiting " + |
| 883 | str( switch_sleep ) + |
| 884 | " seconds for switch up to be discovered" ) |
| 885 | time.sleep( switch_sleep ) |
| 886 | device = main.ONOScli1.get_device( dpid=switchDPID ) |
| 887 | # Peek at the deleted switch |
| 888 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 889 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 890 | if device and device[ 'available' ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 891 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 892 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 893 | onpass="add switch succesful", |
| 894 | onfail="Failed to add switch?" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 895 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 896 | def CASE13( self, main ): |
| 897 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 898 | Clean up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 899 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 900 | import os |
| 901 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 902 | # printing colors to terminal |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 903 | colors = {} |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 904 | colors[ 'cyan' ] = '\033[96m' |
| 905 | colors[ 'purple' ] = '\033[95m' |
| 906 | colors[ 'blue' ] = '\033[94m' |
| 907 | colors[ 'green' ] = '\033[92m' |
| 908 | colors[ 'yellow' ] = '\033[93m' |
| 909 | colors[ 'red' ] = '\033[91m' |
| 910 | colors[ 'end' ] = '\033[0m' |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 911 | description = "Test Cleanup" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 912 | main.log.report( description ) |
| 913 | main.case( description ) |
| 914 | main.step( "Killing tcpdumps" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 915 | main.Mininet2.stop_tcpdump() |
| 916 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 917 | main.step( "Checking ONOS Logs for errors" ) |
| 918 | print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \ |
| 919 | colors[ 'end' ] |
| 920 | print main.ONOSbench.check_logs( ONOS1_ip ) |
| 921 | main.step( "Copying MN pcap and ONOS log files to test station" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 922 | testname = main.TEST |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 923 | teststation_user = main.params[ 'TESTONUSER' ] |
| 924 | teststation_IP = main.params[ 'TESTONIP' ] |
| 925 | # NOTE: MN Pcap file is being saved to ~/packet_captures |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 926 | # 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] | 927 | # FIXME: scp |
| 928 | # mn files |
| 929 | # TODO: Load these from params |
| 930 | # NOTE: must end in / |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 931 | log_folder = "/opt/onos/log/" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 932 | log_files = [ "karaf.log", "karaf.log.1" ] |
| 933 | # NOTE: must end in / |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 934 | dst_dir = "~/packet_captures/" |
| 935 | for f in log_files: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 936 | main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1_ip + ":" + |
| 937 | log_folder + f + " " + |
| 938 | teststation_user + "@" + |
| 939 | teststation_IP + ":" + dst_dir + |
| 940 | str( testname ) + "-ONOS1-" + f ) |
| 941 | main.ONOSbench.handle.expect( "\$" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 942 | print main.ONOSbench.handle.before |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 943 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 944 | # std*.log's |
| 945 | # NOTE: must end in / |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 946 | log_folder = "/opt/onos/var/" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 947 | log_files = [ "stderr.log", "stdout.log" ] |
| 948 | # NOTE: must end in / |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 949 | dst_dir = "~/packet_captures/" |
| 950 | for f in log_files: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 951 | main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1_ip + ":" + |
| 952 | log_folder + f + " " + |
| 953 | teststation_user + "@" + |
| 954 | teststation_IP + ":" + dst_dir + |
| 955 | str( testname ) + "-ONOS1-" + f ) |
| 956 | # sleep so scp can finish |
| 957 | time.sleep( 10 ) |
| 958 | main.step( "Packing and rotating pcap archives" ) |
| 959 | os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 960 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 961 | # TODO: actually check something here |
| 962 | utilities.assert_equals( expect=main.TRUE, actual=main.TRUE, |
| 963 | onpass="Test cleanup successful", |
| 964 | onfail="Test cleanup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 965 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 966 | def CASE14( self, main ): |
| 967 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 968 | start election app on all onos nodes |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 969 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 970 | leader_result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 971 | # install app on onos 1 |
| 972 | main.log.info( "Install leadership election app" ) |
| 973 | main.ONOScli1.feature_install( "onos-app-election" ) |
| 974 | # wait for election |
| 975 | # check for leader |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 976 | leader = main.ONOScli1.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 977 | # verify leader is ONOS1 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 978 | if leader == ONOS1_ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 979 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 980 | pass |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 981 | elif leader is None: |
| 982 | # No leader elected |
| 983 | main.log.report( "No leader was elected" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 984 | leader_result = main.FALSE |
| 985 | elif leader == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 986 | # error in response |
| 987 | # TODO: add check for "Command not found:" in the driver, this |
| 988 | # means the app isn't loaded |
| 989 | main.log.report( "Something is wrong with election_test_leader" + |
| 990 | " function, check the error logs" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 991 | leader_result = main.FALSE |
| 992 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 993 | # error in response |
| 994 | main.log.report( |
| 995 | "Unexpected response from election_test_leader function:'" + |
| 996 | str(leader) + |
| 997 | "'" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 998 | leader_result = main.FALSE |
| 999 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1000 | # install on other nodes and check for leader. |
| 1001 | # Should be onos1 and each app should show the same leader |
| 1002 | for controller in range( 2, num_controllers + 1 ): |
| 1003 | # loop through ONOScli handlers |
| 1004 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
| 1005 | node.feature_install( "onos-app-election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1006 | leaderN = node.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1007 | # verify leader is ONOS1 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1008 | if leaderN == ONOS1_ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1009 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1010 | pass |
| 1011 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1012 | # error in response |
| 1013 | # TODO: add check for "Command not found:" in the driver, this |
| 1014 | # means the app isn't loaded |
| 1015 | main.log.report( "Something is wrong with " + |
| 1016 | "election_test_leader function, check the" + |
| 1017 | " error logs" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1018 | leader_result = main.FALSE |
| 1019 | elif leader != leaderN: |
| 1020 | leader_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1021 | main.log.report( "ONOS" + str( controller ) + " sees " + |
| 1022 | str( leaderN ) + |
| 1023 | " as the leader of the election app. Leader" + |
| 1024 | " should be " + |
| 1025 | str( leader ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1026 | if leader_result: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1027 | main.log.report( "Leadership election tests passed( consistent " + |
| 1028 | "view of leader across listeners and a leader " + |
| 1029 | "was elected)" ) |
| 1030 | utilities.assert_equals( |
| 1031 | expect=main.TRUE, |
| 1032 | actual=leader_result, |
| 1033 | onpass="Leadership election passed", |
| 1034 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1035 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1036 | def CASE15( self, main ): |
| 1037 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1038 | Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1039 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1040 | leader_result = main.TRUE |
| 1041 | description = "Check that Leadership Election is still functional" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1042 | main.log.report( description ) |
| 1043 | main.case( description ) |
| 1044 | main.step( "Find current leader and withdraw" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1045 | leader = main.ONOScli1.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1046 | # TODO: do some sanity checking on leader before using it |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1047 | withdraw_result = main.FALSE |
| 1048 | if leader == ONOS1_ip: |
| 1049 | old_leader = getattr( main, "ONOScli1" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1050 | elif leader is None or leader == main.FALSE: |
| 1051 | main.log.report( |
| 1052 | "Leader for the election app should be an ONOS node," + |
| 1053 | "instead got '" + |
| 1054 | str(leader) + |
| 1055 | "'" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1056 | leader_result = main.FALSE |
| 1057 | withdraw_result = old_leader.election_test_withdraw() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1058 | utilities.assert_equals( |
| 1059 | expect=main.TRUE, |
| 1060 | actual=withdraw_result, |
| 1061 | onpass="App was withdrawn from election", |
| 1062 | onfail="App was not withdrawn from election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1063 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1064 | main.step( "Make sure new leader is elected" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1065 | leader_list = [] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1066 | leaderN = main.ONOScli1.election_test_leader() |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1067 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1068 | main.log.report( "ONOS still sees " + str( leaderN ) + |
| 1069 | " as leader after they withdrew" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1070 | leader_result = main.FALSE |
| 1071 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1072 | # error in response |
| 1073 | # TODO: add check for "Command not found:" in the driver, this |
| 1074 | # means the app isn't loaded |
| 1075 | main.log.report( "Something is wrong with election_test_leader " + |
| 1076 | "function, check the error logs" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1077 | leader_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1078 | elif leaderN is None: |
| 1079 | main.log.info( |
| 1080 | "There is no leader after the app withdrew from election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1081 | if leader_result: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1082 | main.log.report( "Leadership election tests passed(There is no " + |
| 1083 | "leader after the old leader resigned)" ) |
| 1084 | utilities.assert_equals( |
| 1085 | expect=main.TRUE, |
| 1086 | actual=leader_result, |
| 1087 | onpass="Leadership election passed", |
| 1088 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1089 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1090 | main.step( |
| 1091 | "Run for election on old leader(just so everyone is in the hat)" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1092 | run_result = old_leader.election_test_run() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1093 | utilities.assert_equals( |
| 1094 | expect=main.TRUE, |
| 1095 | actual=run_result, |
| 1096 | onpass="App re-ran for election", |
| 1097 | onfail="App failed to run for election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1098 | leader = main.ONOScli1.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1099 | # verify leader is ONOS1 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1100 | if leader == ONOS1_ip: |
| 1101 | leader_result = main.TRUE |
| 1102 | else: |
| 1103 | leader_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1104 | # TODO: assert on run and withdraw results? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1105 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1106 | utilities.assert_equals( |
| 1107 | expect=main.TRUE, |
| 1108 | actual=leader_result, |
| 1109 | onpass="Leadership election passed", |
| 1110 | onfail="ONOS1's election app was not leader after it re-ran " + |
| 1111 | "for election" ) |