def lldp_snmp_pre_config(): """ LLDP Pre Config """ global lldp_value global ipaddress global lldp_value_remote, lldp_value_gran global lldp_total_value data.ipaddress_d1 = basic_obj.get_ifconfig_inet(vars.D1, data.mgmt_int) data.ipaddress_d2 = basic_obj.get_ifconfig_inet(vars.D2, data.mgmt_int) if not data.ipaddress_d1: st.error(" Ip address is not a valid one or the ip is not presented on the device") st.report_fail("operation_failed") ipaddress = data.ipaddress_d1[0] if not intf_obj.poll_for_interfaces(vars.D1,iteration_count=60,delay=1): st.report_fail("interfaces_not_up_after_poll") if not intf_obj.poll_for_interfaces(vars.D2,iteration_count=60,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") if not lldp_obj.poll_lldp_neighbors(vars.D2, iteration_count=30, delay=1, interface=vars.D2D1P1): st.report_fail("lldp_neighbors_info_not_found_after_poll") st.log(" Getting Ip address of the Device") lldp_value = lldp_obj.get_lldp_neighbors(vars.D1, interface=vars.D1D2P1) lldp_value_remote = lldp_obj.get_lldp_neighbors(vars.D2, interface=vars.D2D1P1) st.log(" LLDP Neighbors value is: {} ".format(lldp_value)) st.log(" Remote LLDP Neighbors value is: {} ".format(lldp_value_remote)) if not lldp_value: st.error("No lldp entries are available") st.report_fail("operation_failed") if not lldp_value_remote: st.error(" No lldp entries are available in Remote") st.report_fail("operation_failed") lldp_value = lldp_value[0] lldp_total_value = lldp_value_remote lldp_value_remote = lldp_value_remote[0] lldp_value_gran = lldp_value['chassis_mgmt_ip'] if not data.ipaddress_d2[0] == lldp_value_gran: st.error("LLDP info IP and device IP are not matching") st.report_fail("operation_failed") # TODO : Need to check the below once the infra defect SONIC-5374 is Fixed ''' mac_output = basic_obj.get_platform_syseeprom(vars.D1, 'Serial Number', 'Value') lldp_value_mac = lldp_value['chassis_id_value'] st.log("lldp_value_gran is :{}".format(lldp_value_gran)) if not mac_output == lldp_value_mac: st.report_fail(" MAC Addresses are not matching ") ''' snmp_obj.set_snmp_config(vars.D1, snmp_rocommunity=data.ro_community, snmp_location=data.location) if not snmp_obj.poll_for_snmp(vars.D1, 30 , 1 , ipaddress= data.ipaddress_d1[0], oid=data.oid_sysName, community_name=data.ro_community): st.log("Post SNMP config , snmp is not working") st.report_fail("operation_failed")
def test_mgmt_vrf_ping_traceroute(): report_flag = 0 ip_addr = get_ifconfig_inet(vars.D1, 'eth0') if not ip_addr: st.report_fail('ip_verification_fail') if not ping(vars.D1, mgmt_vrf.extip, interface=mgmt_vrf.vrfname): report_flag = 1 if not ping(vars.D1, ip_addr[0], external=True): report_flag = 1 if report_flag: st.report_tc_fail("ft_mgmtVrf_ping", "mgmt_vrf_ping_fail") else: st.report_tc_pass("ft_mgmtVrf_ping", "mgmt_vrf_ping_pass") report_flag = 0 if not traceroute(vars.D1, mgmt_vrf.extip, vrf_name=mgmt_vrf.vrfname): report_flag = 1 if not traceroute(vars.D1, ip_addr[0], external=True): report_flag = 1 if report_flag: st.report_tc_fail("ft_mgmtVrf_traceroute", "mgmt_vrf_tr_fail") else: st.report_tc_pass("ft_mgmtVrf_traceroute", "mgmt_vrf_tr_pass") if report_flag: st.report_fail("mgmt_vrf_tr_fail") else: st.report_pass("mgmt_vrf_tr_pass")
def test_mgmt_vrf_tacacs(): tacacs_params = st.get_service_info(vars.D1, "tacacs") if not set_aaa_authentication_properties(vars.D1, 'failthrough', 'enable'): st.report_fail("authentication failthrough config fail") set_tacacs_server(vars.D1, 'add', tacacs_params.hosts[0].ip, tacacs_params.hosts[0].tcp_port, tacacs_params.hosts[0].timeout, tacacs_params.hosts[0].passkey, tacacs_params.hosts[0].auth_type, tacacs_params.hosts[0].priority, use_mgmt_vrf=True) if not verify_tacacs_server( vars.D1, tacacs_params.hosts[0].ip, tacacs_params.hosts[0].tcp_port, tacacs_params.hosts[0].timeout, tacacs_params.hosts[0].passkey, tacacs_params.hosts[0].auth_type, tacacs_params.hosts[0].priority): st.report_fail("Tacacs_server_configs_are_not_successful", tacacs_params.hosts[0].ip) set_aaa_authentication_properties(vars.D1, 'login', 'tacacs+ local') ip_addr = get_ifconfig_inet(vars.D1, 'eth0') if not ip_addr: st.report_fail('ip_verification_fail') if not poll_wait(connect_to_device, 10, ip_addr[0], mgmt_vrf.tacusername, mgmt_vrf.tacpassword, mgmt_vrf.protocol, mgmt_vrf.ssh_port): tacacs_cleanup(vars.D1, tacacs_params) st.report_fail("mgmt_vrf_tacacs", "failed") tacacs_cleanup(vars.D1, tacacs_params) st.report_pass("mgmt_vrf_tacacs", "successful")
def get_dut_ip(dut): chef_server.mgmt_intf = util_obj.ensure_service_params(dut, chef_server.name, "mgmt_intf") ip_addr = basic_obj.get_ifconfig_inet(dut, chef_server.mgmt_intf) if not ip_addr: st.log("IP Address not found on eth0") st.report_env_fail("test_case_not_executeds") return ip_addr[0]
def snmp_pre_config(): """ SNMP pre config """ global ipaddress ipaddress_list = basic_obj.get_ifconfig_inet(vars.D1, data.mgmt_int) st.log("Checking Ip address of the Device ") if not ipaddress_list: st.report_env_fail("ip_verification_fail") ipaddress = ipaddress_list[0] st.log("Device ip addresse - {}".format(ipaddress)) snmp_obj.set_snmp_config(vars.D1, snmp_rocommunity=data.ro_community, snmp_location=data.location) if not st.is_community_build(): ipfeature.configure_loopback(vars.D1, loopback_name="Loopback0", config="yes") ipfeature.config_ip_addr_interface(vars.D1, data.loopback0, data.loopback_addr, 32, family=data.af_ipv4) if not ipfeature.ping(vars.D1, ipaddress, family='ipv4', external=True): st.error("Ping reachability is failed between SNMP server and Device.") if not snmp_obj.poll_for_snmp(vars.D1, data.wait_time, 1, ipaddress=ipaddress, oid=data.oid_sysName, community_name=data.ro_community): st.log("Post SNMP config , snmp is not working") st.report_fail("operation_failed")
def test_ft_ip_static_ip_on_mgmt_intrf(): """ Author:Karthik Kumar Goud Battula([email protected]) Scenario: Verify the configuration of static ip address on eth0 interface and check the reachability """ result = True vars = st.ensure_min_topology("D1", "CONSOLE_ONLY") data.interface = 'eth0' intf_obj.enable_dhcp_on_interface(vars.D1, data.interface) st.wait(5) ip_address_list = basic_obj.get_ifconfig_inet(vars.D1, data.interface) if not ip_address_list: st.report_fail("DUT_does_not_have_IP_address".format( vars.D1, data.interface)) data.ip_address = ip_address_list[0] data.netmask = basic_obj.get_ifconfig(vars.D1, data.interface)[0]['netmask'][0] data.gateway = basic_obj.get_ifconfig_gateway(vars.D1, data.interface) intf_obj.config_static_ip_to_interface(vars.D1, data.interface, data.ip_address, data.netmask, data.gateway) st.log("Verify connectivity from DUT") if not ping_obj.ping(vars.D1, data.gateway): st.error("Ping is not successful for address {}".format(data.gateway)) result = False intf_obj.delete_ip_on_interface_linux( vars.D1, data.interface, "{}/{}".format(data.ip_address, data.netmask)) ip_address_list = basic_obj.get_ifconfig_inet(vars.D1, data.interface) if ip_address_list: st.error("DUT_have_IP_address".format(vars.D1, data.interface)) result = False intf_obj.enable_dhcp_on_interface(vars.D1, data.interface) if not ping_obj.ping(vars.D1, data.gateway): st.error("Ping is not successful for address".format(data.gateway)) result = False if not result: st.report_fail("test_case_failed") st.report_pass("test_case_passed")
def test_mgmt_vrf_reboot_cfgreload(): st.banner('mgmt_vrf_reboot, mgmt_vrf_cfgreload') st.log("Config reload the DUT") report_flag = 0 config_save_reload(vars.D1) ip_addr = get_ifconfig_inet(vars.D1, 'eth0') if not ip_addr: st.report_fail('ip_verification_fail') if not ping(vars.D1, mgmt_vrf.extip, interface=mgmt_vrf.vrfname): report_flag = 1 if not ping(vars.D1, ip_addr[0], external=True): report_flag = 1 if report_flag == 1: st.report_tc_fail("ft_mgmtVrf_cfgreload", "mgmt_vrf_cfgreload_fail") st.generate_tech_support(vars.D1, "ft_mgmtVrf_cfgreload") else: st.report_tc_pass("ft_mgmtVrf_cfgreload", "mgmt_vrf_cfgreload_pass") config_save(vars.D1, "sonic") config_save(vars.D1, "vtysh") st.reboot(vars.D1) ip_addr = get_ifconfig_inet(vars.D1, 'eth0') if not ip_addr: st.report_fail('ip_verification_fail') if not ping(vars.D1, mgmt_vrf.extip, interface=mgmt_vrf.vrfname): report_flag = 2 if not ping(vars.D1, ip_addr[0], external=True): report_flag = 2 if report_flag == 2: st.report_tc_fail("ft_mgmtVrf_reboot", "mgmt_vrf_reboot_fail") st.generate_tech_support(vars.D1, "ft_mgmtVrf_reboot") else: st.report_tc_pass("ft_mgmtVrf_reboot", "mgmt_vrf_reboot_pass") if report_flag: st.report_fail("test_case_failed") else: st.report_pass("test_case_passed")
def chef_pre_config_in_parallel(thread=True): [out, exceptions] = utils.exec_foreach(thread, vars.dut_list, chef_pre_config) st.log(exceptions) if False in out: st.report_env_fail("test_case_not_executeds") st.log("Fetching Chef config params from sonic services file") chef_params.ip = util_obj.ensure_service_params(vars.D1, "chef", "ip") chef_params.username = util_obj.ensure_service_params( vars.D1, "chef", "username") chef_params.password = util_obj.ensure_service_params( vars.D1, "chef", "password") chef_params.path = util_obj.ensure_service_params(vars.D1, "chef", "path") chef_params.roles = util_obj.ensure_service_params(vars.D1, "chef", "roles") chef_params.cookbook_path = util_obj.ensure_service_params( vars.D1, "chef", "cookbook_path") chef_params.client_path = util_obj.ensure_service_params( vars.D1, "chef", "client_path") chef_params.validation_file = util_obj.ensure_service_params( vars.D1, "chef", "validation_file") chef_params.client_rb = util_obj.ensure_service_params( vars.D1, "chef", "client_rb") chef_params.client_log = util_obj.ensure_service_params( vars.D1, "chef", "client_log") chef_params.default_rb = util_obj.ensure_service_params( vars.D1, "chef", "default_rb") chef_params.mgmt_intf = util_obj.ensure_service_params( vars.D1, "chef", "mgmt_intf") st.log("Logging in to chef server with the params from config file.") global ssh_conn_obj ssh_conn_obj = con_obj.connect_to_device(chef_params.ip, chef_params.username, chef_params.password) if not ssh_conn_obj: st.error("SSH connetion object not found.") st.report_env_fail("ssh_connection_failed", chef_params.ip) ip_addr = basic_obj.get_ifconfig_inet(vars.D1, chef_params.mgmt_intf) ssh_obj = con_obj.connect_to_device(ip_addr[0], 'admin', 'YourPaSsWoRd') if ssh_obj: chef_obj.bootstrap_chef_node(ssh_conn_obj, ip_addr[0], 'admin', 'YourPaSsWoRd', node_name) else: chef_obj.bootstrap_chef_node(ssh_conn_obj, ip_addr[0], 'admin', 'broadcom', node_name) st.log("CHEF pre-config Done")
def test_mgmt_vrf_curl_snmp(): report_flag, module_flag = 0, 0 ip_addr = get_ifconfig_inet(vars.D1, 'eth0') if not ip_addr: st.report_fail('ip_verification_fail') set_snmp_config(vars.D1, snmp_rocommunity=mgmt_vrf.ro_community, snmp_location=mgmt_vrf.location) config_snmp_agent(vars.D1, ip_addr=ip_addr[0], vrf='mgmt') if not poll_for_snmp(vars.D1, mgmt_vrf.wait_time, 1, ipaddress=ip_addr[0], oid=mgmt_vrf.oid_sysName, community_name=mgmt_vrf.ro_community): st.log( "Post MGMT VRF creation and snmpagent addition, snmp is not working" ) config_snmp_agent(vars.D1, ip_addr=ip_addr[0], vrf='mgmt', no_form=True) report_flag, module_flag = 1, 1 config_snmp_agent(vars.D1, ip_addr=mgmt_vrf.secondagent, vrf='mgmt') if not poll_for_snmp(vars.D1, mgmt_vrf.wait_time, 1, ipaddress=ip_addr[0], oid=mgmt_vrf.oid_sysName, community_name=mgmt_vrf.ro_community): st.log("After second agent within same VRF, snmp is not working") config_snmp_agent(vars.D1, ip_addr=mgmt_vrf.secondagent, vrf='mgmt', no_form=True) report_flag, module_flag = 1, 1 config_snmp_agent(vars.D1, ip_addr=ip_addr[0], vrf='mgmt', no_form=True) if report_flag: st.report_tc_fail("ft_mgmtVrf_snmp", "mgmt_vrf_snmp_fail") else: st.report_tc_pass("ft_mgmtVrf_snmp", "mgmt_vrf_snmp_pass") if module_flag: st.report_fail("test_case_failed") else: st.report_pass("test_case_passed")
def check_dhcp_client(interface='', network_pool='', family='ipv4', entry=True): if family == 'ipv4': ip = basic_api.get_ifconfig_inet(data.dut4, interface) else: ip = basic_api.get_ifconfig_inet6(data.dut4, interface) if len(ip) > 0: for ip_item in ip: if 'fe80' in ip_item: ip.remove(ip_item) if len(ip) == 0: if entry is True: st.error("{} address assignment failed on {}".format( family, interface)) return False else: st.log(" {} address did not get assigned as expected on {}".format( family, interface)) return True else: if entry is False: st.error( " {} address got assigned on {} which is not expected".format( family, interface)) return False else: ip_add = ip[0] if family == 'ipv4': ip = ip_add.split('.')[:-1] network_octet = ".".join(ip) + '.' else: network_octet = ip_add.split("::")[0] + "::" if interface == data.d4d2_ports[1] and family == 'ipv4': data.ip_add_phy = ip_add else: data.ip_add_phy_v6 = ip_add.rstrip() st.log("offered_ip {}".format(ip_add)) if str(network_octet) != str(network_pool): st.error( "{} IP_address_assignment not in expected subnet on {}". format(family, interface)) return False return True
def chef_pre_config(dut): st.log("CHEF pre-config Start") ip_addr = basic_obj.get_ifconfig_inet(dut, 'eth0') if not ip_addr: st.log("IP Address not found on eth0") st.report_env_fail("test_case_not_executeds") basic_obj.deploy_package(dut, mode='update') basic_obj.deploy_package(dut, packane_name='sshpass', mode='install') ip = util_obj.ensure_service_params(dut, "chef", "ip") username = util_obj.ensure_service_params(dut, "chef", "username") password = util_obj.ensure_service_params(dut, "chef", "password") st.log("Chef Server IP : {}".format(ip)) url = "https://{}:443".format(ip) st.log("Chef server url used : {}".format(url)) if not chef_obj.chef_package_install(dut, url, ip_addr[0], 'admin', 'broadcom', 'YourPaSsWoRd'): st.report_env_fail("test_case_not_executeds") st.log("Done Installing the dependents packages if not installed.") if not chef_obj.sync_with_server_time(dut, ip, username, password): st.report_env_fail("test_case_not_executeds")
def test_mgmt_vrf_warmboot(): st.log("Warmboot the DUT") report_flag = 0 st.reboot(vars.D1, "warm") ip_addr = get_ifconfig_inet(vars.D1, 'eth0') if not ip_addr: st.report_fail('ip_verification_fail') if not ping(vars.D1, mgmt_vrf.extip, interface=mgmt_vrf.vrfname): report_flag = 1 if not ping(vars.D1, ip_addr[0], external=True): report_flag = 1 if report_flag: st.report_tc_fail("ft_mgmtVrf_warmboot", "mgmt_vrf_warmboot", "failed") else: st.report_tc_pass("ft_mgmtVrf_warmboot", "mgmt_vrf_warmboot", "successful") if report_flag: st.report_fail("test_case_failed") else: st.report_pass("test_case_passed")
def verify_dhcp_client(dut, interface_name, ip_ad="", network="", family=""): ip_ad = data.RA_ipaddress_2 if not ip_ad else ip_ad network = data.subnet if not network else network family = "ipv4" if not family else family client_ip = None try: if family == "ipv4": ip_details = basic_obj.get_ifconfig_inet(dut, interface_name) if ip_details: client_ip = ip_details[0].strip() elif family == "ipv6": ip_details = basic_obj.get_ifconfig_inet6(dut, interface_name) if ip_details: if len(ip_details) > 1: if not ip_details[1].startswith("fe"): client_ip = ip_details[1].strip() else: client_ip = ip_details[0].strip() else: client_ip = ip_details[0].strip() else: st.log("Unsupported family .. {}".format(family)) return False except Exception as e: st.log(e) st.error("DHCP client failed to get the IP address on {}".format(dut)) return False if not client_ip: st.log("No Client IP found") return False client_ip = client_ip.split("/") st.log("OFFERED IP {}".format(client_ip[0])) if family == "ipv6": client_ip = client_ip[0].split("%") if not utils.verify_ip4_ip6_in_subnetwork(client_ip[0], "{}/{}".format( ip_ad, network)): st.log( "DHCP Client failed to get the ip4/6 address from the configured pool" ) return False return True
def test_mgmt_vrf_bind(): report_flag = 0 #intf = ['mgmt','eth0'] intf = ['eth0'] if not mvrf.verify(vars.D1, mvrfstate='Enabled', interfaces=intf): st.log("FAILED") report_flag = 1 if report_flag: st.report_tc_fail("ft_mgmtVrf_bind", "mgmt_vrf_eth0_bind_fail") else: st.report_tc_pass("ft_mgmtVrf_bind", "mgmt_vrf_eth0_bind_success") report_flag = 0 intf_li = get_all_interfaces(vars.D1) if not mvrf.verify( vars.D1, mvrfstate='Enabled', interfaces=intf_li, dataport=True): report_flag = 1 if report_flag: st.report_tc_fail("ft_mgmtVrf_dataport", "mgmt_vrf_dataport_bind") else: st.report_tc_pass("ft_mgmtVrf_dataport", "mgmt_vrf_dataport_nobind") report_flag = 0 ip_addr = get_ifconfig_inet(vars.D1, 'eth0') if not ip_addr: st.log("IP Address not found on eth0") report_flag = 1 ssh_conn_obj = connect_to_device(ip_addr[0], mgmt_vrf.username_default, mgmt_vrf.password_default) if not ssh_conn_obj: if not connect_to_device(ip_addr[0], mgmt_vrf.username_default, mgmt_vrf.password_alt): report_flag = 1 if report_flag: st.report_tc_fail("ft_mgmtVrf_ssh", "mgmt_vrf_ssh_fail") else: st.report_tc_pass("ft_mgmtVrf_ssh", "mgmt_vrf_ssh_pass") if report_flag: st.report_fail("mgmt_vrf_eth0_bind_fail") else: st.report_pass("mgmt_vrf_eth0_bind_success")
def test_ft_snmp_max_vlan_scale(): ''' Author: Prasad Darnasi <*****@*****.**> verify The BRIDGE-MIB requirements functionality by scaling DUT with max Vlans ''' vlan_module_config(config='yes') st.log("Checking VLAN config after reboot") max_vlan_verify() global ipaddress ipaddress_list = basic_obj.get_ifconfig_inet(vars.D1, sc_data.mgmt_int) st.log("Checking Ip address of the Device ") if not ipaddress_list: st.report_env_fail("ip_verification_fail") ipaddress = ipaddress_list[0] st.log("Device ip addresse - {}".format(ipaddress)) snmp_obj.set_snmp_config(vars.D1, snmp_rocommunity=sc_data.ro_community, snmp_location=sc_data.location) if not snmp_obj.poll_for_snmp(vars.D1, 30, 1, ipaddress=ipaddress, oid=sc_data.oid_sysName, community_name=sc_data.ro_community): st.log("Post SNMP config , snmp is not working") st.report_fail("operation_failed") basic_obj.get_top_info(vars.D1, proc_name='snmpd') get_snmp_output = snmp_obj.poll_for_snmp_walk( vars.D1, 15, 1, ipaddress=ipaddress, oid=sc_data.oid_dot1qBase, community_name=sc_data.ro_community) if not get_snmp_output: st.report_fail("get_snmp_output_fail") st.report_pass("test_case_passed")
def ensure_device_ipaddress(): data.ip_address_list = basic_obj.get_ifconfig_inet(vars.D1, 'eth0') if not data.ip_address_list: st.report_fail("DUT_does_not_have_IP_address") data.ip_address = data.ip_address_list[0]