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