def verify_bgp_route_count(dut, family='ipv4', shell="sonic", **kwargs): if family.lower() == 'ipv4': output = bgpfeature.show_bgp_ipv4_summary(dut) if family.lower() == 'ipv6': output = bgpfeature.show_bgp_ipv6_summary(dut) st.debug(output) if 'neighbor' in kwargs and 'state' in kwargs: match = {'neighbor': kwargs['neighbor']} try: entries = filter_and_select(output, None, match)[0] except Exception: st.log("ERROR 1") if entries['state']: if kwargs['state'] == 'Established': if entries['state'].isdigit(): return entries['state'] else: return 0 else: return 0 else: return 0 return 0
def get_cpu_queue_counters(dut, **kwargs): """ Author: Gangadhara Sahu ([email protected]) API to return CPU queue counters :param dut: :param queue_id: <0-31> :param: <byte_count | pkts_drop | pps | bps | pkts_count | byte_drop > :return: Example : get_cpu_queue_counters(dut1) get_cpu_queue_counters(dut1,queue_id="0",param="pkts_drop") """ if "queue_id" in kwargs: command = "show queue counters interface CPU queue {}".format(kwargs['queue_id']) else: command = "show queue counters interface CPU" if "queue_id" in kwargs: cli_out = st.show(dut,command,type="klish") fil_out = filter_and_select(cli_out, [kwargs['param']], {"txq" : "MC"+kwargs['queue_id']}) return fil_out[0] else: cli_out = st.show(dut,command,type="klish") return cli_out
def verify_tacacs_server(dut, address, tcp_port=None, timeout=None, passkey=None, auth_type=None, priority=None, cli_type=""): ''' To verify the 'show tacacs' server parameters ''' cli_type = st.get_ui_type(dut, cli_type=cli_type) output = show_tacacs(dut, cli_type=cli_type) output = output['servers'] if address and not filter_and_select(output, ['address'], {"address": address}): st.error("Provided and configured address values are not matching.") return False if tcp_port and not filter_and_select(output, ['tcp_port'], {"tcp_port": tcp_port}): st.error("Provided and configured tcp_port values are not matching.") return False if priority and not filter_and_select(output, ['priority'], {"priority": priority}): st.error("Provided and configured priority values are not matching.") return False if timeout and not filter_and_select(output, ['timeout'], {"timeout": timeout}): st.error("Provided and configured timeout values are not matching.") return False if passkey and not filter_and_select(output, ['passkey'], {"passkey": passkey}): st.error("Provided and configured passkey values are not matching.") return False if auth_type and not filter_and_select(output, ['auth_type'], {"auth_type": auth_type}): st.error("Provided and configured auth_type values are not matching.") return False return True
def check_inter_dut_intf_traffic_counters(): dut2 = vars.D2 (dut1) = (data.dut) papi.clear_interface_counters(dut2) papi.clear_interface_counters(dut1) st.wait(5) output = papi.get_interface_counters_all(dut2) p1_tx = intf_traffic_stats(filter_and_select(output, ["tx_bps"], {'iface': vars.D2D1P1})) p2_tx = intf_traffic_stats(filter_and_select(output, ["tx_bps"], {'iface': vars.D2D1P2})) p3_tx = intf_traffic_stats(filter_and_select(output, ["tx_bps"], {'iface': vars.D2D1P3})) p4_tx = intf_traffic_stats(filter_and_select(output, ["tx_bps"], {'iface': vars.D2D1P4})) st.log("Inter Dut port stats tx_ok xounter value on DUT Egress ports : {} {} {} {}".format(p1_tx, p2_tx, p3_tx, p4_tx)) if (p1_tx == 0) | (p2_tx == 0) | (p3_tx == 0) | (p4_tx == 0): st.error("Error:Inter Dut port stats tx_ok xounter value on DUT Egress ports : {} {} {} {}".format(p1_tx, p2_tx, p3_tx, p4_tx)) else: st.log("Inter Dut port stats tx_ok xounter value on DUT Egress ports - Non Zero") return True DUT_rx_value = papi.get_interface_counters(dut2, vars.D2T1P1, "rx_ok") for i in DUT_rx_value: p1_rcvd = i['rx_ok'] p1_rcvd = p1_rcvd.replace(",","") st.log("rx_ok xounter value on DUT Inress port : {}".format(p1_rcvd)) if (abs(int(float(p1_rcvd))) > 0): output = papi.get_interface_counters_all(dut2) entry1 = filter_and_select(output, ["tx_bps"], {'iface': vars.D2D1P1}) entry2 = filter_and_select(output, ["tx_bps"], {'iface': vars.D2D1P2}) entry3 = filter_and_select(output, ["tx_bps"], {'iface': vars.D2D1P3}) entry4 = filter_and_select(output, ["tx_bps"], {'iface': vars.D2D1P4}) for i in entry1: p1_txmt = i['tx_bps'] p1_txmt = p1_txmt.replace(" MB/s","") p1_txmt = p1_txmt.replace(" KB/s","") p1_txmt = p1_txmt.replace(" B/s","") for i in entry2: p2_txmt = i['tx_bps'] p2_txmt = p2_txmt.replace(" MB/s","") p2_txmt = p2_txmt.replace(" KB/s","") p2_txmt = p2_txmt.replace(" B/s","") for i in entry3: p3_txmt = i['tx_bps'] p3_txmt = p3_txmt.replace(" MB/s","") p3_txmt = p3_txmt.replace(" KB/s","") p3_txmt = p3_txmt.replace(" B/s","") for i in entry4: p4_txmt = i['tx_bps'] p4_txmt = p4_txmt.replace(" MB/s","") p4_txmt = p4_txmt.replace(" KB/s","") p4_txmt = p4_txmt.replace(" B/s","") st.log("Inter Dut port stats tx_ok xounter value on DUT Egress ports : {} {} {} {}".format(p1_txmt, p2_txmt, p3_txmt, p4_txmt)) if (abs(int(float(p1_txmt))) == 0) | (abs(int(float(p2_txmt))) == 0) | (abs(int(float(p3_txmt))) == 0) | (abs(int(float(p4_txmt))) == 0): st.show(dut1, "show arp") st.error("Inter Dut port stats tx_ok xounter value on DUT Egress ports are non zero") return False else: st.log("All ECMP paths are utilized") return True else: st.error("rx_ok xounter value on DUT Inress port : {}".format(p1_rcvd)) return False
def get_stp_next_root_port(dut, vlan, cli_type='click'): """ API will return Next possible Root/Forwarding port of the device in the VLAN. Author: Prudvi Mangadu ([email protected]) :param dut: :param vlan: :param cli_type: :return: """ partner = None next_root_port = None sort_list = lambda list1, list2: [x for _, x in sorted(zip(list2, list1))] out = show_stp_vlan(dut, vlan, cli_type=cli_type) if not out: st.error("No Initial Root/Forwarding port found") return next_root_port if out[0]['rt_port'] == "Root": st.error("Given device is ROOT Bridge.") return next_root_port partner_ports = st.get_dut_links(dut) root_port = out[0]['rt_port'] root_cost = int( filter_and_select(out, ['port_pathcost'], {'port_name': root_port})[0]['port_pathcost']) st.log('root_port : {}, root_cost: {}'.format(root_port, root_cost)) # Finding the Root port connected partner for each in partner_ports: if not partner: if root_port == each[0]: partner = each[1] st.log("partner : {}".format(partner)) if not partner: st.error("No Partner found for Root/Forwarding Port.") return next_root_port # Dut Partner port mapping dut_partner_ports = st.get_dut_links(dut, partner) dut_partner_ports_map = {all[0]: all[2] for all in dut_partner_ports} dut_partner_ports_map_rev = {all[2]: all[0] for all in dut_partner_ports} st.log('dut_partner_ports_map : {}'.format(str(dut_partner_ports_map))) st.log('dut_partner_ports_map_rev : {}'.format( str(dut_partner_ports_map_rev))) # Preparing DATA to process and find the next Root/Forwarding port. cut_data = {} pc_list = [ each['teamdev'] for each in portchannel.get_portchannel_list(partner) ] for each in out: port = each['port_name'] if "Ethernet" in port and port in dut_partner_ports_map: port = dut_partner_ports_map[each['port_name']] ifindex = int(re.findall(r'\d+', port)[0]) cut_data[port] = [ ifindex, each['port_state'], int(each['port_pathcost']) ] elif port in pc_list: ifindex = int(re.findall(r'\d+', port)[0]) cut_data[port] = [ ifindex, each['port_state'], int(each['port_pathcost']) ] else: pass st.log('cut_data == {}'.format(str(cut_data))) cost_vs_port = {} for each in cut_data: if each != dut_partner_ports_map[root_port]: if 'Ethernet' in each: if cut_data[each][2] not in cost_vs_port: cost_vs_port[cut_data[each][2]] = [[each], []] else: cost_vs_port[cut_data[each][2]][0].append(each) else: if cut_data[each][2] not in cost_vs_port: cost_vs_port[cut_data[each][2]] = [[], [each]] else: cost_vs_port[cut_data[each][2]][1].append(each) sorted_cost = sorted(cost_vs_port.keys()) st.log("cost_vs_port : {}".format(cost_vs_port)) st.log("sorted_cost : {}".format(sorted_cost)) # Logic to find next Root/Forwarding port if root_cost in cost_vs_port and (len(cost_vs_port[root_cost][0]) or len(cost_vs_port[root_cost][1])): st.debug( "When 2 or more ports has configured with same root port cost.") if len(cost_vs_port[root_cost][0]): port_list = cost_vs_port[root_cost][0] port_index_li = [cut_data[e][0] for e in port_list] next_root_port = sort_list(port_list, port_index_li)[0] return dut_partner_ports_map_rev[next_root_port] else: port_list = cost_vs_port[root_cost][1] port_index_li = [cut_data[e][0] for e in port_list] next_root_port = sort_list(port_list, port_index_li)[0] return next_root_port elif len(sorted_cost): st.debug( "When NO 2 or more ports has root port cost configured. So checking next larger cost ports" ) next_root_cost = sorted_cost[0] if len(cost_vs_port[next_root_cost][0]): port_list = cost_vs_port[next_root_cost][0] port_index_li = [cut_data[e][0] for e in port_list] next_root_port = sort_list(port_list, port_index_li)[0] return dut_partner_ports_map_rev[next_root_port] else: port_list = cost_vs_port[next_root_cost][1] port_index_li = [cut_data[e][0] for e in port_list] next_root_port = sort_list(port_list, port_index_li)[0] return next_root_port else: st.error("No Match") return next_root_port
def get_interface_counters(dut, port, *counter): output = get_interface_counters_all(dut) entries = filter_and_select(output, counter, {'iface': port}) return entries
def verify_udld_neighbors(dut, **kwargs): """ Author: Chandra Sekhar Reddy email : [email protected] :param dut: :param local_port: :type string or list :param device_name: :type string or list :param remote_device_id: :type mac in string or list :param remote_port: :type string or list :param neighbor_state: :type string or list :return: Usage verify_udld_neighbors(dut1,local_port=['Ethernet1','Ethernet3'],device_name=['Sonic','Sonic'], remote_device_id=['3c2c.992d.8201','3c2c.992d.8202'],remote_port=['Ethernet0','Ethernet3'],\ neighbor_state=['Bidirectional','Bidirectional']) verify_udld_neighbors(dut1,local_port='Ethernet3',neighbor_state='Bidirectional') udld.verify_udld_neighbors(dut1,local_port='Ethernet32',neighbor_state='Bidirectional', device_name='Sonic' ,remote_device_id ='3C2C.99A6.FBA0' ,remote_port ='Ethernet24',cli_type = 'rest-put') """ ret_val = True cli_type = kwargs.pop('cli_type', st.get_ui_type(dut)) remote_port = kwargs.get('remote_port', None) device_name = kwargs.get('device_name', None) neighbor_state = kwargs.get('neighbor_state', None) local_port = kwargs.get('local_port', None) if cli_type == 'klish' or cli_type == 'click': output = st.show(dut, 'show udld neighbors', type="klish", config="false", skip_error_check="True") st.log("Before output......................") st.log("{}".format(tabulate(output, headers="keys", tablefmt='psql'))) st.log("After output......................") if len(output) == 0: st.error("Output is Empty") return False if 'return_output' in kwargs: return output #Converting all kwargs to list type to handle single or list of udld neighbors for key in kwargs: if type(kwargs[key]) is list: kwargs[key] = list(kwargs[key]) else: kwargs[key] = [kwargs[key]] #convert kwargs into list of dictionary input_dict_list = [] for i in range(len(kwargs[kwargs.keys()[0]])): temp_dict = {} for key in kwargs.keys(): temp_dict[key] = kwargs[key][i] input_dict_list.append(temp_dict) for input_dict in input_dict_list: entries = filter_and_select(output, None, match=input_dict) if not entries: st.error("DUT {} -> Match Not Found {}".format( dut, input_dict)) ret_val = False return ret_val elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') if type(local_port) is list: local_port = list(local_port) else: local_port = [local_port] for port, rport, dname, nstate in zip(local_port, remote_port, device_name, neighbor_state): rest_url = rest_urls['show_udld_interface_state_get'].format(port) payload = get_rest(dut, rest_url=rest_url)['output'][ 'openconfig-udld-ext:state']['neighbors-info']['neighbor'] for neighbor in payload: if remote_port != None: if neighbor['state']['port-id'] != str(rport): ret_val = False if device_name != None: if neighbor['state']['device-name'] != str(dname).lower(): ret_val = False if neighbor_state != None: if neighbor['state']['status'].split(':')[1] != str( nstate).upper(): ret_val = False return ret_val
def verify_iccp_macs(dut, **kwargs): ''' Klish support not available Author: [email protected] Verify MACs learned in Mclag peers in ICCP cache :param dut: :param kwargs: :return: ''' ret_val = True ### This is ICCP dump for mac and no equivalent klish command, hence keep cli_type as click cli_type = 'click' #cli_type = kwargs.get('cli_type', st.get_ui_type(dut,**kwargs)) #cli_type = kwargs.get('cli_type', 'click') if 'cli_type' in kwargs: del kwargs['cli_type'] return_type = kwargs.get('return_type', 'BOOL') if 'return_type' in kwargs: del kwargs['return_type'] if cli_type == 'click': cmd = 'mclagdctl dump mac ' if 'domain_id' in kwargs: domain_id = kwargs['domain_id'] del kwargs['domain_id'] cmd += '-i {}'.format(domain_id) else: st.error("Mandatory argument domain id Not Found") return False output = st.show(dut, cmd) if len(output) == 0: st.error("Output is Empty") return False if return_type == 'NULL': ### Just display command output return mac_count = len(output) - 1 ### Create match dictionary from kargs,vlaue pair match = {} for key in kwargs: if kwargs.get(key, None) != None: match[key] = kwargs[key] if match != {}: ### Filter matching entries entries = utils.filter_and_select(output, None, match=match) if entries == []: ret_val = False mac_count = 0 st.error("Match NOT FOUND for {}.".format(match)) else: st.log("Match FOUND for {}.\n Output:{}".format(match, entries)) mac_count = len(entries) ### Return count if count in keywords if return_type == 'NUM': return mac_count if return_type == 'BOOL': return ret_val
def verify_ip_mroute(dut,**kwargs): """ Author: Sooriya G email : [email protected] :param dut: :param source: :type string or list :param group: :type string or list :param proto: :type protocol type in string or list :param iif: :type incoming interface as string or list :param oif: :type outgoing interface as list or string :param ttl: :type ttl value as list or string :param uptime :type uptime in list or string :param vrf :type vrfname as list or string :return: Usage pim.verify_ip_mroute(data.dut1,source='10.10.10.1',group='225.1.1.1',proto='STATIC',iif='Ethernet10', oif='Ethernet12',ttl='1',vrf='default') pim.verify_ip_mroute(data.dut1,source=['10.10.10.1','20.20.20.1'],group=['225.1.1.1','232.0.0.1'],proto=['STATIC','STATIC'] ,iif=['Ethernet10','Ethernet5'] , oif=['Ethernet12','Ethernet12'],ttl=['1','1'],vrf=['default','RED']) """ ret_val = True if 'vrf' in kwargs: vrf = kwargs['vrf'] del kwargs['vrf'] else: vrf = 'default' if vrf != 'default': cmd = 'show ip mroute vrf {}'.format(vrf) else: cmd = 'show ip mroute' skip_tmpl = kwargs.pop('skip_tmpl',False) if 'skip_error' in kwargs: skip_error = kwargs['skip_error'] del kwargs['skip_error'] else: skip_error = False output = st.show(dut,cmd,skip_error_check=skip_error,skip_tmpl=skip_tmpl, type='vtysh') if 'return_output' in kwargs: return output if len(output) == 0: st.error("Output is Empty") return False #Converting all kwargs to list type to handle single or list of mroute instances for key in kwargs: if type(kwargs[key]) is list: kwargs[key] = list(kwargs[key]) else: kwargs[key] = [kwargs[key]] #convert kwargs into list of dictionary input_dict_list =[] for i in range(len(kwargs[kwargs.keys()[0]])): temp_dict = {} for key in kwargs.keys(): temp_dict[key] = kwargs[key][i] input_dict_list.append(temp_dict) for input_dict in input_dict_list: entries = filter_and_select(output,None,match=input_dict) if not entries: st.error("DUT {} -> Match Not Found {}".format(dut,input_dict)) ret_val = False return ret_val
def verify_ip_multicast(dut,**kwargs): """ Author: Nagappa email : [email protected] :param dut: :param source: :param vrf :type vrfname as list or string :return: Usage pim.verify_ip_multicast(data.dut1,tot_dyn_mcast_routes='10',join_prune_holdtime='150',upstream_join_timer='70',vrf='default') """ ret_val = True if 'vrf' in kwargs: vrf = kwargs['vrf'] del kwargs['vrf'] else: vrf = 'default' if vrf != 'default': cmd = 'show ip multicast vrf {}'.format(vrf) else: cmd = 'show ip multicast' if 'skip_error' in kwargs: skip_error = kwargs['skip_error'] del kwargs['skip_error'] else: skip_error = False output = st.show(dut, cmd, skip_error_check=skip_error, type='vtysh') if 'return_output' in kwargs: return output if len(output) == 0: st.error("Output is Empty") return False #Converting all kwargs to list type to handle single or list of mroute instances for key in kwargs: if type(kwargs[key]) is list: kwargs[key] = list(kwargs[key]) else: kwargs[key] = [kwargs[key]] #convert kwargs into list of dictionary input_dict_list =[] for i in range(len(kwargs[kwargs.keys()[0]])): temp_dict = {} for key in kwargs.keys(): temp_dict[key] = kwargs[key][i] input_dict_list.append(temp_dict) for input_dict in input_dict_list: entries = filter_and_select(output,None,match=input_dict) if entries: st.log("DUT {} -> Match Found {} ".format(dut,input_dict)) else: st.error("DUT {} -> Match Not Found {}".format(dut,input_dict)) ret_val = False return ret_val
def verify_sag(dut, **kwargs): ''' Author: [email protected] Verify sag output - show <ip|ipv6> static-anycast-gateway :param dut: :param kwargs: Parameters can be ['ip_type'] ['mac', 'status', 'total', 'total_admin', 'total_oper'] ['gateway', 'interface', 'mask', 'vrf', 'admin', 'oper'] :return: Usage: verify_sag(dut1, total=10, mac='00:00:00:ba:ba:12', gateway='13.3.3.3', interface='Vlan20') verify_sag(dut1, status='enable', gateway='2001::15', ip_type='ipv6') ''' ret_val = True cli_type = kwargs.get('cli_type', st.get_ui_type(dut)) cli_type = "klish" if cli_type in ["rest-put", "rest-patch"] else cli_type ip_type = kwargs.get('ip_type', 'ip') kwargs.pop('ip_type', None) cmd = 'show {} static-anycast-gateway'.format(ip_type) output = st.show(dut, cmd, type=cli_type) if len(output) == 0: st.error("Output is Empty") return False if "return_output" in kwargs: return output list1 = ['mac', 'status', 'total', 'total_admin', 'total_oper'] list2 = ['gateway', 'interface', 'mask', 'vrf', 'admin', 'oper'] match = {} status_dict = {'disabled': 'disable', 'enabled': 'enable'} mac_dict = {'Not': ''} for k in list1: if kwargs.get(k, None) != None: match[k] = kwargs[k] if cli_type == 'klish': if kwargs.get('status', None) != None: if match['status'] in status_dict.keys(): match['status'] = status_dict[match['status']] if kwargs.get('mac', None) != None: if match['mac'] in mac_dict.keys(): match['mac'] = mac_dict[match['mac']] entries = filter_and_select(output, None, match=match) if match != {}: if entries == []: ret_val = False st.error("Match NOT FOUND for {}.".format(match)) else: st.log("Match FOUND for {}.".format(match)) # API can be enhanced to accept the list for all items in list2. match = {} for k in list2: if kwargs.get(k, None) != None: match[k] = kwargs[k] entries = filter_and_select(output, None, match=match) if match != {}: if entries == []: ret_val = False st.error("Match NOT FOUND for {}.".format(match)) else: st.log("Match FOUND for {}.".format(match)) return ret_val
def verify_vrrpv3(dut, **kwargs): """ Author:[email protected] :param interface: :type string :param vrid: :type string or integer :param version: :type string or interger :param vip: :type virtual-ip in string :param vmac: :type virtual-mac as string :param state: :type vrrp state as string :param config_prio: :type configured vrrp priority as integer or string :param current_prio: :type Current vrrp priority as integer or string :param adv_interval: :type advertrisement interval as integer or string :param track_interface_list: :type List of uplink track interfaces :param track_priority_list :type List of priorities for uplink tracking ports :param track_state_list :type List of states for uplink tracking ports :param preempt :type preempt state as string usage: verify_vrrpv3(dut1,vrid='1',interface='Vlan1000',state='Master',vip='10.0.0.10',track_interface_list=['Vlan10'],track_state_list=['Up'], track_priority_list=['10'],adv_interval=1,vmac='0000.5e00.0201',config_prio=90,current_prio=100,version=3,preempt='disabled') """ if 'interface' not in kwargs or 'vrid' not in kwargs: st.error("Mandatory arguments \'interface\' or \'vrid \' missing") return False cli_type = kwargs.get("cli_type", st.get_ui_type(dut)) if cli_type in ['rest-patch', 'rest-put']: cli_type = 'klish' if cli_type == 'click': cmd = "show vrrp6 {} {}".format(kwargs['interface'], kwargs['vrid']) else: cmd = "show vrrp6 interface {} vrid {}".format(kwargs['interface'], kwargs['vrid']) parsed_output = st.show(dut, cmd, type=cli_type) if len(parsed_output) == 0: st.error("OUTPUT is Empty") return False if 'return_output' in kwargs: return parsed_output for each in kwargs.keys(): match = {each: kwargs[each]} entries = filter_and_select(parsed_output, None, match) if not entries: st.error( "Match not found for {}: Expected - {} Actual - {} ".format( each, kwargs[each], parsed_output[0][each])) return False return True
def verify_vrrpv3_summary(dut, **kwargs): """ Author: Raghukumar Rampur email : [email protected] :param dut: :param interface: :type string or list :param vrid: :type string or list :param vip: :type virtual-ip in string or list :param state: :type vrrp state as string or list :param config_prio: :type configured vrrp priority as list or string :param current_prio: :type Current vrrp priority as list or string :return: Usage verify_vrrpv3_summary(dut1,vrid=['49','85'],state=['Master','Backup'], interface=['Vlan2996','Vlan2998'],vip=['73.73.73.66','85.85.85.71'], config_prio=[222,97],current_prio=[222,99]) verify_vrrpv3_summary(dut1,vrid='49',state='Master') """ ret_val = True cli_type = kwargs.get("cli_type", st.get_ui_type(dut)) if cli_type in ['rest-patch', 'rest-put']: cli_type = 'klish' output = st.show(dut, 'show vrrp6', type=cli_type) if len(output) == 0: st.error("Output is Empty") return False if 'return_output' in kwargs: return output #Converting all kwargs to list type to handle single or list of vrrp instances for key in kwargs: if type(kwargs[key]) is list: kwargs[key] = list(kwargs[key]) else: kwargs[key] = [kwargs[key]] #convert kwargs into list of dictionary input_dict_list = [] for i in range(len(kwargs[kwargs.keys()[0]])): temp_dict = {} for key in kwargs.keys(): temp_dict[key] = kwargs[key][i] input_dict_list.append(temp_dict) for input_dict in input_dict_list: entries = filter_and_select(output, None, match=input_dict) if not entries: st.error("DUT {} -> Match Not Found {}".format(dut, input_dict)) ret_val = False return ret_val
def verify_copp_actions(dut,**kwargs): """ Author: Gangadhara Sahu ([email protected]) verify_copp_actions(dut=dut1,copp_group=["copp-system-ospf","copp-system-lldp"],trap-action=["copy","trap"]) verify_copp_actions(dut=vars.D1,copp_agroup="copp-user-sflow-action",trap_action="trap",cir="6000",cbs="6070",trap_queue="3") To verify copp action groups :param dut: :param copp_agroup: :param trap_action: :param trap_queue: :param trap_priority: :param cir: :param cbs: :param meter_type: :param policer_mode: :param pol_red_action: :param return_output: if this arg used API will return the class entries matching copp class :return: True or False """ cli_type = kwargs.pop('cli_type', st.get_ui_type(dut,**kwargs)) if cli_type == 'klish': output = st.show(dut,"show copp actions",type="klish") elif cli_type in ['rest-put','rest-patch']: rest_urls = st.get_datastore(dut, "rest_urls") url = rest_urls['show_copp_actions'].format(kwargs['copp_agroup']) response = get_rest(dut, rest_url=url) output = parse_show_copp_actions(response) elif cli_type == 'click': st.error("cli_type click is not not supported") return False if 'copp_agroup' not in kwargs: st.error("Mandetory arg copp_agroup is not present") return False if len(output) == 0: st.error("Output is Empty or copp group is not found through rest GET") return False if "return_output" in kwargs: return filter_and_select(output,None,match={'copp_agroup':kwargs['copp_agroup']})[0] ret_val = True if len(kwargs.keys()) > 0: #Converting all kwargs to list type to handle single or list of instances input_dict_list =[] for key in kwargs: if type(kwargs[key]) is list: kwargs[key] = list(kwargs[key]) else: kwargs[key] = [kwargs[key]] #convert kwargs into list of dictionary for i in range(len(kwargs[kwargs.keys()[0]])): temp_dict = {} for key in kwargs.keys(): temp_dict[key] = kwargs[key][i] input_dict_list.append(temp_dict) for input_dict in input_dict_list: entries = filter_and_select(output,None,match=input_dict) if entries: st.log("DUT {} -> Match Found {} ".format(dut,input_dict)) else: st.error("DUT {} -> Match Not Found {}".format(dut,input_dict)) ret_val = False return ret_val
def verify_remote_syslog_server(dut, **kwargs): """ Verifying syslog server :param dut: :param host: :param source_intf: :param remote_port: :param vrf: :return: log_obj.verify_remote_syslog_server(dut = dut1, host = '10.59.130.43') log_obj.verify_remote_syslog_server(dut = data.dut1_client, host = dut1_dut2_ip[0], source_intf = 'Ethernet48') log_obj.verify_remote_syslog_server(dut = data.dut1_client, host = dut1_dut2_ip[0], source_intf = 'Ethernet48', remote_port = 514) log_obj.verify_remote_syslog_server(dut = data.dut1_client, host = dut2_dut1_ip[0], source_intf = 'Ethernet48', cli_type='rest-put') log_obj.verify_remote_syslog_server(dut = data.dut1_client, host = dut2_dut1_ip[0], source_intf = 'Ethernet48', vrf = 'mgmt', cli_type='rest-put') """ st.log('Verify Syslog server') host = kwargs.get('host',None) source_intf = kwargs.get('source_intf',None) remote_port = kwargs.get('remote_port',None) vrf = kwargs.get('vrf',None) cli_type = kwargs.pop('cli_type', st.get_ui_type(dut,**kwargs)) if host is None: st.error("Mandatory parameter hostname/IP address not sent") return False if cli_type == 'klish': st.log("show logging servers") command = "show logging servers" output = st.show(dut,command,type = "klish",config = "false",skip_error_check = "True") entry = filter_and_select(output, None, {"host": host}) for val in entry: if val['host'] != host: st.log("Host is not as expected {}".format(host)) return False if source_intf != None and val['srcintf'] != source_intf: st.log("Source Interface is not as expected {}".format(source_intf)) return False if remote_port != None and val['port'] != remote_port: st.log("Remote port is not as expected {}".format(remote_port)) return False if vrf != None and val['vrf'] != vrf: st.log("Vrf is not as expected {}".format(vrf)) return False return True elif cli_type == ['rest-patch','rest-put']: rest_urls = st.get_datastore(dut,'rest_urls') rest_url = rest_urls['config_remote_server'].format(str(host)) payload = get_rest(dut, rest_url=rest_url)['output']['openconfig-system:config'] if payload['host'] != str(host): st.log("Host is not as expected {}".format(host)) return False if source_intf != None: if payload['openconfig-system-ext:source-interface'] != str(source_intf): st.log("Source Interface is not as expected {}".format(source_intf)) return False if remote_port != None: if payload['remote-port'] != int(remote_port): st.log("Remote port is not as expected {}".format(remote_port)) return False if vrf != None: if payload['openconfig-system-ext:vrf-name'] != str(vrf): st.log("Vrf is not as expected {}".format(vrf)) return False return True else: st.log("Unsupported cli")
def verify_pim_show(dut,**kwargs): """ Author: Sooriya G email : [email protected] :param dut :type string :param cmd_type :type string (CLI type) :API type: "show ip pim neighbor" :arg_list: interface,neighbor,dr_priority,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,interface=['Ethernet24','Ethernet10'],neighbor=['10.10.10.2','10.10.10.3'],dr_priority=['10','20'],vrf='RED',cmd_type='neighbor') pim.verify_pim_show(dut1,interface='Ethernet24',neighbor='10.10.10.2',dr_priority='10',vrf='RED',cmd_type='neighbor') :API type: "show ip pim interface" :arg_list: interface,state,address,nbr_count,dr,fhrif_channels,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='interface',interface=['Ethernet24','pimreg'],state=['up']*2,address=['10.10.10.1','0.0.0.0'], nbr_count=[1,0],dr=['10.10.10.2','local'],fhr=[0,0],if_channels=[0,0],vrf='default') pim.verify_pim_show(dut1,cmd_type='interface',interface='Ethernet24',state='up',address='10.10.10.1',nbr_count=1,dr='10.10.10.2',fhr=0,if_channels=0) :API type: "show ip pim state " :arg_list:source,group,iif,flag,installed' :arg_type: String or list :Usage: pim.verify_pim_show(dut1,type='state',source='10.10.10.2',group='232.1.1.2',iif='Ethernet24',oif=[['Ethernet10','Vlan100']],flag=[['IJ'],['J']]) :API type: "show ip pim interface traffic " :arg_list:interface,vrf,hello_rx,hello_tx,join_rx,join_tx,prune_rx,prune_tx,register_rx,register_tx,register_stop_tx,register_stop_rxassert_rxassert_tx,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='interface traffic',interface='Ethernet24',vrf='default',hello_rx=32,hello_tx=32,join_rx=0,join_tx=0, prune_rx=0,prune_tx=0,register_rx=0,register_tx=0,register_stop_tx=0, register_stop_rx=0,assert_rx=0,assert_tx=0) :API type: "show ip pim nexthop" :arg_list: source,interface,nexthop,registered_count,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='nexthop',source=['10.10.10.2'],interface=['Ethernet24'],nexthop=['10.10.10.2'],registered_count=1) :API type: "show ip pim assert " :arg_list: interface,address,source,group,state,winner,uptime,timer,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='assert',interface=[],address=[],source=[],group=[],state=[],winner=[],uptime=[],timer=[]) pim.verify_pim_show(dut1,cmd_type='assert',interface='',address='',source='',group='',state='',winner='',uptime='',timer='') :API type: "show ip pim assert-internal " :arg_list: interface,address,source,group,ca,eca,atd,eatd,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='assert-internal',interface=[],address=[],source=[],group=[],ca=[],eca=[],atd=[],eatd=[],vrf='RED') pim.verify_pim_show(dut1,cmd_type='assert-internal',interface='',address='',source='',group='',ca='',eca='',atd='',eatd='') :API type: "show ip pim assert-metric " :arg_list: interface,address,source,group,rpt,pref,metric,address2,vrf :arg_type: :Usage: pim.verify_pim_show(dut1,cmd_type='assert-metric',interface='',address='',source='',group='',rpt='',pref='',metric='',address2='',vrf='RED') pim.verify_pim_show(dut1,cmd_type='assert-metric',interface=[],address=[],source=[],group=[],rpt=[],pref=[],metric=[],address2=[],vrf='RED') :API type: "show ip pim assert-winner-metric " :arg_list: interface,address,source,group,rpt,pref,metric,address2,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='assert-winner-metric',interface='',address='',source='',group='',rpt='',pref='',metric='',address2='',vrf='RED') pim.verify_pim_show(dut1,cmd_type='assert-winner-metric',interface=[],address=[],source=[],group=[],rpt=[],pref=[],metric=[],address2=[],vrf='RED') :API type: "show ip pim upstream " :arg_list: iif,source,group,state,uptime,jointimer,rstimer,katimer,refcnt,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='upstream',source=[],group=[],state=[],uptime=[],jointimer=[],rstimer=[],katimer=[],refcnt=[],vrf='default') pim.verify_pim_show(dut1,cmd_type='upstream',source='',group='',state='',uptime='',jointimer='',rstimer='',katimer='',refcnt='',vrf='RED') :API type: "show ip pim upstream-join-desired " :arg_list: interface,source,group,lostassert,joins,piminclude,joindesired,evaljd,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='upstream-join-desired',interface=[],source=[],group=[],lostassert=[],joins=[],piminclude=[],joindesired=[],evaljd=[],vrf='default') pim.verify_pim_show(dut1,cmd_type='upstream-join-desired',interface='',source='',group='',lostassert='',joins='',piminclude='',joindesired='',evaljd='',vrf='RED') :API type: "show ip pim upstream-rpf " :arg_list: source,group,rpfiface,ribnexthop,rpfaddress,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='upstream-rpf',source=[],group=[],rpfiface=[],ribnexthop=[],rpfaddress=[],vrf='RED') pim.verify_pim_show(dut1,cmd_type='upstream-rpf',source='',group='',rpfiface='',ribnexthop='',rpfaddress='',vrf='default') :API type: "show ip pim join " :arg_list: interface,address,source,group,state,uptime,expire,prune,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='join',interface=[],address=[],source=[],group=[],state=[],uptime=[],expire=[],prune=[],vrf='RED') pim.verify_pim_show(dut1,cmd_type='join',interface='',address='',source='',group='',state='',uptime='',expire='',prune='',vrf='RED') :API type: "show ip pim secondary " :arg_list: interface,address,neighbor,secondary,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='secondary',interface=[],address=[],neighbor=[],secondary=[],vrf='RED') pim.verify_pim_show(dut1,cmd_type='secondary',interface='',address='',neighbor='',secondary='',vrf='RED') :API type: "show ip pim local-membership " :arg_list: interface,address,source,group,membership,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='local-membership',interface=[],address=[],source=[],group=[],membership=[],vrf='RED') pim.verify_pim_show(dut1,cmd_type='local-membership',interface='',address='',source='',group='',membership='',vrf='RED') :API type: "show ip pim rpf" :arg_list: cache_ref_delay,cache_ref_timer,cache_ref_reqs,cache_ref_events,cache_ref_last,nexthop_lookup,nexthop_lookup_avoid, source,group,rpfiface,ribnexthop,rpfaddress,metric,pref,vrf :arg_type: String or list :Usage: pim.verify_pim_show(dut1,cmd_type='rpf',cache_ref_delay='',cache_ref_timer='',cache_ref_reqs='' ,cache_ref_events='',cache_ref_last='',nexthop_lookup='',nexthop_lookup_avoid='' source=[],group=[],rpfiface=[],ribnexthop=[],rpfaddress=[],metric=[],pref=[],vrf='RED') """ ret_val = True if 'cmd_type' in kwargs: cmd_type = kwargs['cmd_type'] del kwargs['cmd_type'] else: cmd_type = 'neighbor' if 'vrf' in kwargs: vrf_name = kwargs['vrf'] del kwargs['vrf'] else: vrf_name = 'default' if vrf_name != 'default': cmd = 'show ip pim vrf {} {}'.format(vrf_name,cmd_type) else: cmd = "show ip pim {}".format(cmd_type) skip_tmpl = kwargs.pop('skip_tmpl', False) if 'skip_error' in kwargs: skip_error = kwargs['skip_error'] del kwargs['skip_error'] else: skip_error = False output = st.show(dut,cmd,skip_error_check=skip_error,skip_tmpl=skip_tmpl, type='vtysh') if 'return_output' in kwargs: return output if len(output) == 0: st.error("Output is Empty") return False common_param = ['registered_count','cache_ref_delay','cache_ref_timer','cache_ref_reqs','cache_ref_events',\ 'cache_ref_last','nexthop_lookup','nexthop_lookup_avoid'] for key in common_param: if key in kwargs: if str(kwargs[key]) != str(output[0][key]): st.error("Match not Found for {}: Expected - {} Actual- {}".format(key,kwargs[key],output[0][key])) ret_val = False else: st.log("Match Found for {}: Expected - {} Actual- {}".format(key,kwargs[key],output[0][key])) del kwargs[key] if cmd_type == 'state': for entry in output: entry_index = output.index(entry) if entry['oif'] != '': pattern = re.compile(r'\w+') result = pattern.findall(entry['oif']) res = result[::2] + result[1::2] res_by_2 = int(len(res)/2) oif_list = [str(oif) for oif in res[:res_by_2]] flag_list = [str(flag) for flag in res[res_by_2:]] output[entry_index]['oif'] = oif_list output[entry_index]['flag'] = flag_list #Converting all kwargs to list type to handle single or list of mroute instances for key in kwargs: if type(kwargs[key]) is list: kwargs[key] = list(kwargs[key]) else: kwargs[key] = [kwargs[key]] #convert kwargs into list of dictionary input_dict_list =[] for i in range(len(kwargs[kwargs.keys()[0]])): temp_dict = {} for key in kwargs.keys(): temp_dict[key] = kwargs[key][i] input_dict_list.append(temp_dict) for input_dict in input_dict_list: entries = filter_and_select(output,None,match=input_dict) if not entries: st.error("DUT {} -> Match Not Found {}".format(dut,input_dict)) ret_val = False return ret_val
def verify_interfaces(dut, **kwargs): ''' Author: [email protected] Verify mclag interfaces output :param dut: :param kwargs: Parameters can be <domain_id|mclag_intf|mclag_intf_local_state|mclag_intf_peer_state| 'mclag_intf_l3_status'|'isolate_peer_link'|'traffic_disable'|cli_type> :return: Usage: verify_mclag_interfaces(dut1,domain_id=10, mclag_intf='PortChannel20', mclag_intf_local_state="Up", mclag_intf_peer_state="Up", \ isolate_peer_link='Yes', traffic_disable='No') verify_mclag_interfaces(dut1,domain_id=10, mclag_intf='PortChannel20', mclag_intf_local_state="Up", mclag_intf_peer_state="Up", \ mclag_intf_l3_status='No',isolate_peer_link='Yes', traffic_disable='No') ''' ret_val = True cli_type = kwargs.get('cli_type', st.get_ui_type(dut, **kwargs)) cli_type = "klish" if cli_type in ["rest-put", "rest-patch"] else cli_type if 'cli_type' in kwargs: del kwargs['cli_type'] if 'domain_id' not in kwargs or 'mclag_intf' not in kwargs: st.error("Mandatory arguments Not Found Expect domain_id & mclag_intf") return False else: domain_id = kwargs['domain_id'] del kwargs['domain_id'] mclag_intf = kwargs['mclag_intf'] del kwargs['mclag_intf'] if cli_type == 'click': st.banner( "Getting Mclag Interface Local state for: {}".format(mclag_intf), delimiter='-') cmd1 = 'mclagdctl dump portlist local' cmd1 += ' -i {}'.format(domain_id) output1 = st.show(dut, cmd1) if len(output1) == 0: st.error("Output is Empty") return False ### Process Local Mclag Interface output entries = utils.filter_and_select(output1, None, match={'mclag_intf': mclag_intf}) args1 = [ 'mclag_intf_local_state', 'mclag_intf_l3_status', 'isolate_peer_link', 'traffic_disable', 'mclag_mac' ] for key in args1: if key in kwargs.keys(): if str(kwargs[key]) != str(entries[0][key]): st.error( "{}:==> Match NOT FOUND for {} : Expected -<{}> Actual-<{}> " .format(mclag_intf, key, kwargs[key], entries[0][key])) ret_val = False else: st.log( "{}:==> Match FOUND for {} : Expected -<{}> Actual-<{}> " .format(mclag_intf, key, kwargs[key], entries[0][key])) st.banner( "Getting Mclag Interface Peer state for: {}".format(mclag_intf), delimiter='-') cmd2 = 'mclagdctl dump portlist peer' cmd2 += ' -i {}'.format(domain_id) output2 = st.show(dut, cmd2) if len(output2) == 0: st.error("Output is Empty") return False ### Process Local Mclag Interface output entries = utils.filter_and_select(output2, None, match={'mclag_intf': mclag_intf}) args2 = ['mclag_intf_peer_state'] for key in args2: if key in kwargs.keys(): if str(kwargs[key]) != str(entries[0][key]): st.error( "{}:==> Match NOT FOUND for {} : Expected -<{}> Actual-<{}> " .format(mclag_intf, key, kwargs[key], entries[0][key])) ret_val = False else: st.log( "{}:==> Match FOUND for {} : Expected -<{}> Actual-<{}> " .format(mclag_intf, key, kwargs[key], entries[0][key])) elif cli_type == 'klish': mintf = get_interface_number_from_name(mclag_intf) cmd = 'show mclag interface {} {}'.format(mintf['number'], domain_id) output = st.show(dut, cmd, type='klish') if len(output) == 0: st.error("Output is Empty") return False # In klish, the value is always lowercase - changing from 'Up' to 'up'. args_modif = ['mclag_intf_local_state', 'mclag_intf_peer_state'] for key in args_modif: if key in kwargs: kwargs[key] = kwargs[key].lower() args1 = [ 'mclag_intf_local_state', 'mclag_intf_peer_state', 'isolate_peer_link', 'traffic_disable' ] for key in args1: if key in kwargs.keys(): if str(kwargs[key]) != str(output[0][key]): st.error( ":==> Match NOT FOUND for {} : Expected -<{}> Actual-<{}> " .format(key, kwargs[key], output[0][key])) ret_val = False else: st.log( ":==> Match FOUND for {} : Expected -<{}> Actual-<{}> " .format(key, kwargs[key], output[0][key])) return ret_val
def verify_crm_thresholds(dut, family, thresholdtype=None, highthreshold=None, lowthreshold=None, cli_type=""): """ To verify the CRM Threshold parameters Author : Prudvi Mangadu ([email protected]) :param dut: :param family: :param thresholdtype: :param highthreshold: :param lowthreshold: :param cli_type: click or klish designation: :return: """ family_list = crm_get_family_list(dut) if family not in family_list: st.log("CRM config for {} is not supported -- ignoring".format(family)) return True cli_type = st.get_ui_type(dut, cli_type=cli_type) output = get_crm_thresholds(dut, family, cli_type) # Handling few crm family cli commands for verify if cli_type in ['click', 'klish']: if family == "fdb": family = 'fdb_entry' if family == "dnat": family = 'dnat_entry' if family == "ipmc": family = 'ipmc_entry' if family == "snat": family = 'snat_entry' if family == "acl_group_entry": family = 'acl_entry' if family == "acl_group_counter": family = 'acl_counter' if family == 'nexthop_group_object': family = 'nexthop_group' entries = filter_and_select(output, None, {"resourcename": family}) if not entries: st.error( "No Entry found for given family in the table - {}".format(family)) return False if thresholdtype and not filter_and_select(entries, None, { "resourcename": family, "thresholdtype": thresholdtype }): st.error("Configured and Provided thresholdtype is not match.") return False if lowthreshold and not filter_and_select(entries, None, { "resourcename": family, 'lowthreshold': lowthreshold }): st.error("Configured and Provided lowthreshold is not match.") return False if highthreshold and not filter_and_select(entries, None, { "resourcename": family, "highthreshold": highthreshold }): st.error("Configured and Provided highthreshold is not match.") return False return True
def check_bgp_session(dut, nbr_list=[], state_list=[], vrf_name='default', **kwargs): """ Author:[email protected] :param nbr_list: :type list of BGPneighbors :param state_list: :type list of states :param dut: :type dut: :return: :rtype: """ ret_val = True cli_type = kwargs.pop('cli_type', st.get_ui_type(dut, **kwargs)) # if cli_type in ['rest-patch', 'rest-put']: cli_type = 'klish' output = [] if cli_type == 'click': if vrf_name == 'default': output = st.show(dut, 'show ip bgp summary', type='vtysh') else: output = st.show(dut, 'show ip bgp vrf {} summary'.format(vrf_name), type='vtysh') elif cli_type == 'klish': family = kwargs.pop('family', 'ipv4') if vrf_name == 'default': output = st.show(dut, 'show bgp {} unicast summary'.format(family), type='klish') else: output = st.show(dut, 'show bgp {} unicast vrf {} summary'.format( family, vrf_name), type='klish') elif cli_type in ["rest-put", "rest-patch"]: family = kwargs.pop('family', 'ipv4') if family == "ipv4": output = show_bgp_ipv4_summary_vtysh(dut, vrf_name, cli_type=cli_type) else: output = show_bgp_ipv6_summary_vtysh(dut, vrf_name, cli_type=cli_type) if len(output) != 0: for nbr, state in zip(nbr_list, state_list): match = {'neighbor': nbr} entry = filter_and_select(output, None, match) if not bool(entry): st.log("BGP Neighbor entry {} is not found".format(nbr)) ret_val = False for entries in entry: if state == 'Established': if entries['state'].isdigit( ) or entries['state'] == "ESTABLISHED": st.log( "BGP Neighbor {} in Established state".format(nbr)) else: st.error( "BGP Neighbor {} state check Failed. Expected:{} Actual :{} " .format(nbr, state, entries['state'])) ret_val = False else: if str(state).upper() == str(entries['state']).upper(): st.log( "BGP Neighbor {} check passed. Expected : {} Actual {}" .format(nbr, state, entries['state'])) else: st.error( "BGP Neighbor {} state check Failed. Expected:{} Actual :{} " .format(nbr, state, entries['state'])) ret_val = False else: st.error("Output is empty") ret_val = False return ret_val
def verify_crm_resources(dut, family, availablecount=None, usedcount=None, tableid=None, bindpoint=None, stage=None, cli_type=""): """ To verify the CRM Resources parameters Author : Prudvi Mangadu ([email protected]) :param dut: :param family: :param availablecount: :param usedcount: :param tableid: :param bindpoint: :param stage: :param cli_type: click or klish designation: :return: """ cli_type = st.get_ui_type(dut, cli_type=cli_type) if family == 'acl_entry': family = 'acl_table_entry' elif family == 'acl_counter': family = 'acl_table_counter' elif family == 'acl_table_stats': family = 'acl_table' output = get_crm_resources(dut, family, cli_type) # Handling few crm family cli commands for verify if family == "fdb": family = 'fdb_entry' if family == "dnat": family = 'dnat_entry' if family == "ipmc": family = 'ipmc_entry' if family == "snat": family = 'snat_entry' if family == "acl_group_entry": family = 'acl_entry' if family == "acl_group_counter": family = 'acl_counter' if family == "acl_table_counter": family = 'acl_counter' if family == "acl_table_entry": family = 'acl_entry' if family == 'nexthop_group_object': family = 'nexthop_group' entries = filter_and_select(output, None, {"resourcename": family}) if not entries: st.error( "No Entry found for given family in the table - {}".format(family)) return False if availablecount and not filter_and_select( entries, None, { "resourcename": family, "availablecount": availablecount }): st.error("Available and Provided availablecount is not match.") return False if usedcount and not filter_and_select(entries, None, { "resourcename": family, 'usedcount': usedcount }): st.error("Available and Provided usedcount is not match.") return False if tableid and not filter_and_select(entries, None, { "resourcename": family, "tableid": tableid }): st.error("Available and Provided tableid is not match.") return False if bindpoint and not filter_and_select(entries, None, { "resourcename": family, "bindpoint": bindpoint }): st.error("Available and Provided bindpoint is not match.") return False if stage and not filter_and_select(entries, None, { "resourcename": family, "stage": stage }): st.error("Available and Provided stage is not match.") return False return True
def verify_udld_statistics(dut, **kwargs): """ Author: Chandra Sekhar Reddy email : [email protected] :param dut: :param udld_interface: :type String or list :param udld_tx :type integer or list of integers :param udld_rx :type integer or list of integers :param udld_errors :type integer or list of integers :return: Usage verify_udld_statistics(dut1,udld_interface=['Ethernet24','Ethernet32'],udld_tx=[10,10],udld_rx=[10,10],udld_errors=[10,10]) verify_udld_statistics(dut1,udld_interface='Ethernet24','Ethernet32',udld_tx=10,udld_rx=10,udld_errors=10) udld.verify_udld_statistics(dut1,udld_interface='Ethernet41',udld_tx=5708,udld_rx=5708,udld_errors=0,cli_type='rest-put') """ cli_type = kwargs.pop('cli_type', st.get_ui_type(dut)) udld_interface = kwargs.get('udld_interface', None) udld_tx = kwargs.get('udld_tx', None) udld_rx = kwargs.get('udld_rx', None) #udld_errors = kwargs.get('udld_errors',None) #Converting all kwargs to list type to handle single or list of udld stats for key in kwargs: if type(kwargs[key]) is list: kwargs[key] = list(kwargs[key]) else: kwargs[key] = [kwargs[key]] if cli_type == 'klish' or cli_type == 'click': if len(kwargs['udld_interface']) > 1: cmd = "show udld statistics" else: cmd = "show udld statistics interface {}".format( kwargs['udld_interface']) output = st.show(dut, cmd, type="klish", config="false") if 'return_output' in kwargs: return output if len(output) == 0: st.error("Output is Empty") return False #convert kwargs into list of dictionary input_dict_list = [] for i in range(len(kwargs[kwargs.keys()[0]])): temp_dict = {} for key in kwargs.keys(): temp_dict[key] = kwargs[key][i] input_dict_list.append(temp_dict) for input_dict in input_dict_list: entries = filter_and_select(output, None, match=input_dict) if not entries: st.error("DUT {} -> Match Not Found {}".format( dut, input_dict)) ret_val = False return ret_val elif cli_type in ['rest-patch', 'rest-put']: rest_urls = st.get_datastore(dut, 'rest_urls') if type(udld_interface) is list: udld_interface = list(udld_interface) else: udld_interface = [udld_interface] for intf in udld_interface: rest_url = rest_urls['show_udld_interface_counters_get'].format( intf) payload = get_rest( dut, rest_url=rest_url)['output']['openconfig-udld-ext:counters'] if udld_tx != None: if payload['pdu-sent'] != int(udld_tx): ret_val = False if udld_rx != None: if payload['pdu-received'] != int(udld_rx): ret_val = False return ret_val
def verify_ip_igmp(dut,**kwargs): """ Author: Sooriya G email : [email protected] :param dut :type string :param vrf :type string :param cmd_type :type string (CLI type) :param cli_type :type string :API type: "show ip igmp groups" :arg_list: 'interface', 'address', 'group', 'mode', 'timer', 'source_count', 'version', 'uptime' :arg_type: String or list :Usage: verify_ip_igmp(dut=data.dut1,cmd_type='groups',interface='Ethernet45',address='10.1.1.1',mode='INCL',group='225.1.1.1',version='2') :API type: "show ip igmp sources" :arg_list: 'interface', 'address', 'source', 'group', 'timer', 'fwd', 'uptime' :arg_type: String or list :Usage: verify_ip_igmp(dut=data.dut1,cmd_type='sources',interface='Ethernet45',address='10.1.1.1',source='20.1.1.1',group='225.1.1.1',vrf='RED') :API type: "show ip igmp groups retransmissions" :arg_list: 'interface', 'address', 'group', 'ret_timer', 'counter', 'ret_sources' :arg_type: String or list :Usage: verify_ip_igmp(dut=data.dut1,cmd_type='groups retransmissions',interface='Ethernet45',address='10.1.1.1',counter='0',group='225.1.1.1',ret_sources='3') :API type: "show ip igmp sources retransmissions" :arg_list: 'interface', 'address', 'group', 'source', 'counter' :arg_type: String or list :Usage: verify_ip_igmp(dut=data.dut1,cmd_type='sources retransmissions',interface='Ethernet45',address='10.1.1.1',source='20.1.1.2',group='225.1.1.1',counter=10) :API type: "show ip igmp join" :arg_list: 'interface', 'address', 'source', 'group', 'socket', 'uptime' :arg_type: String or list :Usage: verify_ip_igmp(dut=data.dut1,cmd_type='join',interface='Ethernet45',address='10.1.1.1',source='20.1.1.2',group='225.1.1.1') """ ret_val = True if 'cmd_type' in kwargs: cmd_type = kwargs['cmd_type'] del kwargs['cmd_type'] else: cmd_type = 'groups' if 'vrf' in kwargs: vrf_name = kwargs['vrf'] del kwargs['vrf'] else: vrf_name = 'default' if vrf_name != 'default': cmd = 'show ip igmp vrf {} {}'.format(vrf_name,cmd_type) else: cmd = "show ip igmp {}".format(cmd_type) if 'skip_error' in kwargs: skip_error = kwargs['skip_error'] del kwargs['skip_error'] else: skip_error = False cli_type = kwargs.pop('cli_type','click') if cli_type == 'click': cli_type = 'vtysh' output = st.show(dut,cmd,skip_error_check=skip_error, type=cli_type) if 'return_output' in kwargs: return output if len(output) == 0: st.error("Output is Empty") return False if 'entry' in kwargs: entry_list = kwargs['entry'] del kwargs['entry'] else: entry_list = [True]*len(kwargs['group']) #Converting all kwargs to list type to handle single or list of mroute instances for key in kwargs: if type(kwargs[key]) is list: kwargs[key] = list(kwargs[key]) else: kwargs[key] = [kwargs[key]] #convert kwargs into list of dictionary input_dict_list =[] for i in range(len(kwargs[kwargs.keys()[0]])): temp_dict = {} for key in kwargs.keys(): temp_dict[key] = kwargs[key][i] input_dict_list.append(temp_dict) for input_dict,entry in zip(input_dict_list,entry_list): entries = filter_and_select(output,None,match=input_dict) if entries: if entry is False: st.error("DUT {} -> Match Found {} which is not expected".format(dut,input_dict)) ret_val = False else: if entry is False: st.log("DUT {} -> Match Not Found {} as expected".format(dut, input_dict)) else: st.error("DUT {} -> Match Not Found {}".format(dut,input_dict)) ret_val = False return ret_val