def reset_module_config(): basic_obj.delete_directory_contents(vars.D1, config_params.ztp_run_path) st.log("Resetting all DHCP services as part of module unconfig...") connection_objs = [ssh_conn_obj_oob_v4, ssh_conn_obj_inb_v4] for connection_obj in connection_objs: if connection_obj: basic_obj.service_operations(connection_obj, config_params.dhcp_service_name, "start", "server") con_obj.ssh_disconnect(connection_obj) if network_flag == "inband": if ssh_conn_obj_inb_v6: basic_obj.service_operations(ssh_conn_obj_inb_v6, config_params.dhcp6_service_name, "start", "server") con_obj.ssh_disconnect(ssh_conn_obj_inb_v6) if ssh_conn_obj_oob_v6: con_obj.ssh_disconnect(ssh_conn_obj_oob_v6) else: if ssh_conn_obj_oob_v6: basic_obj.service_operations(ssh_conn_obj_oob_v6, config_params.dhcp6_service_name, "start", "server") con_obj.ssh_disconnect(ssh_conn_obj_oob_v6) if ssh_conn_obj_inb_v6: con_obj.ssh_disconnect(ssh_conn_obj_inb_v6) basic_obj.ifconfig_operation(vars.D1, ztp_params.dhcp6.oob_port, "up")
def dhcp_relay_module_config(request): initialize_variables() vars = st.ensure_min_topology("D1D2:1", "D2D3:2") bind_class_action_copp_policy(vars.D3, classifier='copp-system-dhcpl2', action_group='copp-system-dhcp') response = basic_obj.dhcp_server_config( vars.D1, dhcp_files_path=data.dhcp_files_path, server_port=vars.D1D2P1, server_ipv4=data.dhcp_server_ip, route_list=data.route_list, ipv4_relay_agent_ip=data.RA_ipaddress_1) if not response: st.report_fail("service_operation_status", "isc-dhcp-server", "installation", "failed") connected_port_ip_address_config() if not basic_obj.check_interface_status(vars.D2, data.dhcp_relay_params, "up"): basic_obj.ifconfig_operation(vars.D2, data.dhcp_relay_params, "up") if not ip_obj.ping(vars.D2, data.dhcp_server_ip): st.log( "Pinging to DHCP server failed from DUT, issue either with DUT or server" ) st.report_fail("ping_fail", data.dhcp_server_ip) basic_dhcp_relay_config_addition() yield response = basic_obj.dhcp_server_config( vars.D1, action="unconfig", dhcp_files_path=data.dhcp_files_path, server_port=vars.D1D2P1, server_ipv4=data.dhcp_server_ip, route_list=data.route_list, ipv4_relay_agent_ip=data.RA_ipaddress_1) if not response: st.report_fail("service_operation_status", "isc-dhcp-server", "uninstallation", "failed") dhcp_relay_obj.dhcp_relay_config_remove(vars.D2, vlan=data.vlan_int, IP=data.dhcp_server_ip) ip_obj.config_ip_addr_interface(vars.D2, data.dhcp_relay_params, data.RA_ipaddress_1, data.subnet, family=data.family, config='remove') ip_obj.clear_ip_configuration(st.get_dut_names()) ip_obj.clear_ip_configuration(st.get_dut_names(), 'ipv6') vlan_obj.clear_vlan_configuration(st.get_dut_names())
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 inband_ssh_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 = mutils.ensure_service_params(vars.D1, "ztp", "dhcp", "outofband", "ip") ztp_params.dhcp.username = mutils.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "username") ztp_params.dhcp.password = mutils.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "password") ztp_params.dhcp.config_file = mutils.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "config_file") ztp_params.dhcp.static_ip = mutils.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "static_ip") ztp_params.oob_port = mutils.ensure_service_params(vars.D1, "ztp", "dhcp", "outofband", "interface") # DHCPV4 in band params ztp_params.dhcp.inband_ip = mutils.ensure_service_params( vars.D1, "ztp", "dhcp", "inband", "ip") ztp_params.dhcp.inband_username = mutils.ensure_service_params( vars.D1, "ztp", "dhcp", "inband", "username") ztp_params.dhcp.inband_password = mutils.ensure_service_params( vars.D1, "ztp", "dhcp", "inband", "password") ztp_params.config_path = mutils.ensure_service_params( vars.D1, "ztp", "config_path") ztp_params.firmware_path = mutils.ensure_service_params( vars.D1, "ztp", "firmware_path") ztp_params.home_path = mutils.ensure_service_params( vars.D1, "ztp", "dhcp", "outofband", "home_path") ztp_params.build_file_name = mutils.ensure_service_params( vars.D1, "ztp", "build_file_name") ztp_params.uninstall_image = mutils.ensure_service_params( vars.D1, "ztp", "uninstall_image") ztp_params.dut_path = mutils.ensure_service_params(vars.D1, "ztp", "dut_path") ztp_params.ztp_cfg_file_name = mutils.ensure_service_params( vars.D1, "ztp", "ztp_cfg_file_name") ztp_params.provision_script_path = mutils.ensure_service_params( vars.D1, "ztp", "provision_script_path") ztp_params.docker_path = mutils.ensure_service_params( vars.D1, "ztp", "docker_path") ztp_params.docker_image = mutils.ensure_service_params( vars.D1, "ztp", "docker_image") ztp_params.docker_component_name = mutils.ensure_service_params( vars.D1, "ztp", "docker_component_name") ztp_params.inband_port = mutils.ensure_service_params( vars.D1, "ztp", "dhcp", "inband", "interface") ztp_params.minigraph_file = mutils.ensure_service_params( vars.D1, "ztp", "minigraph_file") ztp_params.xml_path = mutils.ensure_service_params(vars.D1, "ztp", "xml_path") # DHCPV6 out of band params ztp_params.dhcp6.ip = mutils.ensure_service_params(vars.D1, "ztp", "dhcpv6", "outofband", "ip") ztp_params.dhcp6.username = mutils.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "username") ztp_params.dhcp6.password = mutils.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "password") ztp_params.dhcp6.oob_port = mutils.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "interface") ztp_params.dhcp6.oob_static_ip = mutils.ensure_service_params( vars.D1, "ztp", "dhcpv6", "outofband", "static_ip") # DHCPV6 IN band params ztp_params.dhcp6.inband_ip = mutils.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "ip") ztp_params.dhcp6.inband_username = mutils.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "username") ztp_params.dhcp6.inband_password = mutils.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "password") ztp_params.dhcp6.inband_static_ip = mutils.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "static_ip") ztp_params.dhcp6.inband_port = mutils.ensure_service_params( vars.D1, "ztp", "dhcpv6", "inband", "interface") 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("####### Connecting to DHCPV4 server -- OUT OF BAND ...###########") ssh_conn_obj = con_obj.connect_to_device(ztp_params.dhcp.ip, ztp_params.dhcp.username, ztp_params.dhcp.password) if not ssh_conn_obj: st.error("SSH connetion object not found.") reset_module_config() st.report_env_fail("ssh_connection_failed", ztp_params.dhcp.ip) inband_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 inband_ssh_conn_obj: st.log("SSH connection to inband DHCP server is not successfull") # st.report_env_fail("ssh_connection_failed", ztp_params.dhcp.inband_ip) 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.") 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.") st.log("Stopping V4/V6 services on unwanted servers .. ") 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.service_operations(ssh_conn_obj, config_params.dhcp_service_name, "restart", "server") 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.wait(5) if not basic_obj.check_interface_status(vars.D1, ztp_params.oob_port, "up"): basic_obj.ifconfig_operation(vars.D1, ztp_params.oob_port, "up") intf_obj.enable_dhcp_on_interface(vars.D1, ztp_params.oob_port) if not ip_obj.ping(vars.D1, ztp_params.dhcp.static_ip): st.log( "Pinging to DHCP server failed from DUT, issue either with DUT or server" ) reset_module_config() st.report_fail("ping_fail", ztp_params.dhcp.static_ip) 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) lines = basic_obj.get_number_of_lines_in_file(ssh_conn_obj, ztp_params.dhcp.config_file) st.log("###########LINES -- {}##############".format(lines))
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)