def test_ft_vlan_delete_with_member(): """ Author: Surendra Kumar Vella ([email protected]) Verify that user is not able to delete a valn till its members are deleted """ vars = st.ensure_min_topology("D1T1:1") st.log( "Adding TGen connected interfaces to newly created vlan in tagging mode." ) if not vlan.add_vlan_member(vars.D1, sc_data.vlan, [vars.D1D2P1], tagging_mode=True, cli_type=sc_data.cli_type): st.report_fail("vlan_tagged_member_fail", vars.D1D2P1, sc_data.vlan) st.log("checking whether vlan with member is deleted or not ") if not st.is_community_build(vars.D1): if vlan.delete_vlan(vars.D1, sc_data.vlan, cli_type="click"): st.report_fail("vlan_deletion_successfull_albiet_having_member", sc_data.vlan) if not vlan.delete_vlan_member( vars.D1, sc_data.vlan, vars.D1D2P1, cli_type=sc_data.cli_type): st.report_fail("vlan_tagged_member_fail", vars.D1D2P1, sc_data.vlan) else: if not vlan.delete_vlan(vars.D1, sc_data.vlan, cli_type="click"): st.report_fail("vlan_delete_fail", sc_data.vlan) st.log("deleting the vlan after its member deletion") st.report_pass("test_case_passed")
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 vlan_module_prolog(): """ Module prolog for module configuration :return: """ st.log("Creating vlan in device and adding members ...") vlan.create_vlan_and_add_members(sc_data.vlan_data, cli_type=sc_data.cli_type) if not st.is_community_build(vars.D1): st.banner("Configuring BUM Storm control on interfaces") interface_list = [vars.D1T1P1, vars.D1T1P2] storm_control_type = [ "broadcast", "unknown-multicast", "unknown-unicast" ] for interface in interface_list: for stc_type in storm_control_type: scapi.config(vars.D1, type=stc_type, action="add", interface_name=interface, bits_per_sec=sc_data.kbps, cli_type="click") if not scapi.verify_config(vars.D1, interface_name=interface, type=stc_type, rate=sc_data.kbps, cli_type="click"): st.report_fail("storm_control_config_verify_failed", stc_type, interface)
def set_status(dut, portlist, status): """ :param dut: :type dut: :param portlist: :type portlist: :param status: "shutdown" or "startup" :type status: string :return: :rtype: """ if '-' in portlist: st.config(dut, "config interface {} {}".format(status, portlist)) return if not st.is_community_build(): try: port = ",".join(portlist) return st.config(dut, "config interface {} {}".format(status, port)) except Exception as exp: st.warn("Failed to execute {} command - try alternative".format( status)) for port in portlist: try: st.config(dut, "config interface {} {}".format(status, port)) except ValueError as ex: st.warn("Failed to execute {} command - try alternative".format( status)) st.config(dut, "config interface {} {}".format(port, status)) return ""
def vlan_postconfig(): if not st.is_community_build(vars.D1): mac_obj.clear_mac(vars.D1, port=vars.D1T1P1, vlan=data.vlan) else: mac_obj.clear_mac(vars.D1) vlan_obj.delete_vlan_member(vars.D1, data.vlan, [vars.D1T1P1, vars.D1T1P2]) vlan_obj.delete_vlan(vars.D1, data.vlan)
def f(dut): if st.get_device_type(dut) in ["sonic", "vsonic"]: if not st.is_community_build(): st.show(dut, "show system status", skip_error_check=True, skip_tmpl=True)
def snmp_post_config(): """ SNMP post config """ snmp_obj.restore_snmp_config(vars.D1) if not st.is_community_build(): ipfeature.configure_loopback(vars.D1, loopback_name="Loopback0", config="no")
def clear_interface_counters(dut): """ Clear interface counters Author : Prudvi Mangadu ([email protected]) :param dut: :return: """ if st.is_community_build(): return st.config(dut, "sonic-clear counters") else: return st.show(dut, "show interfaces counters -c")
def show_specific_interface_counters(dut, interface_name): """ API to fetch the specific interface counters :param dut: :param interface_name: :return: """ command = "show interfaces counters -a -i {}".format(interface_name) if st.is_community_build(): command = "show interfaces counters -a | grep -w {}".format( interface_name) output = st.show(dut, command) st.log(output) return output
def storm_control_func_hooks(request): bum_test_functions = [ "test_ft_stormcontrol_verification", "test_ft_stormcontrol_portchannel_intf", "test_ft_stormcontrol_incremental_bps_max_vlan", "test_ft_stormcontrol_fast_reboot", "test_ft_stormcontrol_warm_reboot" ] if request.function.func_name in bum_test_functions: platform_check() yield if request.function.func_name == "test_ft_vlan_delete_with_member": if st.is_community_build(vars.D1): vlan.create_vlan_and_add_members(sc_data.vlan_data, cli_type=sc_data.cli_type)
def _clear_vlan_configuration_helper(dut_list, cli_type="click"): """ Find and clear VLAN and its Members. Author : Prudvi Mangadu ([email protected]) :param dut_list: :return: """ dut_li = list(dut_list) if isinstance(dut_list, list) else [dut_list] for dut in dut_li: st.log("############## {} : VLAN Cleanup ################".format(dut)) if cli_type == 'click': output = show_vlan_config(dut) if st.is_community_build(): (vlans, commands) = ({}, []) for eac in output: (vid, member) = (eac['vid'], eac['member']) if vid: vlans[vid] = 1 if member: command = "config vlan member del {} {}".format( vid, member) commands.append(command) for vid in vlans.keys(): command = "config vlan del {}".format(vid) commands.append(command) st.config(dut, commands) continue # Get Vlan list vlan_list = list(set([eac['vid'] for eac in output])) # Get interface list member_list = list( set([eac['member'] for eac in output if eac['member'] != ''])) if member_list: if not config_vlan_range_members( dut, '1 4093', member_list, config='del', skip_verify=True): st.log("VLAN all member delete failed") return False if vlan_list: if not delete_all_vlan(dut, cli_type=cli_type): st.log("VLAN all delete failed") return False if cli_type == 'klish': return delete_all_vlan(dut, cli_type=cli_type) return True
def f(dut): if st.get_device_type(dut) in ["sonic", "vsonic"]: st.show(dut, "show version", skip_error_check=True, skip_tmpl=True) st.show(dut, "show runningconfiguration all", skip_error_check=True, skip_tmpl=True) if not st.is_community_build(): st.show(dut, "show system status", skip_error_check=True, skip_tmpl=True)
def vlan_preconfig(): if not vlan_obj.create_vlan(vars.D1, data.vlan): st.report_fail("vlan_create_fail", data.vlan) if not st.is_community_build(): mac_obj.config_mac(vars.D1, data.source_mac, data.vlan, vars.D1T1P1) st.log( "Adding TGen-1 connected interface to newly created vlan in un tagging mode." ) if not vlan_obj.add_vlan_member( vars.D1, data.vlan, vars.D1T1P1, tagging_mode=False): st.report_fail("vlan_untagged_member_fail", vars.D1T1P1, data.vlan) st.log( "Adding TGen-2 connected interface to newly created vlan in tagging mode." ) if not vlan_obj.add_vlan_member( vars.D1, data.vlan, vars.D1T1P2, tagging_mode=True): st.report_fail("vlan_untagged_member_fail", vars.D1T1P2, data.vlan)
def show_interface_counters_detailed(dut, interface, filter_key=None): """ show interfaces counters detailed <interface>. Author : Rakesh Kumar Vooturi ([email protected]) :param dut: :param interface: :return: """ command = "show interfaces counters detailed {}".format(interface) if st.is_community_build(): output = st.show(dut, command, skip_error_check=True) else: output = st.show(dut, command) if not filter_key: return output else: if not output: return False return output[0][filter_key]
def vlan_module_epilog(): if not st.is_community_build(vars.D1): interface_list = [vars.D1T1P1, vars.D1T1P2] storm_control_type = [ "broadcast", "unknown-multicast", "unknown-unicast" ] for interface in interface_list: for stc_type in storm_control_type: scapi.config(vars.D1, type=stc_type, action="del", interface_name=interface, bits_per_sec=sc_data.kbps, cli_type="click") vlan.clear_vlan_configuration(st.get_dut_names(), thread=False, cli_type="click") portchannel.clear_portchannel_configuration(st.get_dut_names(), thread=True)
def config_vlan_range(dut, vlan_range, config="add", skip_verify=False): """ Author: [email protected] Creates/Deletes range of VLANs given as input. :param dut: :param vlan_range: range of VLAN IDs in string format, separator space: "first-VLAN last_VLAN". can be list of strings. :param config: flag which specifies to configure or unconfigure the cli. add for config, del for unconfig. Default:add :param skip_verify: True | False :return True: The VLANs were successfully created or deleted. :return False: Error in parameter passed. """ if config == "del": st.log("Deleting range of vlans {}".format(vlan_range)) else: st.log("Creating range of vlans {}".format(vlan_range)) vlan_range_list = list(vlan_range) if isinstance(vlan_range, list) else [vlan_range] commands = [] if st.is_community_build(): for vrange in vlan_range_list: [range_min, range_max] = [int(vid) for vid in vrange.split()] for vid in range(range_min, range_max + 1): commands.append("config vlan {} {}".format(config, vid)) rv = st.config(dut, commands) return _check_config_vlan_output(rv) for vrange in vlan_range_list: commands.append("config vlan range {} {}".format(config, vrange)) ver_flag = True for command in commands: # -w option displays warning, turned on so that existing vlans message can be checked if not skip_verify: command += " -w" rv = st.config(dut, command) if not _check_config_vlan_output(rv): ver_flag = False return ver_flag
def config_vlan_interfaces(dut, vlan_data={}, config='yes', skip_error=False): if config == 'yes' or config == 'add': config = 'add' elif config == 'no' or config == 'del': config = 'del' else: st.error("Invalid config type {}".format(config)) return False command = [] if config == 'del': for if_name, if_data in vlan_data.items(): vlan_id = if_data['vlan_id'] range_cmd = False if 'range' in if_data.keys(): range_ids = if_data['range'] if range_ids[0] < range_ids[1]: range_min, range_max = range_ids[0], range_ids[1] range_cmd = True elif range_ids[0] > range_ids[1]: range_min, range_max = range_ids[1], range_ids[0] range_cmd = True else: vlan_id = range_ids[0] for link_member in if_data['members']: if not range_cmd: cmd_str = "config vlan member {} {} {} ".format( config, vlan_id, link_member) command.append(cmd_str) elif not st.is_community_build(): cmd_str = "config vlan member range {} {} {} {}".format( config, range_min, range_max, link_member) command.append(cmd_str) else: skip_error = True for vid in range(range_min, range_max + 1): cmd_str = "config vlan member {} {} {} ".format( config, vid, link_member) command.append(cmd_str) try: st.config(dut, command, skip_error_check=skip_error) except Exception as e: st.log(e) return False command = [] for if_name, if_data in vlan_data.items(): vlan_id = if_data['vlan_id'] range_cmd = False if 'range' in if_data.keys(): range_ids = if_data['range'] if range_ids[0] < range_ids[1]: range_min, range_max = range_ids[0], range_ids[1] range_cmd = True elif range_ids[0] > range_ids[1]: range_min, range_max = range_ids[1], range_ids[0] range_cmd = True else: vlan_id = range_ids[0] if not range_cmd: cmd_str = "sudo config vlan {} {} ".format(config, vlan_id) command.append(cmd_str) elif not st.is_community_build(): cmd_str = "sudo config vlan range {} {} {}".format( config, range_min, range_max) command.append(cmd_str) else: for vid in range(range_min, range_max + 1): cmd_str = "sudo config vlan {} {} ".format(config, vid) command.append(cmd_str) try: st.config(dut, command) except Exception as e: st.log(e) return False command = [] if config == 'add': for if_name, if_data in vlan_data.items(): vlan_id = if_data['vlan_id'] range_cmd = False if 'range' in if_data.keys(): range_ids = if_data['range'] if range_ids[0] < range_ids[1]: range_min, range_max = range_ids[0], range_ids[1] range_cmd = True elif range_ids[0] > range_ids[1]: range_min, range_max = range_ids[1], range_ids[0] range_cmd = True else: vlan_id = range_ids[0] for link_member in if_data['members']: if not range_cmd: cmd_str = "config vlan member {} {} {} ".format( config, vlan_id, link_member) command.append(cmd_str) elif not st.is_community_build(): cmd_str = "config vlan member range {} {} {} {}".format( config, range_min, range_max, link_member) command.append(cmd_str) else: for vid in range(range_min, range_max + 1): cmd_str = "config vlan member {} {} {} ".format( config, vid, link_member) command.append(cmd_str) try: st.config(dut, command) except Exception as e: st.log(e) return False return True
def clear_interface_counters(dut): if st.is_community_build(): return st.config(dut, "sonic-clear counters") else: return st.show(dut, "show interfaces counters -c")
def config_vlan_range_members(dut, vlan_range, port, config="add", skip_verify=False, skip_error=False): """ Author: [email protected] Add or remove given member ports to range of VLANs given as input. :param dut: :param vlan_range: range of VLAN IDs in string format "first-VLAN last_VLAN". can be list of strings. :param port: port or list of ports which needs to be added / deleted to vlan_range :param config: flag which specifies to configure or unconfigure the cli. add for config, del for unconfig. Default:add :param skip_verify: True | False :param skip_error: True | False :return True: Member ports successfully added or deleted to vlan range. :return False: Error in parameter passed. """ if config == "del": st.log("Deleting member ports from range of vlans") else: st.log("Adding member ports to range of vlans") vlan_range_list = list(vlan_range) if isinstance(vlan_range, list) else [vlan_range] port_list = list(port) if isinstance(port, list) else [port] entries = [] for vlan_range in vlan_range_list: for each_port in port_list: if not st.is_community_build(): command = "config vlan member range {} {} {}".format( config, vlan_range, each_port) entries.append([command, each_port, vlan_range]) else: [range_min, range_max] = [int(vid) for vid in vlan_range.split()] for vid in range(range_min, range_max + 1): command = "config vlan member {} {} {}".format( config, vid, each_port) entries.append([command, each_port, vid]) if st.is_community_build() and config == "del": skip_error = True ver_flag = True for [command, each_port, vlan_range] in entries: if not skip_verify and not st.is_community_build(): # -w option displays warning, turned on so that existing vlans message can be checked command += " -w" output = st.config(dut, command, skip_error_check=skip_error) if "is already a member of Vlan" in output: st.error("{} is already a member of Vlan{}".format( each_port, vlan_range)) ver_flag = False if "doesn't exist" in output: st.error(" Vlan{} doesn't exist".format(vlan_range)) ver_flag = False return ver_flag