def setUp(self): # Run Voltha,OFAgent,3 ONOS and form ONOS cluster. print "Starting all containers ..." cmd = command_defs['docker_compose_start_all'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Waiting for all containers to be ready ..." sleep(60) cmd = command_defs['onos1_ip'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos1_ip = out print "ONOS1 IP is {}".format(onos1_ip) cmd = command_defs['onos2_ip'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos2_ip = out print "ONOS2 IP is {}".format(onos2_ip) cmd = command_defs['onos3_ip'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos3_ip = out print "ONOS3 IP is {}".format(onos3_ip) cmd = command_defs['onos_form_cluster'] + ' {} {} {}'.format(onos1_ip.strip(), onos2_ip.strip(), onos3_ip.strip()) out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Cluster Output :{} ".format(out) self.get_rest_endpoint()
def setUp(self): # Run Voltha,OFAgent,3 ONOS and form ONOS cluster. print "Starting all containers ..." cmd = command_defs['docker_compose_start_all'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Waiting for all containers to be ready ..." sleep(80) cmd = command_defs['onos1_ip'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos1_ip = out print "ONOS1 IP is {}".format(onos1_ip) cmd = command_defs['onos2_ip'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos2_ip = out print "ONOS2 IP is {}".format(onos2_ip) cmd = command_defs['onos3_ip'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos3_ip = out print "ONOS3 IP is {}".format(onos3_ip) cmd = command_defs['onos_form_cluster'] + ' {} {} {}'.format( onos1_ip.strip(), onos2_ip.strip(), onos3_ip.strip()) out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Cluster Output :{} ".format(out) self.get_rest_endpoint()
def stop_voltha(self, remove=False): t0 = time() self.pt("Stopping voltha ...") cmd = command_defs['docker_compose_stop_voltha'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) if remove: cmd = command_defs['docker_compose_remove_voltha'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0)
def tearDown(self): # Stopping and Removing Voltha,OFAgent,3 ONOS. print "Stopping and removing all containers ..." cmd = command_defs['docker_compose_stop'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Waiting for all containers to be stopped ..." sleep(1) cmd = command_defs['docker_compose_rm_f'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0)
def test_01_basic_def(self): print "Test_01_basic_def_Start:------------------" t0 = time.time() # input file: /voltha/tests/utests/netconf/yang/basic.yang expected_response = """ syntax = "proto3"; package basic; message commonAttributes { uint32 my_id = 1 ; string my_name = 2 ; bool my_status = 3 ; } """ try: cmd = pyang_cmd.format('basic.yang') print 'running command: {}'.format(cmd) response, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) self._compare_file(response, expected_response) finally: print "Test_01_basic_def_End:------------------ took {} " \ "secs\n\n".format(time.time() - t0)
def test_04_cord_tenant(self): print "Test_04_cord_tenant_Start:------------------" t0 = time.time() # input file: /voltha/tests/utests/netconf/yang/cord-tenant.yang expected_response = """ syntax = "proto3"; package cord_tenant; message subscriber { string label = 1 ; enum status { violation = 0 ; enabled = 1 ; delinquent = 2 ; suspended = 3 ; } bool demo = 3 ; } """ try: cmd = pyang_cmd.format('cord-tenant.yang') print 'running command: {}'.format(cmd) response, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) self._compare_file(response, expected_response) finally: print "Test_04_cord_tenant_End:------------------ took {} " \ "secs\n\n".format(time.time() - t0)
def test_02_container_def(self): print "Test_02_container_def_Start:------------------" t0 = time.time() # input file: /voltha/tests/utests/netconf/yang/container.yang expected_response = """ syntax = "proto3"; package container; message int_container { int32 eight = 1 ; int32 nine = 2 ; } """ try: cmd = pyang_cmd.format('container.yang') print 'running command: {}'.format(cmd) response, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) self._compare_file(response, expected_response) finally: print "Test_02_container_def_End:------------------ took {} " \ "secs\n\n".format(time.time() - t0)
def _stop_and_remove_all_containers(self): # check if there are any running containers first cmd = command_defs['docker_ps'] out, err, rc = run_command_to_completion_with_stdout_in_list(cmd) self.assertEqual(rc, 0) if len(out) > 1: # not counting docker ps header cmd = command_defs['docker_stop_and_remove_all_containers'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0)
def start_container(self, container): print "Starting {} ...".format(container) cmd = command_defs['docker_start'].format(container) out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) time.sleep(10) print "Started {}".format(container)
def start_container(self, container): print "Starting {} ...".format(container) cmd = command_defs['docker_start'].format(container) out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) sleep(10) print "Started {}".format(container)
def enable_device(self, device_id): print "Enabling device - id:{}".format(device_id) cmd = command_defs['enable_olt'].format(device_id) out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) time.sleep(30) print "Enabled device - id:{}".format(device_id)
def _gen_yang(self, proto): try: save_file(os.path.join(TEMP_PATH, TEMP_INPUT_PROTO_FILE), proto) cmd = proto_to_yang_cmd.format(TEMP_PATH, TEMP_PATH, TEMP_PROTO_PATH) print 'running command: {}'.format(cmd) response, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) return load_file(TEMP_YANG_PATH) except Exception as e: print('Failure to generate yang file {}'.format(e))
def _gen_yang(self, proto): try: save_file(os.path.join(TEMP_PATH, TEMP_INPUT_PROTO_FILE), proto) cmd = proto_to_yang_cmd.format(TEMP_PATH, TEMP_PATH, TEMP_PROTO_PATH ) print 'running command: {}'.format(cmd) response, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) return load_file(TEMP_YANG_PATH) except Exception as e: print('Failure to generate yang file {}'.format(e))
def add_device(self): print "Adding device" cmd = command_defs['add_olt'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) device = json.loads(out) print "Added device - id:{}, type:{}".format(device['id'], device['type']) time.sleep(5) return device
def start_voltha(self): t0 = time() self.pt("Starting voltha ...") cmd = command_defs['docker_compose_start_voltha'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) self.pt("Waiting for voltha to be ready ...") self.wait_till('voltha service HEALTHY', lambda: verify_all_services_healthy( LOCAL_CONSUL, service_name='vcore-grpc') == True, timeout=30) self.pt("Voltha is ready ...")
def get_onos_devices(self): print "Getting ONOS devices ..." cmd = command_defs['get_onos_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) if out is not None: onos_devices = json.loads(out) print "Got ONOS devices" else: onos_devices = None print "Unable to get ONOS devices" return onos_devices
def start_all_containers(self): t0 = time() # start all the containers self.pt("Starting all containers ...") cmd = command_defs['docker_compose_start_all'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) self.pt("Waiting for voltha container to be ready ...") self.wait_till('voltha services HEALTHY', lambda: verify_all_services_healthy( LOCAL_CONSUL, service_name='vcore-grpc') == True, timeout=10) sleep(10)
def start_all_containers(self): t0 = time() # start all the containers self.pt("Starting all containers ...") cmd = command_defs['docker_compose_start_all'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) self.pt("Waiting for voltha container to be ready ...") self.wait_till('voltha services HEALTHY', lambda: verify_all_services_healthy( LOCAL_CONSUL, service_name='voltha-grpc') == True, timeout=10) sleep(10)
def test_03_mix_simple_types(self): print "Test_03_mix_simple_types_Start:------------------" t0 = time.time() # input file: /voltha/tests/utests/netconf/yang/mix_simple_types.yang expected_response = """ syntax = "proto3"; package mix_simple_types; message user { string name = 1 ; string full_name = 2 ; string class = 3 ; } message int_container { int32 eight = 1 ; int32 nine = 2 ; int32 ten = 3 ; } message container1 { bool a = 1 ; Any b = 2 ; string mleaf = 3 ; repeated string mleaf_list = 4 ; message inner_container { string mleaf1 = 1 ; string mleaf2 = 2 ; } } """ try: cmd = pyang_cmd.format('mix_simple_types.yang') print 'running command: {}'.format(cmd) response, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) self._compare_file(response, expected_response) finally: print "Test_03_mix_simple_types_End:------------------ took {} " \ "secs\n\n".format(time.time() - t0)
def test_05_basic_rpc(self): print "Test_05_basic_rpc_Start:------------------" t0 = time.time() # input file: /voltha/tests/utests/netconf/yang/basic-rpc.yang expected_response = """ syntax = "proto3"; package basic_rpc; message my_id { uint32 my_id = 1 ; } message my_name { string my_name = 2 ; } message my_status { bool my_status = 3 ; } message my_input { string my_input = 4 ; } message my_output { string my_output = 5 ; } service basic_rpc { rpc do_something(my_input) returns(my_output) {} } """ try: cmd = pyang_cmd.format('basic-rpc.yang') print 'running command: {}'.format(cmd) response, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) self._compare_file(response, expected_response) finally: print "Test_05_basic_rpc_End:------------------ took {} " \ "secs\n\n".format(time.time() - t0)
def start_all_containers(self): t0 = time() # start all the containers self.pt("Starting all containers ...") cmd = command_defs['docker_compose_start_all'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) self.pt("Waiting for voltha and chameleon containers to be ready ...") self.wait_till('voltha services HEALTHY', lambda: verify_all_services_healthy( LOCAL_CONSUL, service_name='voltha-grpc') == True, timeout=10) self.wait_till('chameleon services HEALTHY', lambda: verify_all_services_healthy( LOCAL_CONSUL,service_name='chameleon-rest') == True, timeout=10) # Chameleon takes some time to compile the protos and make them # available. So let's wait 10 seconds sleep(10)
def test_ofagent_controller_failover(self): olt_device = self.add_device() print "Output of ADD OLT is {} {} {}".format(olt_device, type(olt_device), olt_device['id']) sleep(5) self.enable_device(olt_device['id']) print "Waiting for OLT device to be activated ..." sleep(80) cmd = command_defs['onos1_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos1_devices = json.loads(out) onos1_role = onos1_devices['devices'][0]['role'] print "Role of ONOS1 is {}".format(onos1_role) cmd = command_defs['onos2_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos2_devices = json.loads(out) onos2_role = onos2_devices['devices'][0]['role'] print "Role of ONOS2 is {}".format(onos2_role) cmd = command_defs['onos3_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos3_devices = json.loads(out) onos3_role = onos3_devices['devices'][0]['role'] print "Role of ONOS3 is {}".format(onos3_role) if onos1_role == "MASTER": cmd = command_defs['docker_stop']+ ' onos1' out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Waiting for ONOS to Elect New Master" sleep(20) cmd = command_defs['onos2_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos2_devices = json.loads(out) onos2_role = onos2_devices['devices'][0]['role'] print "Role of ONOS2 is {}".format(onos2_role) cmd = command_defs['onos3_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos3_devices = json.loads(out) onos3_role = onos3_devices['devices'][0]['role'] print "Role of ONOS3 is {}".format(onos3_role) assert (onos3_role == "MASTER" or onos2_role == "MASTER"), "Exception,New Master Election Failed" elif onos2_role == "MASTER": cmd = command_defs['docker_stop']+ ' onos2' out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Waiting for ONOS to Elect New Master" sleep(20) cmd = command_defs['onos1_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos1_devices = json.loads(out) onos1_role = onos1_devices['devices'][0]['role'] print "Role of ONOS1 is {}".format(onos1_role) cmd = command_defs['onos3_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos3_devices = json.loads(out) onos3_role = onos3_devices['devices'][0]['role'] print "Role of ONOS3 is {}".format(onos3_role) assert (onos3_role == "MASTER" or onos1_role == "MASTER"), "Exception,New Master Election Failed" elif onos3_role == "MASTER": cmd = command_defs['docker_stop']+ ' onos3' out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Waiting for ONOS to Elect New Master" sleep(20) cmd = command_defs['onos1_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos1_devices = json.loads(out) onos1_role = onos1_devices['devices'][0]['role'] print "Role of ONOS1 is {}".format(onos1_role) cmd = command_defs['onos2_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos2_devices = json.loads(out) onos2_role = onos2_devices['devices'][0]['role'] print "Role of ONOS2 is {}".format(onos2_role) assert (onos1_role == "MASTER" or onos2_role == "MASTER"), "Exception,New Master Election Failed"
def _scale_voltha(self, scale=2): self.pt("Scaling voltha ...") cmd = command_defs['docker_compose_scale_voltha'] + str(scale) out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0)
def test_ofagent_controller_failover(self): olt_device = self.add_device() print "Output of ADD OLT is {} {} {}".format(olt_device, type(olt_device), olt_device['id']) sleep(5) self.enable_device(olt_device['id']) print "Waiting for OLT device to be activated ..." sleep(80) cmd = command_defs['onos1_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos1_devices = json.loads(out) onos1_role = onos1_devices['devices'][0]['role'] print "Role of ONOS1 is {}".format(onos1_role) cmd = command_defs['onos2_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos2_devices = json.loads(out) onos2_role = onos2_devices['devices'][0]['role'] print "Role of ONOS2 is {}".format(onos2_role) cmd = command_defs['onos3_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos3_devices = json.loads(out) onos3_role = onos3_devices['devices'][0]['role'] print "Role of ONOS3 is {}".format(onos3_role) if onos1_role == "MASTER": cmd = command_defs['docker_stop'] + ' onos1' out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Waiting for ONOS to Elect New Master" sleep(20) cmd = command_defs['onos2_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos2_devices = json.loads(out) onos2_role = onos2_devices['devices'][0]['role'] print "Role of ONOS2 is {}".format(onos2_role) cmd = command_defs['onos3_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos3_devices = json.loads(out) onos3_role = onos3_devices['devices'][0]['role'] print "Role of ONOS3 is {}".format(onos3_role) assert (onos3_role == "MASTER" or onos2_role == "MASTER"), "Exception,New Master Election Failed" elif onos2_role == "MASTER": cmd = command_defs['docker_stop'] + ' onos2' out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Waiting for ONOS to Elect New Master" sleep(20) cmd = command_defs['onos1_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos1_devices = json.loads(out) onos1_role = onos1_devices['devices'][0]['role'] print "Role of ONOS1 is {}".format(onos1_role) cmd = command_defs['onos3_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos3_devices = json.loads(out) onos3_role = onos3_devices['devices'][0]['role'] print "Role of ONOS3 is {}".format(onos3_role) assert (onos3_role == "MASTER" or onos1_role == "MASTER"), "Exception,New Master Election Failed" elif onos3_role == "MASTER": cmd = command_defs['docker_stop'] + ' onos3' out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) print "Waiting for ONOS to Elect New Master" sleep(20) cmd = command_defs['onos1_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos1_devices = json.loads(out) onos1_role = onos1_devices['devices'][0]['role'] print "Role of ONOS1 is {}".format(onos1_role) cmd = command_defs['onos2_devices'] out, err, rc = run_command_to_completion_with_raw_stdout(cmd) self.assertEqual(rc, 0) onos2_devices = json.loads(out) onos2_role = onos2_devices['devices'][0]['role'] print "Role of ONOS2 is {}".format(onos2_role) assert (onos1_role == "MASTER" or onos2_role == "MASTER"), "Exception,New Master Election Failed"