def delete_ntp_servers(dut, cli_type=''): """ :param dut: :param iplist: :return: """ cli_type = st.get_ui_type(dut, cli_type=cli_type) output = show_ntp_server(dut) commands = [] if output is None: st.log("No servers to delete") return True else: for ent in iterable(output): server_ip = ent["remote"].strip("+*#o-x").strip() if cli_type == "click": commands.append("config ntp del {}".format(server_ip)) elif cli_type == "klish": commands.append("no ntp server {}".format(server_ip)) elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, "rest_urls") url1 = rest_urls['config_ntp_server'].format(server_ip) if not delete_rest(dut, rest_url=url1): st.error("Failed to delete ntp {} server".format(server_ip)) else: st.log("UNSUPPORTED CLI TYPE -- {}".format(cli_type)) return False st.config(dut, commands, type=cli_type) return True
def get_interface_pmap_details(dut, interface_name=None): """ Author: Chaitanya Vella ([email protected]) This API is used to get the interface pmap details :param dut: dut :param interface_name: List of interface names :return: """ ##Passing the cli_type as click in the API call "interface_status_show" because the lanes information is available only in click CLI. ##Please refer the JIRA: SONIC-22102 for more information. interfaces = utils.make_list(interface_name) if interface_name else '' if interfaces: if any("/" in interface for interface in interfaces): interfaces = st.get_other_names(dut, interfaces) key = 'alias' else: key = 'interface' st.debug("The interfaces list is: {}".format(interfaces)) interface_list = interface_obj.interface_status_show( dut, interfaces=interfaces, cli_type='click') else: key = 'alias' if interface_obj.show_ifname_type( dut, cli_type='klish') else 'interface' interface_list = interface_obj.interface_status_show(dut, cli_type='click') interface_pmap = dict() pmap_list = bcmcmd_show_pmap(dut) for detail in utils.iterable(interface_list): lane = detail["lanes"].split( ",")[0] if "," in detail["lanes"] else detail["lanes"] for pmap in pmap_list: if pmap["physical"] == lane: interface_pmap[detail[key]] = pmap["interface"] return interface_pmap
def get_mac_entries_by_mac_address(dut, mac_address, **kwargs): ''' Display MAC entries with a MAC search pattern and return the output. :param mac_address: :param cli_type: :return: ''' cli_type = st.get_ui_type(dut, **kwargs) if cli_type == 'click': command="show mac | grep {}".format(mac_address) mac_entries = st.show(dut, command) elif cli_type == 'klish': command="show mac address-table | grep {}".format(mac_address) mac_entries = st.show(dut, command,type=cli_type) elif cli_type in ["rest-patch", "rest-put"]: entries = get_mac(dut, cli_type=cli_type) mac_entries = [] for entry in iterable(entries): exp = "^{}".format(mac_address.strip()) if re.search(exp, entry['macaddress'], re.IGNORECASE): mac_entries.append(entry) st.debug(mac_entries) else: st.log("Unsupported cli") return False return mac_entries
def get_member_vlan(dut, interface_list=[], cli_type=''): cli_type = st.get_ui_type(dut, cli_type=cli_type) """ To Get Members vs list of VLANs. Author : Prudvi Mangadu ([email protected]) :param dut: :param interface_list: :param cli_type: :return: """ member_val = {} interface_li = list(interface_list) if isinstance( interface_list, list) else [interface_list] out = show_vlan_config(dut, cli_type=cli_type) if interface_li: temp = [] for each in list(set(interface_li)): temp += filter_and_select(out, None, {"member": each}) out = temp for each in iterable(out): if each['member']: if each['member'] not in member_val: member_val[each['member']] = [each['vid']] else: member_val[each['member']].append(each['vid']) return member_val
def get_vlan_member(dut, vlan_list=[], cli_type=''): cli_type = st.get_ui_type(dut, cli_type=cli_type) """ To Get VLANs vs list of Members. Author : Prudvi Mangadu ([email protected]) :param dut: :param vlan_list: :param cli_type: :return: """ vlan_val = {} vlan_li = map(str, vlan_list) if isinstance(vlan_list, list) else [vlan_list] out = show_vlan_config(dut, cli_type=cli_type) if vlan_li: temp = [] for each in list(set(vlan_li)): temp += filter_and_select(out, None, {"vid": each}) out = temp for each in iterable(out): if each['member']: if each['vid'] not in vlan_val: vlan_val[each['vid']] = [each['member']] else: vlan_val[each['vid']].append(each['member']) return vlan_val
def verify_ntp_server_details(dut, server_ip=None, **kwargs): output = show_ntp_server(dut) flag = 1 if not output: flag = 0 if server_ip is None: if "No association ID's returned" in str(output): return True elif "%Error: Resource not found" in str(output): return True else: return False else: server_ips = [server_ip] if type(server_ip) is str else list([str(e) for e in server_ip]) data = kwargs for ent in iterable(output): remote_ip = ent["remote"].strip("+*#o-x").strip() if remote_ip in server_ips: if 'remote' in data and remote_ip not in data['remote']: st.log("Remote Server IP is not matching") flag = 0 if 'refid' in data and ent["refid"] != data["refid"]: st.log("Ref ID is not matching") flag = 0 if 'st' in data and ent["st"] != data["st"]: st.log("Stratum value is not matching") flag = 0 if 't' in data and ent["t"] != data["t"]: st.log("Type is not matching") flag = 0 if 'when' in data and ent["when"] != data["when"]: st.log("Polling value is not matching") flag = 0 if 'poll' in data and ent["poll"] != data["poll"]: st.log("Polling in seconds is not matching") flag = 0 if 'reach' in data and ent["reach"] != data["reach"]: st.log("Reach is not matching") flag = 0 if 'delay' in data and ent["delay"] != data["delay"]: st.log("Delay is not matching") flag = 0 if 'offset' in data and ent["offset"] != data["offset"]: st.log("Offset value is not matching") flag = 0 if 'jitter' in data and ent["jitter"] != data["jitter"]: st.log("Jitter value is not matching") flag = 0 else: st.log("Server IP is not matching") flag = 0 if flag: st.log("Server IP's matched.") return True else: st.log("Server IP's not matched.") return False
def multicast_queue_start_value(dut, *argv, **kwargs): result = True output = show(dut, *argv, **kwargs) for queue in iterable(output): if queue.get('mc8'): result = True break else: result = False return result
def verify_ntp_server_exists(dut, server_ip=None, **kwargs): output = show_ntp_server(dut) if server_ip is None: if "No association ID's returned" in str(output): return True else: return False else: server_ips = [server_ip] if type(server_ip) is str else list([str(e) for e in server_ip]) data = kwargs for ent in iterable(output): remote_ip = ent["remote"].strip("+*#o-x").strip() if remote_ip in server_ips: if 'remote' in data and remote_ip not in data['remote']: st.log("Remote Server IP is not matching") return False else: return True
def verify_traffic_hash(dut, port_list, pkts_per_port, traffic_loss_verify=False, rx_port = '', tx_port = '', dut2 =''): if traffic_loss_verify: sub_list = [] sub_list.append([intf_obj.show_interface_counters_all, dut]) sub_list.append([intf_obj.show_interface_counters_all, dut2]) [output, exceptions] = utils.exec_all(True, sub_list) utils.ensure_no_exception(exceptions) data.int_cntr_1, data.int_cntr_2 = output else: data.int_cntr_1 = intf_obj.show_interface_counters_all(dut) data.intf_count_dict = {} for port in port_list: for counter_dict in iterable(data.int_cntr_1): if counter_dict['iface'] == port: try: data.intf_count_dict[port] = int(counter_dict['tx_ok'].replace(',','')) except Exception: st.report_fail('invalid_traffic_stats') if not (data.intf_count_dict[port] >= pkts_per_port): intf_obj.show_interface_counters_detailed(vars.D1, vars.D1T1P1) st.report_fail("traffic_not_hashed", dut) if traffic_loss_verify: for counter_dict in data.int_cntr_1: if counter_dict['iface'] == rx_port: try: data.rx_traffic = int(counter_dict['rx_ok'].replace(',', '')) except Exception: st.report_fail('invalid_traffic_stats') break for counter_dict in data.int_cntr_2: if counter_dict['iface'] == tx_port: try: data.tx_traffic = int(counter_dict['tx_ok'].replace(',', '')) except Exception: st.report_fail('invalid_traffic_stats') break if not (data.tx_traffic >= 0.95* data.rx_traffic): st.log("data.tx_traffic:{}".format(data.tx_traffic)) st.log("data.rx_traffic:{}".format(data.rx_traffic)) intf_obj.show_interface_counters_detailed(vars.D1, vars.D1T1P1) st.report_fail('traffic_loss_observed') return data.intf_count_dict
def verify_dhcp_relay_detailed(dut, interface, **kwargs): """ API to verify DHCP RELAY datailed configuration :param dut: """ #src_interface = kwargs.get("src_interface", None) #link_select = kwargs.get("link_select", None) #hop_count = kwargs.get("max_hop_count",None) ip_family = kwargs.get("family", "ipv4") cli_type = st.get_ui_type(dut, **kwargs) output = dhcp_relay_detailed_show(dut, interface, family=ip_family, cli_type=cli_type) if output == 0: st.error("Output is Empty") return False if kwargs.get("cli_type"): del kwargs["cli_type"] if kwargs.get("family"): del kwargs["family"] for each in kwargs.keys(): if 'src_interface' in each or 'link_select' in each or 'max_hop_count' in each \ or 'vrf_name' in each or 'policy_action' in each or 'vrf_select' in each: match = {each: kwargs[each]} st.log(match) entries = filter_and_select(output, None, match) st.log("entries {}".format(entries)) if not entries: st.log("{} and {} is not match ".format(each, kwargs[each])) return False if kwargs.get("server_addr"): for result in iterable(output): if result.get("server_addr"): server_addr = result.get("server_addr") break st.debug("SERVER ADDR: {}".format(server_addr)) if not server_addr: st.log("Server address from output is empty") return False if kwargs.get("server_addr") not in server_addr.split(", "): st.log("Provided server address is not matching with configured one") return False return True
def check_intf_traffic_counters(dut, port, loopCnt): flag = 0 iter = 1 p2_txmt = 0 while iter <= loopCnt: output = papi.get_interface_counters_all(dut, port=port) for entry in iterable(output): if entry["iface"] == port: DUT_tx_value = entry["tx_pps"] p2_txmt = DUT_tx_value p2_txmt = p2_txmt.replace("/s","") st.log("tx_pps counter value on DUT {} Egress port {} : {}".format(dut,port,p2_txmt)) if (int(float(p2_txmt)) >= data.traffic_rate_pps-1000): flag = 1 break iter = iter+1 if flag: return True else: return False