def config_pddf_mode(dut, file_path="/usr/local/bin/pddf_util.py", module_name="switch-pddf", iteration=150, delay=2): """ API to enable / disable PDDF on the switch Author: Chaitanya Vella ([email protected]) :param dut: :param file_path: :param module_name: :param iteration: :param delay: :return: """ command = "{} {}".format(file_path, module_name) output = st.config(dut, command) st.log("OUTPUT : {}".format(output)) if module_name == "switch-pddf": if 'REBOOT IS REQUIRED IMMEDIATELY' in output: st.reboot(dut, skip_fallback=True) if not poll_for_system_status( dut, iteration=iteration, delay=delay): st.log("System status is not up ...") return False if not is_service_active(dut): st.log("PDDF service is not active ...") return False else: if is_service_active(dut): st.log("PDDF service is still active ...") return False return True
def test_ft_lldp_docker_restart(): """ Author : Karthikeya Kumar CH<*****@*****.**> Verify the LLDP functionality after docker restart. Reference Test Bed : D1 <--2--> D2 """ st.log("Checking the LLDP functionality with docker restart") service_name = "lldp" basic_obj.service_operations_by_systemctl(vars.D1, service_name, 'stop') basic_obj.service_operations_by_systemctl(vars.D1, service_name, 'restart') if not basic_obj.poll_for_system_status(vars.D1, service_name, 30, 1): st.report_fail("service_not_running", service_name) if not basic_obj.verify_service_status(vars.D1, service_name): st.report_fail("lldp_service_not_up") if not intf_obj.poll_for_interfaces(vars.D1, iteration_count=30, delay=1): st.report_fail("interfaces_not_up_after_poll") if not lldp_obj.poll_lldp_neighbors( vars.D1, iteration_count=30, delay=1, interface=vars.D1D2P1): st.report_fail("lldp_neighbors_info_not_found_after_poll") lldp_info = lldp_obj.get_lldp_neighbors(vars.D1, interface=vars.D1D2P1) if not lldp_info: st.error("No lldp entries are available") st.report_fail("operation_failed") lldp_value_dut1 = lldp_info[0] lldp_output_dut1 = lldp_value_dut1['chassis_name'] hostname_cli_output = basic_obj.get_hostname(vars.D2) if lldp_output_dut1 != hostname_cli_output: st.report_fail("lldp_cli_not_matching") st.log("LLDP and CLI output values are : LLDP:{} , CLI:{} ".format( lldp_output_dut1, hostname_cli_output)) st.report_pass("test_case_passed")
def test_dhcp_relay_warm_reboot(): ################################################# # # Objective - Configure DHCP relay and verify if the configuration is retained after warm reboot. # ################################################# data.platform = basic_obj.get_hwsku(vars.D2) data.constants = st.get_datastore(vars.D2, "constants", 'default') st.log("OUTPUT:{}".format(data.constants)) if not data.platform.lower( ) in data.constants['WARM_REBOOT_SUPPORTED_PLATFORMS']: st.report_fail('test_case_unsupported') st.log("Performing Config save") rb_obj.config_save(vars.D2) st.log("Performing warm Reboot") st.reboot(vars.D2, "warm") if not basic_obj.poll_for_system_status(vars.D2, 'dhcp_relay.service', 120, 1): st.report_fail("service_not_running", "dhcp-relay") if not st.poll_wait(basic_obj.verify_service_status, 60, vars.D2, "dhcp_relay"): st.log("DHCP relay service not running") st.log("Verifying DHCP Helper configuration post reboot") check_dhcp_relay_config() dhcp_relay_obj.dhcp_client_start(vars.D3, vars.D3D2P1) if ip_obj.verify_interface_ip_address(vars.D3, vars.D3D2P1, data.pool_ip_address, family="ipv4", vrfname=''): st.report_fail("IP_address_assignment_failed", vars.D3) st.log( "Successfully verified DHCP Helper configuration is retained after warm reboot" ) st.report_pass("test_case_passed")
def test_ft_netinstall_warm_reboot(): """ Author : Pradeep Bathula([email protected]) Test function to verify system status after performing netinstall followed by ZTP disable and Warm reboot :return: """ st.log("performing warm-reboot") st.reboot(vars.D1, 'warm') start_time = int(time.time()) while True: current_time = int(time.time()) if not basic_obj.poll_for_system_status(vars.D1, iteration=1): st.reboot(vars.D1) st.report_fail("system_not_ready") if (current_time - start_time) > 300: break st.report_pass("test_case_passed")
def test_ft_pmon_docker_restart(): """ Author : Karthikeya Kumar CH<*****@*****.**> Verify that the platform monitoring(pmon) works fine after docker restart Reference Test Bed : D1 --- Mgmt Network """ vars = st.get_testbed_vars() service_name = "pmon" basic_obj.service_operations_by_systemctl(vars.D1, service_name, 'stop') basic_obj.service_operations_by_systemctl(vars.D1, service_name, 'restart') if not basic_obj.poll_for_system_status(vars.D1, service_name, 30, 1): st.report_fail("service_not_running", service_name) if not basic_obj.verify_service_status(vars.D1, service_name): st.report_fail("pmon_service_not_up") pmon_check = basic_obj.show_version(vars.D1) if not pmon_check: st.report_fail("pmon_show_command_fail") st.report_pass("test_case_passed")
def test_ft_snmp_docker_restart(): """ Author : Karthikeya Kumar CH<*****@*****.**> Verify that the sysName MIB object functions properly after docker restart Reference Test Bed : D1--- Mgmt Network """ basic_obj.service_operations_by_systemctl(vars.D1, 'snmp', 'restart') if not basic_obj.poll_for_system_status(vars.D1, 'snmp', 30, 1): st.report_fail("service_not_running".format('snmp')) if not basic_obj.verify_service_status(vars.D1, 'snmp'): st.report_fail("snmp_service_not_up") hostname = basic_obj.get_hostname(vars.D1) get_snmp_output = snmp_obj.get_snmp_operation( ipaddress=ipaddress, oid=data.oid_sysName, community_name=data.ro_community) st.log("hostname Device('{}') and SNMP('{}')".format( hostname, get_snmp_output[0])) if not get_snmp_output[0] == hostname: st.report_fail("sysName_verification_fail_after_docker_restart") st.report_pass("test_case_passed")
def docker_restart_test(): st.log("Performing Config save") rb_obj.config_save(vars.D2) #check the docker part st.log("DHCP relay docker restart") basic_obj.service_operations_by_systemctl(vars.D2, "dhcp_relay.service", "restart") st.log("Wait for DHCP relay docker restart") if not basic_obj.poll_for_system_status(vars.D2, 'dhcp_relay.service', 120, 3): st.report_fail("service_not_running", "dhcp-relay") if not st.poll_wait(basic_obj.verify_service_status, 60, vars.D2, "dhcp_relay"): st.report_fail("docker_restart_failed") st.log("Verifying DHCP Helper configuration post Docker Restart") check_dhcp_relay_config() dhcp_relay_obj.dhcp_client_start(vars.D3, vars.D3D2P1) if not poll_wait(verify_dhcp_client, 60, vars.D3, vars.D3D2P1): dhcp_relay_debug(vars.D2, interface="Vlan{}".format(data.vlan)) st.report_fail("dhcp_relay_functionality_tc_status", "IPv4", "failed", "vlan") st.report_pass("test_case_passed")
def pre_config_ztp(): global vars global ssh_conn_obj_oob_v6 global ssh_conn_obj global ssh_conn_obj_oob_v4 global ssh_conn_obj_inb_v4 global ssh_conn_obj_inb_v6 vars = st.get_testbed_vars() # DHCPV6 out of band params ztp_params.dhcp6.ip = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "ip") ztp_params.dhcp6.username = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "username") ztp_params.dhcp6.password = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "password") ztp_params.dhcp6.oob_port = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "interface") ztp_params.dhcp6.oob_static_ip = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "static_ip") # DHCPV4 out of band params ztp_params.dhcp.ip = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "ip") ztp_params.dhcp.username = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "username") ztp_params.dhcp.password = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "password") ztp_params.oob_port = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "interface") ztp_params.static_ip = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "static_ip") #DHCPV6 in band params ztp_params.dhcp6.inband_ip = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "ip") ztp_params.dhcp6.inband_username = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "username") ztp_params.dhcp6.inband_password = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "password") ztp_params.dhcp6.inband_static_ip = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "static_ip") ztp_params.dhcp6.inband_port = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "interface") # DHCPV4 in band params ztp_params.dhcp.inband_ip = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "inband", "ip") ztp_params.dhcp.inband_username = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "inband", "username") ztp_params.dhcp.inband_password = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "inband", "password") ztp_params.dhcp.inband_static_ip = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "inband", "static_ip") ztp_params.inband_port = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcp", "inband", "interface") ztp_params.dhcp6.oob_config_file = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "config_file") ztp_params.dhcp6.inband_config_file = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "config_file") ztp_params.config_path = utils_obj.ensure_service_params( vars.D1, "ztp", "config_path") ztp_params.dhcp6.oob_home_path = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "home_path") ztp_params.dhcp6.inband_home_path = utils_obj.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "home_path") ztp_params.port = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "port") ztp_params.dut_path = utils_obj.ensure_service_params( vars.D1, "ztp", "dut_path") ztp_params.ztp_cfg_file_name = utils_obj.ensure_service_params( vars.D1, "ztp", "ztp_cfg_file_name") ztp_params.provision_script_path = utils_obj.ensure_service_params( vars.D1, "ztp", "provision_script_path") st.log("Clearing V4/V6 lease database from DUT ...") basic_obj.delete_directory_contents(vars.D1, config_params.lease_db_path) st.log("####### Connecting to DHCPV6 server -- OUT OF BAND ...###########") ssh_conn_obj_oob_v6 = con_obj.connect_to_device(ztp_params.dhcp6.ip, ztp_params.dhcp6.username, ztp_params.dhcp6.password) if not ssh_conn_obj_oob_v6: st.error( "SSH connection object not found for DHCPV6 server OUT OF BAND.") if network_flag != "inband": reset_module_config() st.report_env_fail("ssh_connection_failed", ztp_params.dhcp6.ip) st.log( "############Connecting to DHCPV4 server -- OUT OF BAND ...#############" ) ssh_conn_obj_oob_v4 = con_obj.connect_to_device(ztp_params.dhcp.ip, ztp_params.dhcp.username, ztp_params.dhcp.password) if not ssh_conn_obj_oob_v4: st.error( "SSH connection object not found for DHCPV4 server OUT OF BAND.") # st.report_env_fail("ssh_connection_failed", ztp_params.dhcp6.ip) st.log( "###########Connecting to DHCPV4 server -- IN BAND ...##############") ssh_conn_obj_inb_v4 = con_obj.connect_to_device( ztp_params.dhcp.inband_ip, ztp_params.dhcp.inband_username, ztp_params.dhcp.inband_password) if not ssh_conn_obj_inb_v4: st.error( "SSH connection object not found for DHCPV4 server OUT OF BAND.") # st.report_env_fail("ssh_connection_failed", ztp_params.dhcp6.ip) ssh_conn_obj_inb_v6 = con_obj.connect_to_device( ztp_params.dhcp6.inband_ip, ztp_params.dhcp6.inband_username, ztp_params.dhcp6.inband_password) if not ssh_conn_obj_inb_v6: st.error( "SSH connection object not found for DHCPV4 server OUT OF BAND.") if network_flag == "inband": reset_module_config() st.report_env_fail("ssh_connection_failed", ztp_params.dhcp6.inband_ip) st.log( "###########Stopping V4/V6 services to avoid the DHCP option conflict .. ###########" ) v4_connection_objs = [ssh_conn_obj_oob_v4, ssh_conn_obj_inb_v4] for connection_obj in v4_connection_objs: if connection_obj: basic_obj.service_operations(connection_obj, config_params.dhcp_service_name, "stop", "server") if ztp_obj.verify_dhcpd_service_status(connection_obj, config_params.dhcpd_pid): st.log("{} service is running which is not expected".format( config_params.dhcp_service_name)) reset_module_config() st.report_fail("service_running_not_expected", config_params.dhcp_service_name) st.log("Restarting V6 services on required server .. ") if network_flag != "inband": ssh_conn_obj = ssh_conn_obj_oob_v6 st.log("Using OUT OF BAND V6 ssh object ... ") if ssh_conn_obj_inb_v6: basic_obj.service_operations(ssh_conn_obj_inb_v6, config_params.dhcp6_service_name, "stop", "server") if ztp_obj.verify_dhcpd_service_status(ssh_conn_obj_inb_v6, config_params.dhcpd6_pid): st.log("{} service is running which is not expected".format( config_params.dhcp6_service_name)) reset_module_config() st.report_fail("service_running_not_expected", config_params.dhcp6_service_name) else: st.log("SSH object for INB V6 server is not found ...") else: st.log("Using INBAND V6 ssh object ... ") ssh_conn_obj = ssh_conn_obj_inb_v6 if ssh_conn_obj_oob_v6: basic_obj.service_operations(ssh_conn_obj_oob_v6, config_params.dhcp6_service_name, "stop", "server") if ztp_obj.verify_dhcpd_service_status(ssh_conn_obj_oob_v6, config_params.dhcpd6_pid): st.log("{} service is running which is not expected".format( config_params.dhcp6_service_name)) reset_module_config() st.report_fail("service_running_not_expected", config_params.dhcp6_service_name) else: st.log("SSH object for OOB V6 server is not found ...") basic_obj.service_operations(ssh_conn_obj, config_params.dhcp6_service_name, "restart", "server") if not ztp_obj.verify_dhcpd_service_status(ssh_conn_obj, config_params.dhcpd6_pid): st.log("{} service is not running ".format( config_params.dhcp6_service_name)) reset_module_config() st.report_fail("service_running_not_expected", config_params.dhcp6_service_name) global dhcp6_port global dhcp6_static_ip global dhcp6_home_path global dhcp6_config_file if network_flag != "inband": dhcp6_port = ztp_params.dhcp6.oob_port dhcp6_static_ip = ztp_params.dhcp6.oob_static_ip dhcp6_home_path = ztp_params.dhcp6.oob_home_path dhcp6_config_file = ztp_params.dhcp6.oob_config_file ztp_params.home_path = ztp_params.dhcp6.oob_home_path else: dhcp6_port = ztp_params.dhcp6.inband_port dhcp6_static_ip = ztp_params.dhcp6.inband_static_ip dhcp6_home_path = ztp_params.dhcp6.inband_home_path dhcp6_config_file = ztp_params.dhcp6.inband_config_file ztp_params.home_path = ztp_params.dhcp6.inband_home_path basic_obj.ifconfig_operation(vars.D1, ztp_params.dhcp6.oob_port, "down") basic_obj.poll_for_system_status(vars.D1) ztp_cfg = { "admin-mode": True, "restart-ztp-interval": 30, "feat-console-logging": feat_logging_console } ztp_obj.config_ztp_backdoor_options(vars.D1, ztp_cfg)
def config_and_verify_dhcp_option(ssh_conn_obj, dut, ztp_params, data, expect_reboot=False, reboot_on_success=list(), cli_type=""): """ Common function to configure DHCP option along with status / logs verification Author: Chaitanya Vella ([email protected]) :param ssh_conn_obj: :param dut: :param ztp_params: :param data: :return: """ cli_type = st.get_ui_type(dut,cli_type=cli_type) cli_type = "klish" if cli_type in ["rest-put", "rest-patch"] else cli_type retry_count = data.retry_count if "retry_count" in data and data.retry_count else 0 iteration = data.iteration if "iteration" in data and data.iteration else 300 delay = data.delay if "delay" in data and data.delay else 3 if "func_name" in data: syslog_file_names = ["syslog_1_{}".format(data.func_name), "syslog_{}".format(data.func_name)] # basic_obj.copy_config_db_to_temp(dut, data.config_db_path, data.config_db_temp) if "config_file_type" in data and data.config_file_type == "text": file_path = "/tmp/file_temp.json" basic_obj.write_to_file(ssh_conn_obj, data.json_content, file_path, device="server") elif "config_file_type" in data and data.config_file_type == "EoL": file_path = "" else: file_path = basic_obj.write_to_json_file(data.json_content) if file_path: destination_path = "{}{}/{}".format(ztp_params.home_path, ztp_params.config_path, data.config_file) basic_obj.copy_file_from_client_to_server(ssh_conn_obj, src_path=file_path, dst_path=destination_path) if "config_db_location" in data and data.config_db_location == "json": st.download_file_from_dut(dut, data.config_db_temp, file_path) destination_path = "{}{}/{}".format(ztp_params.home_path, ztp_params.config_path, data.config_db_file_name) basic_obj.copy_file_from_client_to_server(ssh_conn_obj, src_path=file_path, dst_path=destination_path) if "scenario" in data and data.scenario == "invalid-json": st.log("Writing invalid content to make invalid json ...") basic_obj.write_to_file_to_line(ssh_conn_obj, ",", 5, destination_path, "server") if data.option_type == "67": st.log("Creating {} file on DHCP server ...".format(data.config_file)) data.search_pattern = r'\s*option\s+bootfile-name\s*\S*\s*"\S+";' data.option_string = "option bootfile-name" if data.type == "http": data.option_url = "http://{}{}/{}".format(data.static_ip, data.config_path, data.config_file) elif data.type == "tftp": data.option_url = "tftp://{}/{}/{}".format(data.static_ip, data.config_path, data.config_file) elif data.type == "ftp": data.option_url = "ftp://{}/{}/{}".format(data.static_ip, data.config_path, data.config_file) write_option_to_dhcp_server(ssh_conn_obj, data) basic_obj.service_operations(ssh_conn_obj, data.dhcp_service_name, data.action, data.device) if not verify_dhcpd_service_status(ssh_conn_obj, data.dhcpd_pid): st.log("{} service not running".format(data.dhcp_service_name)) st.report_fail("service_not_running", data.dhcp_service_name) # write_option_67_to_dhcp_server(ssh_conn_obj, data) data.device_action = "reboot" if cli_type == "klish" else data.device_action if data.device_action == "reboot": reboot_type = data.reboot_type if "reboot_type" in data and data.reboot_type else "normal" basic_obj.remove_file(dut, data.config_db_path) st.reboot(dut, reboot_type, skip_port_wait=True) st.wait_system_status(dut, 500) elif data.device_action == "run": ztp_operations(dut, data.device_action) if "band_type" in data and data.band_type=="inband": if not basic_obj.poll_for_system_status(dut): st.log("Sytem is not ready ..") st.report_env_fail("system_not_ready") if not basic_obj.check_interface_status(dut, ztp_params.oob_port,"up"): basic_obj.ifconfig_operation(dut, ztp_params.oob_port, "down") interface_status = basic_obj.check_interface_status(dut, ztp_params.inband_port, "up") if interface_status is not None: if not interface_status: intf_obj.interface_noshutdown(dut, ztp_params.inband_port, cli_type=cli_type) if "service" in data and data.service == "disable": basic_obj.service_operations_by_systemctl(dut, "ztp", "stop") if basic_obj.verify_service_status(dut, "ztp"): st.log("ZTP status is not stopped") st.report_fail("service_not_stopped", "ztp") basic_obj.service_operations_by_systemctl(dut, "ztp", "start") if not poll_ztp_status(dut, ["IN-PROGRESS", "Not Started", "SUCCESS"], cli_type=cli_type): st.report_fail("ztp_max_polling_interval") if "check" in data and data.check == "not": if verify_ztp_status(dut, retry_count, iteration, delay, cli_type=cli_type): if "logs_path" in data and "func_name" in data: capture_syslogs(dut, data.logs_path, syslog_file_names) st.log("ZTP status verification failed") st.report_fail("ztp_status_verification_failed") else: st.log("Iteration count {}".format(iteration)) st.log("REBOOT ON SUCCESS - {}".format(reboot_on_success)) if reboot_on_success: if "configdb-json" in reboot_on_success: st.wait_system_reboot(dut) st.wait_system_status(dut, 300) result = verify_ztp_status(dut, retry_count, iteration, delay, expect_reboot=expect_reboot, reboot_on_success=reboot_on_success, cli_type=cli_type) else: result = verify_ztp_status(dut, retry_count, iteration, delay, expect_reboot=expect_reboot, cli_type=cli_type) if not result: if "logs_path" in data and "func_name" in data: capture_syslogs(dut, data.logs_path, syslog_file_names) st.log("ZTP status verification failed") st.report_fail("ztp_status_verification_failed") if reboot_on_success: output = show_ztp_status(dut, cli_type=cli_type) if output["status"] != "SUCCESS": st.wait(300, "Waiting for device to reboot after success...") st.wait_system_status(dut, 300) # st.wait_system_reboot(dut) if not verify_ztp_status(dut, retry_count, iteration, delay, cli_type=cli_type): if "logs_path" in data and "func_name" in data: capture_syslogs(dut, data.logs_path, syslog_file_names) st.log("ZTP status verification failed") st.report_fail("ztp_status_verification_failed") st.banner(boot_up_obj.sonic_installer_list(dut)) verify_ztp_filename_logs(dut, data) if "ztp_log_string" in data and data.ztp_log_string: if not basic_obj.poll_for_error_logs(dut, data.ztp_log_path, data.ztp_log_string): st.log("ZTP log {} verification failed for message {}".format(data.ztp_log_path, data.ztp_log_string)) if not basic_obj.poll_for_error_logs(dut, data.ztp_log_path_1, data.ztp_log_string): st.log("ZTP log {} verification failed for message {}".format(data.ztp_log_path_1, data.ztp_log_string)) st.report_fail("ztp_log_verification_failed", data.ztp_log_path_1, data.ztp_log_string) if "result" in data and data.result == "pass": st.report_pass("test_case_passed")
def pre_config_ztp(): global vars global ssh_conn_obj global outofband_conn_obj global ssh_conn_obj_oob_v6 global ssh_conn_obj_inb_v6 vars = st.get_testbed_vars() # DHCPV4 out of band params ztp_params.dhcp.ip = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "outofband", "ip") ztp_params.dhcp.username = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "outofband", "username") ztp_params.dhcp.password = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "outofband", "password") ztp_params.oob_port = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "outofband", "interface") # DHCPV4 in band params ztp_params.dhcp.inband_ip = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "ip") ztp_params.dhcp.inband_username = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "username") ztp_params.dhcp.inband_password = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "password") ztp_params.dhcp.inband_config_file = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "config_file") ztp_params.dhcp.inband_static_ip = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "static_ip") ztp_params.inband_port = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "interface") ztp_params.config_path = utils_obj.ensure_service_params(vars.D1, "ztp", "config_path") ztp_params.firmware_path = utils_obj.ensure_service_params(vars.D1, "ztp", "firmware_path") ztp_params.home_path = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "home_path") ztp_params.port = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "port") ztp_params.build_file_name = utils_obj.ensure_service_params(vars.D1, "ztp", "build_file_name") ztp_params.uninstall_image = utils_obj.ensure_service_params(vars.D1, "ztp", "uninstall_image") ztp_params.dut_path = utils_obj.ensure_service_params(vars.D1, "ztp", "dut_path") ztp_params.ztp_cfg_file_name = utils_obj.ensure_service_params(vars.D1, "ztp", "ztp_cfg_file_name") ztp_params.provision_script_path = utils_obj.ensure_service_params(vars.D1, "ztp", "provision_script_path") ztp_params.docker_path = utils_obj.ensure_service_params(vars.D1, "ztp", "docker_path") ztp_params.docker_image = utils_obj.ensure_service_params(vars.D1, "ztp", "docker_image") ztp_params.docker_component_name = utils_obj.ensure_service_params(vars.D1, "ztp", "docker_component_name") ztp_params.inband_port = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "interface") ztp_params.minigraph_file = utils_obj.ensure_service_params(vars.D1, "ztp", "minigraph_file") ztp_params.xml_path = utils_obj.ensure_service_params(vars.D1, "ztp", "xml_path") # DHCPV6 out of band params ztp_params.dhcp6.ip = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "outofband", "ip") ztp_params.dhcp6.username = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "outofband", "username") ztp_params.dhcp6.password = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "outofband", "password") ztp_params.dhcp6.oob_port = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "outofband", "interface") ztp_params.dhcp6.oob_static_ip = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "outofband", "static_ip") # DHCPV6 IN band params ztp_params.dhcp6.inband_ip = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "inband", "ip") ztp_params.dhcp6.inband_username = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "inband", "username") ztp_params.dhcp6.inband_password = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "inband", "password") ztp_params.dhcp6.inband_static_ip = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "inband", "static_ip") ztp_params.dhcp6.inband_port = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "inband", "interface") ztp_params.dhcp.inband_v4_subnet = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "subnet") ztp_params.dhcp.oob_v4_subnet= utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "outofband", "subnet") ztp_params.dhcp6.inband_v6_subnet = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "inband", "subnet") ztp_params.dhcp6.oob_v6_subnet = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcpv6", "outofband", "subnet") ztp_params.dhcp.client_ip_inband = utils_obj.ensure_service_params(vars.D1, "ztp", "dhcp", "inband", "client_ip") ztp_params.breakout = utils_obj.ensure_service_params(vars.D1, "ztp", "breakout") ztp_params.cli_type = st.get_ui_type(vars.D1) st.log("Clearing V4/V6 lease database from DUT ...") basic_obj.delete_directory_contents(vars.D1, config_params.lease_db_path) st.log("################# Logging in to DHCPV4 server ---- IN BAND ...#################") ssh_conn_obj = con_obj.connect_to_device(ztp_params.dhcp.inband_ip, ztp_params.dhcp.inband_username, ztp_params.dhcp.inband_password) if not ssh_conn_obj: st.error("SSH connetion object not found for DHCPV4 server IN BAND.") reset_module_config() st.report_env_fail("ssh_connection_failed", ztp_params.dhcp.inband_ip) st.log("########Restarting DHCPV4 service##########") basic_obj.service_operations(ssh_conn_obj, config_params.dhcp_service_name, "restart", "server") st.log("########Verifying DHCPV4 service status##########") if not ztp_obj.verify_dhcpd_service_status(ssh_conn_obj, config_params.dhcpd_pid): st.log("{} service is not running ".format(config_params.dhcp_service_name)) reset_module_config() st.report_fail("service_running_not_expected", config_params.dhcp_service_name) st.log("################# Logging in to DHCPV4 server ---- OUT OF BAND ... #################") outofband_conn_obj = con_obj.connect_to_device(ztp_params.dhcp.ip, ztp_params.dhcp.username, ztp_params.dhcp.password) if not outofband_conn_obj: st.error("OUT OF BAND SSH connetion object not found.") else: basic_obj.service_operations(outofband_conn_obj, config_params.dhcp_service_name, "stop", "server") if ztp_obj.verify_dhcpd_service_status(outofband_conn_obj, config_params.dhcpd_pid): st.log("{} service is running which is not expected".format(config_params.dhcp_service_name)) reset_module_config() st.report_fail("service_running_not_expected", config_params.dhcp_service_name) # st.report_env_fail("ssh_connection_failed", ztp_params.dhcp.ip) st.log("################# Logging in to DHCPV6 server -- OUT OF BAND ... #################") ssh_conn_obj_oob_v6 = con_obj.connect_to_device(ztp_params.dhcp6.ip, ztp_params.dhcp6.username, ztp_params.dhcp6.password) if not ssh_conn_obj_oob_v6: st.error("SSH connection object not found for DHCPV6 server OUT OF BAND.") st.log("################# Logging in to DHCPV6 server ---- IN BAND ... ##################") ssh_conn_obj_inb_v6 = con_obj.connect_to_device(ztp_params.dhcp6.inband_ip, ztp_params.dhcp6.inband_username, ztp_params.dhcp6.inband_password) if not ssh_conn_obj_inb_v6: st.error("SSH connection object not found for DHCPV6 server IN BAND.") st.log("Stopping V4/V6 services to avoid the DHCP option conflict .. ") v6_connection_objs = [ssh_conn_obj_inb_v6, ssh_conn_obj_oob_v6] for connection_obj in v6_connection_objs: if connection_obj: basic_obj.service_operations(connection_obj, config_params.dhcp6_service_name, "stop", "server") if ztp_obj.verify_dhcpd_service_status(connection_obj, config_params.dhcpd6_pid): st.log("{} service is running which is not expected".format(config_params.dhcp6_service_name)) reset_module_config() st.report_fail("service_running_not_expected", config_params.dhcp6_service_name) basic_obj.poll_for_system_status(vars.D1) st.log("Shutting down the out of band interface ...") basic_obj.ifconfig_operation(vars.D1, ztp_params.oob_port, "down") ztp_cfg = {"admin-mode": True, "restart-ztp-interval": 30, "feat-console-logging": feat_logging_console} ztp_obj.config_ztp_backdoor_options(vars.D1, ztp_cfg)