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