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 client_auth(dut, **kwargs): """ To enable disable REST client auth. Author: Prudvi Mangadu ([email protected]) :param dut: :param kwargs: :return: """ st.log("Configuring REST authentication.") docer_name = "mgmt-framework" show_command = [] if 'auth_type' in kwargs: show_command.append('sonic-cfggen -d -v "REST_SERVER"') if kwargs.get('auth_type'): command = 'redis-cli -n 4 hmset "REST_SERVER|default" client_auth "{}"'.format( kwargs.get('auth_type')) else: command = 'redis-cli -n 4 hdel "REST_SERVER|default" client_auth' st.config(dut, command) if 'ca_crt' in kwargs: show_command.append('redis-cli -n 4 hgetall "DEVICE_METADATA|x509"') if kwargs.get('ca_crt'): command = 'redis-cli -n 4 hmset "DEVICE_METADATA|x509" ca_crt {}'.format( kwargs.get('ca_crt')) else: command = 'redis-cli -n 4 hdel "DEVICE_METADATA|x509" ca_crt' st.config(dut, command) service_operations_by_systemctl(dut, docer_name, 'stop') service_operations_by_systemctl(dut, docer_name, 'start') st.config(dut, show_command) return True
def dhcp_server_config(): ''' 1. Install dhcp package 2. Update dhcp files - dhcpd6.conf dhcpd.conf isc-dhcp-server 3. Add static routes 4.Restart dhcp process ''' hdrMsg("Installing and configuring the dhcp server on dut1") dut = data.dut1 copy_files_to_dut(st.get_mgmt_ip(dut)) # st.config(dut,'sudo mv /tmp/'+data.dhcp_files[0]+' /etc/default/'+server_filename,skip_error_check=True) # st.config(dut,'sudo mv /tmp/'+data.dhcp_files[1]+' /etc/dhcp/',skip_error_check=True) # st.config(dut,'sudo mv /tmp/'+data.dhcp_files[2]+' /etc/dhcp/',skip_error_check=True) basic_api.move_file_to_local_path(dut, '/tmp/' + data.dhcp_files[0], '/etc/default/' + server_filename, sudo=True, skip_error_check=True) basic_api.move_file_to_local_path(dut, '/tmp/' + data.dhcp_files[1], '/etc/dhcp/', sudo=True, skip_error_check=True) basic_api.move_file_to_local_path(dut, '/tmp/' + data.dhcp_files[2], '/etc/dhcp/', sudo=True, skip_error_check=True) for ip in route_list: ip_api.create_static_route(dut, next_hop=dut3_loopback_ip_list[0], static_ip=ip) basic_api.deploy_package(dut, mode='update') basic_api.deploy_package(dut, options='-o Dpkg::Options::=\"--force-confold\"', packane_name='isc-dhcp-server', mode='install', skip_verify_package=True) #st.config(dut, "systemctl restart isc-dhcp-server") st.wait(2) ps_aux = basic_api.get_ps_aux(data.dut1, "dhcpd") if len(ps_aux) > 1: hdrMsg("dhcp server is up and running in dut1") return True #st.config(dut, "systemctl restart isc-dhcp-server") basic_api.service_operations_by_systemctl(dut, operation='restart', service='isc-dhcp-server') ps_aux = basic_api.get_ps_aux(data.dut1, "dhcpd") st.wait(2) if len(ps_aux) < 1: hdrMsg("dhcp server is not up and running in dut1") return False return True
def dhcp_server_unconfig(): dut = data.dut1 hdrMsg("Stoping the dhcp server on dut1") #st.config(dut, "systemctl stop isc-dhcp-server") basic_api.service_operations_by_systemctl(dut, operation='stop', service='isc-dhcp-server') for ip in route_list: ip_api.delete_static_route(dut, next_hop=dut3_loopback_ip_list[0], static_ip=ip)
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 client_auth(dut, **kwargs): """ To enable disable gNMI client auth. Author: Prudvi Mangadu ([email protected]) :param dut: :param auth_type: :return: """ st.log("Configuring gNMI authentication.") docer_name = "TELEMETRY" docker_name = "telemetry" command = 'redis-cli -n 4 hmset "TELEMETRY|gnmi" client_auth' if 'auth_type' in kwargs: if kwargs.get('auth_type'): command = 'redis-cli -n 4 hmset "TELEMETRY|gnmi" client_auth "{}"'.format( kwargs.get('auth_type')) else: command = 'redis-cli -n 4 hdel "TELEMETRY|gnmi" client_auth' st.config(dut, command) if 'server_key' in kwargs: if kwargs.get('server_key'): command = 'redis-cli -n 4 hmset "DEVICE_METADATA|x509" server_key "{}"'.format( kwargs.get('server_key')) st.config(dut, command) if 'server_crt' in kwargs: if kwargs.get('server_crt'): command = 'redis-cli -n 4 hmset "DEVICE_METADATA|x509" server_crt "{}"'.format( kwargs.get('server_crt')) st.config(dut, command) if 'ca_crt' in kwargs: if kwargs.get('ca_crt'): command = 'redis-cli -n 4 hmset "DEVICE_METADATA|x509" ca_crt "{}"'.format( kwargs.get('ca_crt')) else: command = 'redis-cli -n 4 hdel "DEVICE_METADATA|x509" ca_crt' st.config(dut, command) service_operations_by_systemctl(dut, docker_name, 'stop') service_operations_by_systemctl(dut, docker_name, 'start') command = 'sonic-cfggen -d -v "TELEMETRY"' st.config(dut, command) return True
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 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")