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