Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1 | |
| 2 | #Testing the basic functionality of ONOS Next |
| 3 | #For sanity and driver functionality excercises only. |
| 4 | |
| 5 | import time |
| 6 | import sys |
| 7 | import os |
| 8 | import re |
| 9 | |
| 10 | class JonTest: |
| 11 | def __init__(self): |
| 12 | self.default = '' |
| 13 | |
| 14 | def CASE1(self, main): |
| 15 | ''' |
| 16 | Startup sequence: |
| 17 | git pull |
| 18 | mvn clean install |
| 19 | onos-package |
| 20 | cell <name> |
| 21 | onos-verify-cell |
| 22 | onos-install -f |
| 23 | onos-wait-for-start |
| 24 | ''' |
| 25 | import time |
| 26 | |
| 27 | PULL_CODE = False |
| 28 | if main.params['Git'] == 'True': |
| 29 | PULL_CODE = True |
| 30 | cell_name = main.params['ENV']['cellName'] |
| 31 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 32 | ONOS1_port = main.params['CTRL']['port1'] |
| 33 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 34 | ONOS2_port = main.params['CTRL']['port2'] |
| 35 | |
| 36 | main.case("Setting up test environment") |
| 37 | |
| 38 | main.step("Applying cell variable to environment") |
| 39 | cell_result = main.ONOSbench.set_cell(cell_name) |
| 40 | #cell_result = main.ONOSbench.set_cell("temp_cell_2") |
| 41 | verify_result = main.ONOSbench.verify_cell() |
| 42 | |
| 43 | if PULL_CODE: |
| 44 | main.step("Git checkout and pull master") |
| 45 | #main.log.report("Skipping git pull") |
| 46 | main.ONOSbench.git_checkout("master") |
| 47 | git_pull_result = main.ONOSbench.git_pull() |
| 48 | main.log.report(main.ONOSbench.get_version()) |
| 49 | |
| 50 | main.step("Using mvn clean & install") |
| 51 | clean_install_result = main.FALSE |
| 52 | if git_pull_result: |
| 53 | clean_install_result = main.ONOSbench.clean_install() |
| 54 | else: |
| 55 | main.log.report("git pull failed so skipping mvn clean install") |
| 56 | |
| 57 | main.step("Creating ONOS package") |
| 58 | package_result = main.ONOSbench.onos_package() |
| 59 | |
| 60 | main.step("Installing ONOS package") |
| 61 | onos1_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS1_ip) |
| 62 | onos2_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS2_ip) |
| 63 | onos1_isup = main.ONOSbench.isup(ONOS1_ip) |
| 64 | onos2_isup = main.ONOSbench.isup(ONOS2_ip) |
| 65 | |
| 66 | main.step("Starting ONOS service") |
| 67 | start_result = main.TRUE |
| 68 | #start_result = main.ONOSbench.onos_start(ONOS1_ip) |
| 69 | |
| 70 | case1_result = (clean_install_result and package_result and\ |
| 71 | cell_result and verify_result and onos1_install_result and\ |
| 72 | onos2_install_result and onos1_isup and onos2_isup ) |
| 73 | utilities.assert_equals(expect=main.TRUE, actual=case1_result, |
| 74 | onpass="Test startup successful", |
| 75 | onfail="Test startup NOT successful") |
| 76 | |
| 77 | |
| 78 | def CASE11(self, main): |
| 79 | ''' |
| 80 | Cleanup sequence: |
| 81 | onos-service <node_ip> stop |
| 82 | onos-uninstall |
| 83 | |
| 84 | TODO: Define rest of cleanup |
| 85 | |
| 86 | ''' |
| 87 | |
| 88 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 89 | |
| 90 | main.case("Cleaning up test environment") |
| 91 | |
| 92 | main.step("Testing ONOS kill function") |
| 93 | kill_result = main.ONOSbench.onos_kill(ONOS1_ip) |
| 94 | |
| 95 | main.step("Stopping ONOS service") |
| 96 | stop_result = main.ONOSbench.onos_stop(ONOS1_ip) |
| 97 | |
| 98 | main.step("Uninstalling ONOS service") |
| 99 | uninstall_result = main.ONOSbench.onos_uninstall() |
| 100 | |
| 101 | def CASE3(self, main): |
| 102 | ''' |
| 103 | Test 'onos' command and its functionality in driver |
| 104 | ''' |
| 105 | |
| 106 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 107 | |
| 108 | main.case("Testing 'onos' command") |
| 109 | |
| 110 | main.step("Sending command 'onos -w <onos-ip> system:name'") |
| 111 | cmdstr1 = "system:name" |
| 112 | cmd_result1 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr1) |
| 113 | main.log.info("onos command returned: "+cmd_result1) |
| 114 | |
| 115 | main.step("Sending command 'onos -w <onos-ip> onos:topology'") |
| 116 | cmdstr2 = "onos:topology" |
| 117 | cmd_result2 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr2) |
| 118 | main.log.info("onos command returned: "+cmd_result2) |
| 119 | |
| 120 | main.step("Testing check_status") |
| 121 | check_status_results = main.FALSE |
| 122 | check_status_results = main.ONOSbench.check_status(ONOS1_ip, 4, 6) |
| 123 | main.log.info("Results of check_status " + str(check_status_results)) |
| 124 | |
| 125 | main.step("Sending command 'onos -w <onos-ip> bundle:list'") |
| 126 | cmdstr3 = "bundle:list" |
| 127 | cmd_result3 = main.ONOSbench.onos_cli(ONOS1_ip, cmdstr3) |
| 128 | main.log.info("onos command returned: "+cmd_result3) |
| 129 | case3_result = (cmd_result1 and cmd_result2 and\ |
| 130 | check_status_results and cmd_result3 ) |
| 131 | utilities.assert_equals(expect=main.TRUE, actual=case3_result, |
| 132 | onpass="Test case 3 successful", |
| 133 | onfail="Test case 3 NOT successful") |
| 134 | |
| 135 | def CASE4(self, main): |
| 136 | import re |
| 137 | import time |
| 138 | main.case("Pingall Test(No intents are added)") |
| 139 | main.step("Assigning switches to controllers") |
| 140 | for i in range(1,5): #1 to (num of switches +1) |
| 141 | main.Mininet1.assign_sw_controller(sw=str(i),count=2, |
| 142 | ip1=ONOS1_ip, port1=ONOS1_port, |
| 143 | ip2=ONOS2_ip, port2=ONOS2_port) |
| 144 | |
| 145 | switch_mastership = main.TRUE |
| 146 | for i in range (1,5): |
| 147 | response = main.Mininet1.get_sw_controller("s"+str(i)) |
| 148 | print("Response is " + str(response)) |
| 149 | if re.search("tcp:"+ONOS1_ip,response): |
| 150 | switch_mastership = switch_mastership and main.TRUE |
| 151 | else: |
| 152 | switch_mastership = main.FALSE |
| 153 | |
| 154 | |
| 155 | #REACTIVE FWD test |
| 156 | main.step("Pingall") |
| 157 | ping_result = main.FALSE |
| 158 | time1 = time.time() |
| 159 | ping_result = main.Mininet1.pingall() |
| 160 | time2 = time.time() |
| 161 | print "Time for pingall: %2f seconds" % (time2 - time1) |
| 162 | |
| 163 | case4_result = switch_mastership and ping_result |
| 164 | utilities.assert_equals(expect=main.TRUE, actual=case4_result, |
| 165 | onpass="Pingall Test successful", |
| 166 | onfail="Pingall Test NOT successful") |
| 167 | |
| 168 | def CASE5(self, main): |
| 169 | ''' |
| 170 | Test the ONOS-cli functionality |
| 171 | |
| 172 | Below are demonstrations of what the |
| 173 | ONOS cli driver functions can be used for. |
| 174 | ''' |
| 175 | import time |
| 176 | import json |
| 177 | |
| 178 | cell_name = main.params['ENV']['cellName'] |
| 179 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 180 | |
| 181 | main.case("Testing the ONOS-cli") |
| 182 | |
| 183 | main.step("Set cell for ONOS-cli environment") |
| 184 | main.ONOScli.set_cell(cell_name) |
| 185 | |
| 186 | main.step("Start ONOS-cli") |
| 187 | main.ONOScli.start_onos_cli(ONOS1_ip) |
| 188 | |
| 189 | main.step("issue command: onos:topology") |
| 190 | topology_obj = main.ONOScli.topology() |
| 191 | |
| 192 | main.step("issue various feature:install <str> commands") |
| 193 | #main.ONOScli.feature_install("onos-app-fwd") |
| 194 | #main.ONOScli.feature_install("onos-rest") |
| 195 | |
| 196 | main.step("Add a bad node") |
| 197 | node_result = main.ONOScli.add_node("111", "10.128.20.") |
| 198 | if node_result == main.TRUE: |
| 199 | main.log.info("Node successfully added") |
| 200 | |
| 201 | main.step("Add a correct node") |
| 202 | node_result = main.ONOScli.add_node("111", "10.128.20.12") |
| 203 | |
| 204 | main.step("Assign switches and list devices") |
| 205 | for i in range(1,8): |
| 206 | main.Mininet1.handle.sendline("sh ovs-vsctl set-controller s"+str(i)+ |
| 207 | " tcp:10.128.20.11") |
| 208 | main.Mininet1.handle.expect("mininet>") |
| 209 | #Need to sleep to allow switch add processing |
| 210 | time.sleep(5) |
| 211 | list_result = main.ONOScli.devices() |
| 212 | main.log.info(list_result) |
| 213 | |
| 214 | main.step("Get all devices id") |
| 215 | devices_id_list = main.ONOScli.get_all_devices_id() |
| 216 | main.log.info(devices_id_list) |
| 217 | |
| 218 | main.step("Get path and cost between device 1 and 7") |
| 219 | (path, cost) = main.ONOScli.paths(devices_id_list[0], devices_id_list[6]) |
| 220 | main.log.info("Path: "+str(path)) |
| 221 | main.log.info("Cost: "+str(cost)) |
| 222 | |
| 223 | main.step("Get nodes currently visible") |
| 224 | nodes_str = main.ONOScli.nodes() |
| 225 | main.log.info(nodes_str) |
| 226 | |
| 227 | main.step("Get all nodes id's") |
| 228 | node_id_list = main.ONOScli.get_all_nodes_id() |
| 229 | main.log.info(node_id_list) |
| 230 | |
| 231 | main.step("Set device "+str(devices_id_list[0])+" to role: standby") |
| 232 | device_role_result = main.ONOScli.device_role( |
| 233 | devices_id_list[0], node_id_list[0], "standby") |
| 234 | if device_role_result == main.TRUE: |
| 235 | main.log.report("Device role successfully set") |
| 236 | |
| 237 | main.step("Revert device role to master") |
| 238 | device_role = main.ONOScli.device_role( |
| 239 | devices_id_list[0], node_id_list[0], "master") |
| 240 | |
| 241 | main.step("Check devices / role again") |
| 242 | dev_result = main.ONOScli.devices() |
| 243 | main.log.info(dev_result) |
| 244 | |
| 245 | #Sample steps to push intents *********** |
| 246 | # * Obtain host id in ONOS format |
| 247 | # * Push intents |
| 248 | main.step("Get list of hosts from Mininet") |
| 249 | host_list = main.Mininet2.get_hosts() |
| 250 | main.log.info(host_list) |
| 251 | |
| 252 | main.step("Get host list in ONOS format") |
| 253 | host_onos_list = main.ONOScli.get_hosts_id(host_list) |
| 254 | main.log.info(host_onos_list) |
| 255 | |
| 256 | main.step("Ensure that reactive forwarding is installed") |
| 257 | feature_result = main.ONOScli.feature_install("onos-app-fwd") |
| 258 | |
| 259 | time.sleep(5) |
| 260 | |
| 261 | main.Mininet2.handle.sendline("\r") |
| 262 | main.Mininet2.handle.sendline("h4 ping h5 -c 1") |
| 263 | |
| 264 | time.sleep(5) |
| 265 | |
| 266 | main.step("Get hosts") |
| 267 | main.ONOScli.handle.sendline("hosts") |
| 268 | main.ONOScli.handle.expect("onos>") |
| 269 | hosts = main.ONOScli.handle.before |
| 270 | main.log.info(hosts) |
| 271 | |
| 272 | main.step("Install host-to-host-intents between h4 and h5") |
| 273 | intent_install = main.ONOScli.add_host_intent( |
| 274 | host_onos_list[3], host_onos_list[4]) |
| 275 | main.log.info(intent_install) |
| 276 | |
| 277 | main.step("Uninstall reactive forwarding to test host-to-host intent") |
| 278 | main.ONOScli.feature_uninstall("onos-app-fwd") |
| 279 | |
| 280 | main.step("Get intents installed on ONOS") |
| 281 | get_intent_result = main.ONOScli.intents() |
| 282 | main.log.info(get_intent_result) |
| 283 | #**************************************** |
| 284 | |
| 285 | |
| 286 | def CASE7(self, main): |
| 287 | ''' |
| 288 | Test compare topo functions |
| 289 | ''' |
| 290 | import sys |
| 291 | sys.path.append("/home/admin/sts") # Trying to remove some dependancies, #FIXME add this path to params |
| 292 | from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH |
| 293 | import json |
| 294 | |
| 295 | main.step("Create TestONTopology object") |
| 296 | ctrls = [] |
| 297 | count = 1 |
| 298 | while True: |
| 299 | temp = () |
| 300 | if ('ip' + str(count)) in main.params['CTRL']: |
| 301 | temp = temp + (getattr(main,('ONOS' + str(count))),) |
| 302 | temp = temp + ("ONOS"+str(count),) |
| 303 | temp = temp + (main.params['CTRL']['ip'+str(count)],) |
| 304 | temp = temp + (eval(main.params['CTRL']['port'+str(count)]),) |
| 305 | ctrls.append(temp) |
| 306 | count = count + 1 |
| 307 | else: |
| 308 | break |
| 309 | MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations |
| 310 | |
| 311 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 312 | ONOS2_ip = main.params['CTRL']['ip2'] |
| 313 | |
| 314 | main.ONOScli1.start_onos_cli(ONOS1_ip) |
| 315 | main.ONOScli2.start_onos_cli(ONOS2_ip) |
| 316 | |
| 317 | main.step("Collecting topology information from ONOS") |
| 318 | devices1 = main.ONOScli1.devices() |
| 319 | devices2 = main.ONOScli2.devices() |
| 320 | switch1 = main.ONOScli1.get_device("0000000000000001") |
| 321 | hosts1 = main.ONOScli1.hosts() |
| 322 | hosts2 = main.ONOScli2.hosts() |
| 323 | host1 = main.ONOScli1.get_host("00:00:00:00:00:01") |
| 324 | print json.dumps(json.loads(hosts1), sort_keys=True,indent=4,separators=(',', ': ')) |
| 325 | print json.dumps(json.loads(hosts2), sort_keys=True,indent=4,separators=(',', ': ')) |
| 326 | print json.dumps(host1, sort_keys=True,indent=4,separators=(',', ': ')) |
| 327 | ports1 = main.ONOScli1.ports() |
| 328 | ports2 = main.ONOScli2.ports() |
| 329 | links1 = main.ONOScli1.links() |
| 330 | links2 = main.ONOScli2.links() |
| 331 | |
| 332 | |
| 333 | main.step("Comparing ONOS topology to MN") |
| 334 | #results = main.Mininet1.compare_topo(MNTopo, json.loads(devices)) |
| 335 | switches_results1 = main.Mininet1.compare_switches(MNTopo, json.loads(devices1)) |
| 336 | utilities.assert_equals(expect=main.TRUE, actual=switches_results1, |
| 337 | onpass="ONOS1 Switches view is correct", |
| 338 | onfail="ONOS1 Switches view is incorrect") |
| 339 | |
| 340 | switches_results2 = main.Mininet1.compare_switches(MNTopo, json.loads(devices2)) |
| 341 | utilities.assert_equals(expect=main.TRUE, actual=switches_results2, |
| 342 | onpass="ONOS2 Switches view is correct", |
| 343 | onfail="ONOS2 Switches view is incorrect") |
| 344 | |
| 345 | |
| 346 | ports_results1 = main.Mininet1.compare_ports(MNTopo, json.loads(ports1)) |
| 347 | utilities.assert_equals(expect=main.TRUE, actual=ports_results1, |
| 348 | onpass="ONOS1 Ports view is correct", |
| 349 | onfail="ONOS1 Ports view is incorrect") |
| 350 | |
| 351 | ports_results2 = main.Mininet1.compare_ports(MNTopo, json.loads(ports2)) |
| 352 | utilities.assert_equals(expect=main.TRUE, actual=ports_results2, |
| 353 | onpass="ONOS2 Ports view is correct", |
| 354 | onfail="ONOS2 Ports view is incorrect") |
| 355 | |
| 356 | links_results1 = main.Mininet1.compare_links(MNTopo, json.loads(links1)) |
| 357 | utilities.assert_equals(expect=main.TRUE, actual=links_results1, |
| 358 | onpass="ONOS1 Links view is correct", |
| 359 | onfail="ONOS1 Links view is incorrect") |
| 360 | |
| 361 | links_results2 = main.Mininet1.compare_links(MNTopo, json.loads(links2)) |
| 362 | utilities.assert_equals(expect=main.TRUE, actual=links_results2, |
| 363 | onpass="ONOS2 Links view is correct", |
| 364 | onfail="ONOS2 Links view is incorrect") |
| 365 | |
| 366 | topo_result = switches_results1 and switches_results2 \ |
| 367 | and ports_results1 and ports_results2\ |
| 368 | and links_results1 and links_results2 |
| 369 | utilities.assert_equals(expect=main.TRUE, actual=topo_result, |
| 370 | onpass="Topology Check Test successful", |
| 371 | onfail="Topology Check Test NOT successful") |
| 372 | |
| 373 | ###### |
| 374 | #jhall@onlab.us |
| 375 | #andrew@onlab.us |
| 376 | ###### |