def test_ft_port_fn_verify_shut_noshut(): if not ipapi.config_ip_addr_interface(vars.D1, interface_name=vars.D1D2P1, ip_address=intf_data.ip_address, subnet=intf_data.mask, family="ipv4", config='add'): st.report_fail("operation_failed") if not ipapi.config_ip_addr_interface(vars.D2, interface_name=vars.D2D1P1, ip_address=intf_data.ip_address1, subnet=intf_data.mask, family="ipv4", config='add'): st.report_fail("operation_failed") if not ipapi.ping(vars.D1, intf_data.ip_address1, family='ipv4', count=1): st.report_fail("ping_fail", intf_data.ip_address, intf_data.ip_address1) if not ipapi.ping(vars.D2, intf_data.ip_address, family='ipv4', count=1): st.report_fail("ping_fail", intf_data.ip_address1, intf_data.ip_address) for _ in range(3): intfapi.interface_shutdown(vars.D1, [vars.D1D2P1], skip_verify=True) intfapi.interface_noshutdown(vars.D1, [vars.D1D2P1], skip_verify=True) if not ipapi.ping(vars.D1, intf_data.ip_address1, family='ipv4', count=5): st.report_fail("ping_fail", intf_data.ip_address, intf_data.ip_address1) if not ipapi.ping(vars.D2, intf_data.ip_address, family='ipv4', count=1): st.report_fail("ping_fail", intf_data.ip_address1, intf_data.ip_address) rbapi.config_save_reload(vars.D1) if not ipapi.config_ip_addr_interface(vars.D1, interface_name=vars.D1D2P1, ip_address=intf_data.ip_address, subnet=intf_data.mask, family="ipv4", config='remove'): st.report_fail("operation_failed") if not ipapi.config_ip_addr_interface(vars.D2, interface_name=vars.D2D1P1, ip_address=intf_data.ip_address1, subnet=intf_data.mask, family="ipv4", config='remove'): st.report_fail("operation_failed") for _ in range(3): intfapi.interface_shutdown(vars.D1, [vars.D1D2P1], skip_verify=True) intfapi.interface_noshutdown(vars.D1, [vars.D1D2P1], skip_verify=True) if not st.poll_wait(intfapi.verify_interface_status, 15, vars.D1, vars.D1D2P1, "oper", "up"): st.report_fail("interface_is_down_on_dut", [vars.D1D2P1]) if not st.poll_wait(intfapi.verify_interface_status, 15, vars.D2, vars.D2D1P1, "oper", "up"): st.report_fail("interface_is_down_on_dut", [vars.D2D1P1]) 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 config_ntp_server_on_config_db_file(dut, iplist): """ Author: Anil Kumar Kacharla <*****@*****.**> """ st.log("Configuring NTP servers in Config_db file") ntp_obj.add_ntp_servers(dut, iplist=iplist) data.time_date = time.strftime('%a %B %d %H:%M:%S %Z %Y') ntp_obj.config_date(vars.D1, data.time_date) reboot_obj.config_save(vars.D1) st.log("verifying ntp service status") if ntp_obj.verify_ntp_service_status(vars.D1, 'active (running)'): st.log("ntpd is running") else: st.log("ntpd is exited and restarting ntp service") basic_obj.service_operations(vars.D1, data.ntp_service, action="restart") if not st.poll_wait(ntp_obj.verify_ntp_server_details, 30, dut, iplist, remote=iplist): st.log("ip not matching") st.report_fail("operation_failed") if not ntp_obj.verify_ntp_service_status(dut, 'active (running)', iteration=65, delay=2): st.log("ntp is exited") st.report_fail("operation_failed") st.log("Verify that NTP server connectivity from DUT") result = 0 for server_ip in data.servers: if not ping_obj.ping(vars.D1, server_ip): st.log("ping to ntp server is not successfull:{}".format(server_ip)) result += 1 if len(data.servers) == result: st.report_fail("None_of_the_configured_ntp_server_reachable") if not ntp_obj.verify_ntp_status(vars.D1, iteration=65, delay=2, server=data.servers): st.log("ntp syncronization failed") st.report_fail("operation_failed")
def port_fec_no_fec(vars, speed, fec=["none", "rs"]): """ Author : Nagarjuna Suravarapu <[email protected] By using this function we can pass parameters where we required (In my usage only fec parameter is changed ) and we can also reuse the code so that we can reduce the codes of line. """ if not isinstance(fec, list): st.log("FEC is not matching the criteria ..") st.report_fail("interface_is_down_on_dut", [vars.D1D2P1, vars.D1D2P2]) st.log("Observed that speed as {} on interface {}".format(speed, vars.D1D2P1)) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D1, [vars.D1D2P1, vars.D1D2P2], 'oper', 'up'): st.report_fail("interface_is_down_on_dut", [vars.D1D2P1, vars.D1D2P2]) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D2, [vars.D2D1P1, vars.D2D1P2], 'oper', 'up'): st.report_fail("interface_is_down_on_dut", [vars.D2D1P1, vars.D2D1P2]) if base_obj.get_hwsku(vars.D1).lower() in vars.constants[vars.D1]["TH3_PLATFORMS"]: if speed not in ['400G', '400000']: st.log("enabling the fec on Dut1") st.log(" if the fec on both duts interfaces mismatch then the ports should be down") intfapi.interface_properties_set(vars.D1, [vars.D1D2P1, vars.D1D2P2], "fec", fec[0], skip_error=False) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D1, [vars.D1D2P1, vars.D1D2P2], 'oper', 'down'): st.report_fail("interface_is_up_on_dut", [vars.D1D2P1, vars.D1D2P2]) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D2, [vars.D2D1P1, vars.D2D1P2], 'oper', 'down'): st.report_fail("interface_is_up_on_dut", [vars.D2D1P1, vars.D2D1P2]) st.log("disabling the fec on Dut1") intfapi.interface_properties_set(vars.D1, [vars.D1D2P1, vars.D1D2P2], "fec", fec[1], skip_error=False, no_form=True) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D1, [vars.D1D2P1, vars.D1D2P2], 'oper', 'up'): st.report_fail("interface_is_down_on_dut", [vars.D1D2P1, vars.D1D2P2]) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D2, [vars.D2D1P1, vars.D2D1P2], 'oper', 'up'): st.report_fail("interface_is_down_on_dut", [vars.D2D1P1, vars.D2D1P2]) else: st.log("enabling the fec on Dut1") st.log("if the fec on both duts interfaces mismatch then the ports should be down") intfapi.interface_properties_set(vars.D1, [vars.D1D2P1, vars.D1D2P2], "fec", fec[1], skip_error=False) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D1, [vars.D1D2P1, vars.D1D2P2], 'oper', 'down'): st.report_fail("interface_is_up_on_dut", [vars.D1D2P1, vars.D1D2P2]) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D2, [vars.D2D1P1, vars.D2D1P2], 'oper', 'down'): st.report_fail("interface_is_up_on_dut", [vars.D2D1P1, vars.D2D1P2]) st.log("disabling the fec on Dut1") intfapi.interface_properties_set(vars.D1, [vars.D1D2P1, vars.D1D2P2], "fec", fec[0], skip_error=False) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D1, [vars.D1D2P1, vars.D1D2P2], 'oper', 'up'): st.report_fail("interface_is_down_on_dut", [vars.D1D2P1, vars.D1D2P2]) if not st.poll_wait(intfapi.verify_interface_status, 20, vars.D2, [vars.D2D1P1, vars.D2D1P2], 'oper', 'up'): st.report_fail("interface_is_down_on_dut", [vars.D2D1P1, vars.D2D1P2])
def config_dut2_verify(): st.log("Enabling docker routing config mode in D2 ") bgp_obj.enable_docker_routing_config_mode(vars.D2) st.log("saving the BGP config in vtysh shell") st.log("config save in D2") reboot_obj.config_save(vars.D2, shell='vtysh') st.log("Performing reboot") st.reboot(vars.D2) st.wait(data.neighborship_wait, "wait for bgp neighborship") st.log("Verifying BGP is established after save and reload") if not st.poll_wait(bgp_obj.verify_bgp_neighborship, 60, vars.D2, family=data.af_ipv4, shell=data.shell_vtysh, neighbor=data.local_ip_addr, state='Established', asn=data.local_asn4): st.report_fail('bgp_ip_peer_establish_fail', data.local_ip_addr) else: st.log("eBGP V4 peer neigborship is successful") if data.ipv6_support: st.log("Verifying BGPV6 is established after save and reload") if not st.poll_wait(bgp_obj.verify_bgp_neighborship, 60, vars.D2, family=data.af_ipv6, shell=data.shell_vtysh, neighbor=data.local_ip6_addr, state='Established', asn=data.local_asn4): st.report_fail('bgp_ip6_peer_establish_fail', data.local_ip6_addr) else: st.log("eBGP V6 peer neigborship is successful")
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 poll_wait(method, timeout, *args, **kwargs): from spytest import st return st.poll_wait(method, timeout, *args, **kwargs)
def test_ft_arp_entry_link_failure(): ################# Author Details ################ # Name: Rakesh Kumar Vooturi # Email: [email protected] ################################################# # # Objective - Verify an ARP table entry learned on port based routing interface is # removed from ARP table after link failure on which that entry is learned. # Objective - Verify an ARP table entry learned on vlan based routing interface is # removed from ARP table after link failure on which that entry is learned # ############### Test bed details ################ # DUT-----TG ################################################# # Ping from tgen to DUT. res = tgapi.verify_ping(src_obj=tg, port_handle=tg_handler["tg_ph_1"], dev_handle=h1['handle'], dst_ip=data.d1t1_ip_addr,ping_count='1', exp_count='1') if res: st.log("Ping succeeded.") else: st.warn("Ping failed.") res = tgapi.verify_ping(src_obj=tg, port_handle=tg_handler["tg_ph_2"], dev_handle=h2['handle'], dst_ip=data.d1t2_ip_addr,ping_count='1', exp_count='1') st.log("PING_RES: " + str(res)) if res: st.log("Ping succeeded.") else: st.warn("Ping failed.") # Verify dynamic arp entries st.log("Verifying the arp entries on the DUT.") if not arp_obj.verify_arp(dut1,data.t1d1_ip_addr,data.t1d1_mac_addr,vars.D1T1P1,cli_type=data.cli_type): st.report_fail("ARP_entry_dynamic_entry_fail", data.t1d1_ip_addr, dut1) st.log("Verifying the arp entries on the DUT") if not arp_obj.verify_arp(dut1,data.t2d1_ip_addr,data.t2d1_mac_addr,vars.D1T1P2,data.vlan_1,cli_type=data.cli_type): st.report_fail("ARP_entry_dynamic_entry_fail", data.t2d1_ip_addr, dut1) # Shutdown the routing interface link. st.log("Shutdown the routing interface links.") if not interface_obj.interface_operation(dut1, [vars.D1T1P1, vars.D1T1P2] , "shutdown"): st.report_fail('interface_admin_shut_down_fail', [vars.D1T1P1, vars.D1T1P2]) # wait for ARP entries to be cleared waitapi.arp_clear_on_link_down(vars.D1T1P1) # Verify dynamic arp entries st.log("Verifying the arp entries on the DUT.") if arp_obj.verify_arp(dut1,data.t1d1_ip_addr,data.t1d1_mac_addr,vars.D1T1P1,cli_type=data.cli_type): interface_obj.interface_operation(dut1, [vars.D1T1P1, vars.D1T1P2], "startup") st.report_fail("ARP_dynamic_entry_removal_fail", data.t1d1_ip_addr, vars.D1T1P1) st.log("Verifying the arp entries on the DUT") if arp_obj.verify_arp(dut1,data.t2d1_ip_addr): interface_obj.interface_operation(dut1, [vars.D1T1P1, vars.D1T1P2], "startup") st.report_fail("ARP_dynamic_entry_removal_fail", data.t2d1_ip_addr, vars.D1T1P2) # Startup the routing interface link. st.log("Startup the routing interface link.") if not interface_obj.interface_operation(dut1, [vars.D1T1P1, vars.D1T1P2], "startup"): st.report_fail('interface_admin_startup_fail', [vars.D1T1P1, vars.D1T1P2]) if tg.tg_type == 'stc': tg.tg_traffic_control(action='run', port_handle=[tg_handler["tg_ph_1"], tg_handler["tg_ph_2"]]) # Verify dynamic arp entries st.log("Verifying the arp entries on the DUT.") if not st.poll_wait(arp_obj.verify_arp,15,dut1,data.t1d1_ip_addr,data.t1d1_mac_addr,vars.D1T1P1,cli_type=data.cli_type): st.report_fail("ARP_entry_dynamic_entry_fail", data.t1d1_ip_addr, dut1) st.log("Verifying the arp entries on the DUT") if not st.poll_wait(arp_obj.verify_arp,15,dut1,data.t2d1_ip_addr,data.t2d1_mac_addr,vars.D1T1P2,data.vlan_1,cli_type=data.cli_type): st.report_fail("ARP_entry_dynamic_entry_fail", data.t2d1_ip_addr, dut1) st.report_pass("test_case_passed")