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