Beispiel #1
0
def bind_class_action_copp_policy(dut, **kwargs):
    """
    Author: Gangadhara Sahu ([email protected])
    To configure classifier of type CoPP
    :param dut:
    :param classifier:
    :param action_group:
    :param config:
    :return bool:

    Example : bind_class_action_copp_policy(dut1,classifier="copp-system-arp",action_group="copp-system-arp",config="no")
              bind_class_action_copp_policy(dut1,classifier="copp-system-arp",action_group="copp-system-nd")
    """
    config_cmd = 'no' if kwargs.get('config','yes').lower() == 'no' else 'yes'

    command = []
    if config_cmd == 'no':
        command.append("policy-map copp-system-policy type copp")
        command.append("no class {}".format(kwargs['classifier']))
        command.append("exit")
    else:
        command.append("policy-map copp-system-policy type copp")
        command.append("class {}".format(kwargs['classifier']))
        command.append("set copp-action {}".format(kwargs['action_group']))
        command.append("exit")
        command.append("exit")

    st.config(dut, command,type="klish")
    return True
Beispiel #2
0
def _cleanup_mclag_config_helper(dut_list, cli_type=''):
    """
    Helper routine to cleanup MCLAG config from devices.
    """
    dut_li = list(dut_list) if isinstance(dut_list, list) else [dut_list]
    cli_type = st.get_ui_type(dut_li[0], cli_type=cli_type)
    for dut in dut_li:
        st.log(
            "############## {} : MCLAG config cleanup ################".format(
                dut))
        if cli_type == 'click':
            output = st.show(dut, "mclagdctl dump state")
        elif cli_type == 'klish':
            output = st.show(dut, "show mclag brief", type=cli_type)
        st.log("##### MCLAG : {}".format(output))
        if len(output) == 0:
            continue

        for entry in output:
            if not entry['domain_id']:
                continue

            domain_id = entry['domain_id']
            if cli_type == 'click':
                st.config(dut, "sudo config mclag del {}".format(domain_id))
            elif cli_type == 'klish':
                cmd = "no mclag domain {}".format(domain_id)
                st.config(dut, cmd, type="klish", conf=True)

    return True
Beispiel #3
0
def default_interface(dut,**kwargs):
    """
    TO configure default interface
    Author: Naveen ([email protected])

    :param dut:
    :param interface_name:
    :param range: 'True', if Range is True, please provide interfaces range with "-" for eg Ethernet 0-10
    :return:

    Eg : port.default_interface(dut1, interface = 'Ethernet 4-7',range='yes/True')
         port.default_interface(dut1, interface = 'Ethernet 4')
    """
    cli_type = st.get_ui_type(dut, **kwargs)

    if 'interface' not in kwargs:
        st.error("Mandatory arg interface is not present")
        return False
    else:
        interface = kwargs['interface']

    skip_error = kwargs.pop('skip_error', False)
    command = ''

    if cli_type == 'klish':
        if 'range' in kwargs:
            command = command + "\n" + "default interface range {}".format(interface)
        else:
            command = command + "\n" + "default interface {}".format(interface)
    else:
        st.error("Invalid cli_type for this API - {}.".format(cli_type))
        return False

    st.config(dut, command, type='klish',skip_error_check=skip_error)
    return True
Beispiel #4
0
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
Beispiel #5
0
def config_mclag_router_mac(dut, **kwargs):
    '''
    Configures <gw_mac for mclag
    :param dut:
    :param kwargs: op_type/gw_mac>
    :return:

    Usage:
    config_mclag_router_mac(dut1, op_type='add', gw_mac='00:11:22:33:44:55')
    config_mclag_router_mac(dut1, op_type='del', gw_mac='00:11:22:33:44:55')
    '''
    ### Optional parameters processing
    type_val = kwargs.get('op_type', None)
    gw_mac_val = kwargs.get('gw_mac', None)
    ##TODO enable below after adding Klish support as of now overriding with click
    #cli_type = kwargs.pop('cli_type', st.get_ui_type(dut,**kwargs))
    cli_type = 'click'

    if cli_type == 'click':
        cmd = ""
        if 'op_type' in kwargs and 'gw_mac' in kwargs:
            cmd += "config mclag gw-mac {} {}\n".format(type_val, gw_mac_val)
        else:
            st.error("Mandatory argument gw_mac Not Found")
            return False
        st.config(dut, cmd)
    return True
Beispiel #6
0
def config_stp_vlan_parameters(dut, vlan, **kwargs):
    """

    :param dut:
    :param vlan:
    :param kwargs:
    :return:
    """
    cli_type = kwargs.setdefault('cli_type', 'click')
    no_form = 'no' if kwargs.setdefault('no_form', False) else ''
    del kwargs['cli_type']
    del kwargs['no_form']
    click_2_klish = {
        'forward_delay': 'forward-time',
        'hello': 'hello-time',
        'max_age': 'max-age'
    }

    for each_key, value in kwargs.items():
        if cli_type == 'click':
            command = "config spanning_tree vlan {} {} {}".format(
                each_key, vlan, value)
        elif cli_type == 'klish':
            each_key1 = click_2_klish.get(each_key, each_key)
            command = "{} spanning-tree vlan {} {} {}".format(
                no_form, vlan, each_key1, value)
        else:
            st.error("Invalid CLI type - {}".format(cli_type))
            return
        st.config(dut, command, type=cli_type)
Beispiel #7
0
def config_nat_global(dut, **kwargs):
    """
    Author : Priyanka
    :param :dut:
    :param :prot:
    :param :time:
    :return:
    """
    cli_type = st.get_ui_type(dut, **kwargs)
    skip_error_check = kwargs.get("skip_error_check", True)
    if cli_type not in ["click", "klish"]:
        st.log("UNSUPPORTED CLI TYPE")
        return False
    if kwargs["admin_mode"]:
        if cli_type == "click":
            command = "config nat feature {}".format(kwargs["admin_mode"])
        else:
            command = list()
            command.append("nat")
            admin_mode = "enable" if kwargs["admin_mode"] == "enable" else "no enable"
            command.append("{}".format(admin_mode))
            command.append("exit")
    elif kwargs["prot"]:
        command = "config nat {}-timeout {}".format(kwargs["prot"], kwargs["time"])
    else:
        command = "config nat timeout {}".format(kwargs["time"])
    st.config(dut, command, type=cli_type, skip_error_check=skip_error_check)
    return True
Beispiel #8
0
def clear_watermark_counters(dut, **kwargs):
    """
    Clear priority-group or queue watermark counters.
    Author: Shiva Kumar Boddula ([email protected])

    :param :dut:
    :param :threshold_type:  priority-group|queue
    :param :buffer_type: if threshold_type:priority-group {shared|headroom} |
                                                            else threshold_type:queue {unicast|multicast}
    :return:
    """
    if 'threshold_type' not in kwargs and 'buffer_type' not in kwargs and 'cli_type' not in kwargs:
        st.error(
            "Mandatory parameter threshold_type/buffer_type/cli_type not found"
        )
        return False
    cli_type = st.get_ui_type(dut, **kwargs)
    if "priority-group" in kwargs['threshold_type'] or "queue" in kwargs[
            'threshold_type']:
        if cli_type == "click":
            command = "sonic-clear {} watermark {}".format(
                kwargs['threshold_type'], kwargs['buffer_type'])
        elif cli_type == "klish":
            command = "clear {} watermark {}".format(kwargs['threshold_type'],
                                                     kwargs['buffer_type'])
    else:
        st.error("Invalid threshold_type provided '{}'".format(
            kwargs['threshold_type']))
        return False
    st.config(dut, command, type=cli_type)
    return True
Beispiel #9
0
def disable_sshv6(dut):
    st.log(" # Disable SSH on a device to listen on IPv6")
    command = "sed -i 's/ListenAddress ::/#ListenAddress ::/g' /etc/ssh/sshd_config"
    st.config(dut, command)
    command = "/etc/init.d/ssh restart"
    st.config(dut, command)
    return True
Beispiel #10
0
def config_mac_agetime(dut, agetime, cli_type="", config= "add", **kwargs):
    """
    This proc is to config mac aging and setting it back to default.
    :param dut: DUT Number
    :param agetime: fdb age time in seconds
    :return:
    """
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    skip_error_check = kwargs.get('skip_error', False)
    command = ''
    if cli_type == 'click':
        command = "config mac aging_time {}".format(int(agetime))
        if not st.is_feature_supported("config-mac-aging_time-command", dut):
            st.community_unsupported(command, dut)
            skip_error_check=True
    elif cli_type == 'klish':
        if config == 'add':
            command = "mac address-table aging-time {}".format(int(agetime))
        else:
            command = "no mac address-table aging-time"
    elif cli_type in ['rest-patch', 'rest-put']:
        rest_urls = st.get_datastore(dut, 'rest_urls')
        url = rest_urls['mac_aging'].format(name='default')
        config_data = {"openconfig-network-instance:mac-aging-time": int(agetime)}
        if not config_rest(dut, rest_url=url, http_method=cli_type, json_data=config_data):
              st.error("Failed to configure aging as {}".format(agetime))
              return False
    if command:
        st.config(dut, command, skip_error_check=skip_error_check, type=cli_type)
    return True
Beispiel #11
0
def bcmcmd_l3_entry_only_config(dut, **kwargs):
    if "action" not in kwargs:
        st.error("Mandatory params num, action are not provided")
        return False
    valid = 1
    if kwargs["action"] == "delete":
        valid = 0
    output = bcmcmd_get_l3_entry(dut)
    name_list = utils.dicts_list_values(output, "names")
    if "L3_ENTRY_ONLY" in name_list:
        num = int(
            utils.filter_and_select(
                output, [], {"names": "L3_ENTRY_ONLY"})[0]['entries']) - 1
        command = "bcmcmd 'mod L3_ENTRY_ONLY 1 {} VALID={}'".format(num, valid)
    elif "L3_ENTRY_ONLY_SINGLE" in name_list:
        num = int(
            utils.filter_and_select(
                output, [],
                {"names": "L3_ENTRY_ONLY_SINGLE"})[0]['entries']) - 1
        command = "bcmcmd 'mod L3_ENTRY_ONLY_SINGLE 1 {} BASE_VALID={}'".format(
            num, valid)
    elif "L3_ENTRY_SINGLE" in name_list:
        num = int(
            utils.filter_and_select(
                output, [], {"names": "L3_ENTRY_SINGLE"})[0]['entries']) - 1
        command = "bcmcmd 'mod L3_ENTRY_SINGLE 1 {} BASE_VALID={}'".format(
            num, valid)
    else:
        st.error(
            "L3_ENTRY_ONLY | L3_ENTRY_ONLY_SINGLE | L3_ENTRY_SINGLE not found in - listmem l3_entry"
        )
        return False
    st.config(dut, command)
    return True
Beispiel #12
0
def clear_mac(dut,port=None,vlan=None,**kwargs):
    """
    This proc is to clear mac address/fdb entries of the dut.
    :param dut: DUT Number
    :return:
    """
    cli_type = st.get_ui_type(dut, **kwargs)
    cli_type = 'klish' if cli_type in ['rest-patch', 'rest-put'] else cli_type
    if cli_type == "click":
        if not st.is_feature_supported("sonic-clear-fdb-type-command", dut):
            command = "sonic-clear fdb all"
        elif port:
            command = "sonic-clear fdb port {}".format(port)
        elif vlan:
            command = "sonic-clear fdb vlan Vlan{}".format(vlan)
        else:
            command = "sonic-clear fdb all"
        st.config(dut, command, type=cli_type)
    elif cli_type == "klish":
        if 'address' in kwargs:
            command = "clear mac address-table dynamic address  {}".format(kwargs['address'])
        elif vlan:
            command = "clear mac address-table dynamic Vlan {}".format(vlan)
        elif port:
            intf_data = get_interface_number_from_name(port)
            command = "clear mac address-table dynamic interface {} {}".format(intf_data["type"],intf_data["number"])
        else:
            command = "clear mac address-table dynamic all"

        st.config(dut, command,type=cli_type)
    else:
        st.error("Unsupported CLI: {}".format(cli_type))
        return False
    return True
Beispiel #13
0
def test_wrong_vtysh_cmd_2():
    vars = st.get_testbed_vars()

    st.config(vars.D1, "router bgp\nexit\nexit", type="vtysh", skip_error_check=True)
    st.show(vars.D1, "testetst\nexit", skip_error_check=True, skip_tmpl=True)

    st.report_pass("operation_successful")
Beispiel #14
0
def config_vrfs(dut, vrf_data_list={}, config='yes', cli_type=''):

    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

    cli_type = st.get_ui_type(dut, cli_type=cli_type)

    command = []
    for _, vrf_data in vrf_data_list.items():
        vrf = vrf_data['name']
        if cli_type == 'click':
            cmd_str = "sudo config vrf {} {} ".format(config, vrf)
            command.append(cmd_str)
        elif cli_type == "klish":
            cmd_str = "no " if config == 'del' else ''
            cmd_str += "ip vrf {}".format(vrf)
            command.append(cmd_str)
        elif cli_type in ['rest-patch', 'rest-put']:
            st.error("Spytest API not yet supported for REST type")
            return False

    if cli_type in ['click', 'klish']:
        try:
            st.config(dut, command, type=cli_type)
        except Exception as e:
            st.log(e)
            return False

    return True
Beispiel #15
0
def config_stp_vlan_interface(dut, vlan, iface, value, mode='cost', **kwargs):
    """

    :param dut:
    :param vlan:
    :param iface:
    :param value:
    :param mode:
    :return:
    """
    cli_type = kwargs.get('cli_type', 'click')
    no_form = 'no' if kwargs.get('no_form') else ''

    if mode in ['cost', 'priority']:
        if cli_type == 'click':
            command = "config spanning_tree vlan interface {} {} {} {} ".format(
                mode, vlan, iface, value)
        elif cli_type == 'klish':
            if mode == 'priority':
                mode = 'port-priority'
            interface_data = utils.get_interface_number_from_name(iface)
            command = [
                'interface {} {}'.format(interface_data["type"],
                                         interface_data["number"]),
                '{} spanning-tree vlan {} {} {}'.format(
                    no_form, vlan, mode, value), "exit"
            ]
        else:
            st.error("Invalid CLI type - {}".format(cli_type))
            return
    else:
        st.log("Invalid mode = {}".format(mode))
        return
    st.config(dut, command, type=cli_type)
Beispiel #16
0
def config_mac(dut, mac, vlan, intf, cli_type=""):
    """
    :param dut:
    :type dut:
    :return:
    :rtype:
    """
    #st.log("config mac add <mac> <vlan> <intf>")
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    if cli_type == 'click':
        command = "config mac add {} {} {}".format(mac, vlan, intf)
        if not st.is_feature_supported("config-mac-add-command", dut):
            st.community_unsupported(command, dut)
            _json_mac_add(dut, mac, vlan, intf)
        else:
            st.config(dut, command, type='click')
    elif cli_type == 'klish':
        interface = get_interface_number_from_name(intf)
        command = "mac address-table {} vlan {} {} {}".format(
            mac, vlan, interface["type"], interface["number"])
        st.config(dut, command, type=cli_type)
    elif cli_type in ["rest-patch", "rest-put"]:
        rest_urls = st.get_datastore(dut, "rest_urls")
        url = rest_urls['static_mac_config']
        json = {
            "openconfig-network-instance:network-instances": {
                "network-instance": [{
                    "name": "default",
                    "fdb": {
                        "mac-table": {
                            "entries": {
                                "entry": [{
                                    "mac-address": mac,
                                    "vlan": int(vlan),
                                    "config": {
                                        "mac-address": mac,
                                        "vlan": int(vlan)
                                    },
                                    "interface": {
                                        "interface-ref": {
                                            "config": {
                                                "interface": intf,
                                                "subinterface": 0
                                            }
                                        }
                                    }
                                }]
                            }
                        }
                    }
                }]
            }
        }
        if not config_rest(
                dut, http_method=cli_type, rest_url=url, json_data=json):
            return False
    else:
        st.log("Unsupported cli")
        return False
    return True
Beispiel #17
0
def config_spanning_tree(dut,
                         feature="pvst",
                         mode="enable",
                         vlan=None,
                         cli_type='click'):
    """

    :param dut:
    :param feature:
    :param mode:
    :param vlan:
    :param cli_type:
    :return:
    """
    command = ''
    no_form = 'no'
    if mode == 'enable':
        no_form = ''

    st.log("{} spanning_tree {}".format(mode, feature))
    if cli_type == 'click':
        if vlan:
            command = "config spanning_tree vlan {} {}".format(mode, vlan)
        else:
            command = "config spanning_tree {} {}".format(mode, feature)
    elif cli_type == 'klish':
        if mode == 'disable':
            feature = ''
        if vlan:
            command = "{} spanning-tree vlan {}".format(no_form, vlan)
        else:
            command = "{} spanning-tree mode {}".format(no_form, feature)

    st.config(dut, command, type=cli_type)
Beispiel #18
0
def delete_mac(dut, mac, vlan, cli_type=""):
    """
    :param dut:
    :type dut:
    :return:
    :rtype:
    """
    #st.log("config mac del <mac> <vlan>")
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    if cli_type == 'click':
        command = "config mac del {} {}".format(mac, vlan)
        if not st.is_feature_supported("config-mac-add-command", dut):
            st.community_unsupported(command, dut)
            _json_mac_del(dut, mac, vlan)
        else:
            st.config(dut, command, type=cli_type)
    elif cli_type == 'klish':
        command = "no mac address-table {} vlan {}".format(mac, vlan)
        st.config(dut, command, type=cli_type)
    elif cli_type in ["rest-patch", "rest-put"]:
        network_instance_name = 'default'
        rest_urls = st.get_datastore(dut, "rest_urls")
        url = rest_urls['mac_entry_based_vlan_interface'].format(
            network_instance_name, mac, vlan)
        delete_rest(dut, rest_url=url)
    else:
        st.log("Unsupported cli")
        return False

    return True
Beispiel #19
0
def config_nat_feature(dut, oper='enable', cli_type="", skip_error_check=True):
    """
    Config NAT Feature
    Author:[email protected]

    :param dut:
    :param oper: enable/disable
    :param cli_type:
    :param skip_error_check:
    :return:
    """
    instance = 0
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    if cli_type == "click":
        command = "config nat feature {}".format(oper)
    elif cli_type == "klish":
        command = list()
        operation = "enable" if oper == "enable" else "no enable"
        command.append("nat")
        command.append("{}".format(operation))
        command.append("exit")
    elif cli_type in ["rest-patch", "rest-put"]:
        operation = True if oper == "enable" else False
        url = st.get_datastore(dut, "rest_urls")['config_nat_feature'].format(instance)
        data = {"openconfig-nat:config": {"enable": operation}}
        config_rest(dut, http_method=cli_type, rest_url=url, json_data=data)
        return True
    else:
        st.log("UNSUPPORTED CLI TYPE")
        return False
    st.config(dut, command, type=cli_type, skip_error_check=skip_error_check)
    return True
Beispiel #20
0
def clear_mac_dampening(dut, **kwargs):
    """
    Author :
    :param dut:
    :param interface:
    :return:
    usage
    clear_mac_dampening(dut1,interface="Ethernet0")
    clear_mac_dampening(dut1)
    """

    cli_type = kwargs.get("cli_type", st.get_ui_type(dut))
    if cli_type in ["click", "rest-put", "rest-patch"]: cli_type = 'klish'
    if cli_type == "klish":
        if 'interface' in kwargs:
            intf_data = get_interface_number_from_name(kwargs['interface'])
            command = "clear mac dampening-disabled-ports {} {}\n".format(
                intf_data["type"], intf_data["number"])
        else:
            command = "clear mac dampening-disabled-ports all\n"
    elif cli_type in ["rest-put", "rest-patch"]:
        st.log('Needs to add rest url support')
        #url = st.get_datastore(dut, "rest_urls")["config_interface"]
        #if not config_rest(dut, http_method=cli_type, rest_url=url, json_data=):
        #return False
    else:
        st.log("Unsupported CLI TYPE {}".format(cli_type))
        return False
    if command:
        st.config(dut, command, type=cli_type)
    return True
Beispiel #21
0
def delete_acl_table(dut, acl_table_name=None, cli_type="click"):
    """
    API to delete the ACL table from DUT
    Author: Chaitanya Vella ([email protected])
    :param dut:
    :param acl_table_name: table name can be a string or list
    :return:
    """
    st.log("Deleting ACL table ...")
    if cli_type == "click":
        command = "config acl table delete"
        if st.is_community_build():
            command = "config acl remove table"
        if acl_table_name:
            table_name = list([str(e) for e in acl_table_name]) if isinstance(acl_table_name, list) \
                else [acl_table_name]
            for acl_table in table_name:
                command = "{} {}".format(command, acl_table)
                st.config(dut, command)
        else:
            st.config(dut, command)
    else:
        if not acl_table_name:
            st.report_fail("acl_table_name_missing")
        command = "no ip access-list {}".format(acl_table_name)
        output = st.config(dut, command, type=cli_type, skip_error_check=True)
        if "Entry not found" in output:
            st.log("acl_table_not_found")
Beispiel #22
0
def delete_vlan(dut, vlan_list, cli_type=""):
    """
    To delete list of VLANs.
    Author : Prudvi Mangadu ([email protected])

    :param dut:
    :param vlan_list:
    :param cli_type:
    :return:
    """
    if not cli_type:
        cli_type = st.get_ui_type(dut)

    st.log("Delete vlan")
    vlan_li = map(str, vlan_list) if isinstance(vlan_list,
                                                list) else [vlan_list]
    commands = list()
    try:
        for each_vlan in vlan_li:
            if cli_type == "click":
                commands.append("config vlan del {}".format(each_vlan))
            else:
                commands.append("no interface Vlan {}".format(each_vlan))
        st.config(dut, commands, skip_error_check=True, type=cli_type)
        if cli_type == "click":
            vlan_list = get_vlan_list(dut, cli_type="click")
            for each_vlan in vlan_li:
                if each_vlan in vlan_list:
                    st.error(" Vlan{} is not deleted".format(each_vlan))
                    return False
        return True
    except Exception as e1:
        st.log(e1)
        st.error(" Vlan is not deleted due to other reasons")
        return False
Beispiel #23
0
def sonic_installer_install2(dut,
                             url,
                             max_time=1800,
                             skip_error_check=False,
                             migartion=False):
    cli_type = st.get_ui_type(dut)
    if cli_type == 'click':
        if migartion:
            cmd = "sudo sonic_installer install {} -y".format(url)
        else:
            cmd = "sudo sonic_installer install --skip_migration {} -y".format(
                url)

        st.log("installing {}".format(cmd))
        output = st.config(dut,
                           cmd,
                           skip_error_check=skip_error_check,
                           max_time=max_time)
        if re.search("Installed SONiC base image SONiC-OS successfully",
                     output):
            return "success"
        if re.search("Not installing SONiC version", output) and \
           re.search("as current running SONiC has the same version", output):
            return "skipped"
        return "error"
    elif cli_type == 'klish':
        cmd = "image install {}".format(url)
        st.log("installing {}".format(cmd))
        st.config(dut,
                  cmd,
                  skip_error_check=skip_error_check,
                  max_time=max_time,
                  type=cli_type)
        return "success"
Beispiel #24
0
def create_vlan(dut, vlan_list, cli_type=""):
    """
    To create list of VLANs.
    Author : Prudvi Mangadu ([email protected])

    :param dut:
    :param vlan_list:
    :param cli_type:
    :return:
    """
    if not cli_type:
        cli_type = st.get_ui_type(dut)

    st.log("Creating vlan")
    vlan_li = map(str, vlan_list) if isinstance(vlan_list,
                                                list) else [vlan_list]
    commands = list()
    for each_vlan in vlan_li:
        if cli_type == "click":
            commands.append("config vlan add {}".format(each_vlan))
        else:
            commands.append("interface Vlan {}".format(each_vlan))
            commands.append('exit')
    st.config(dut, commands, type=cli_type)
    return True
Beispiel #25
0
def config_gw_mac(dut, skip_error=False, **kwargs):
    '''
    Configures< gw mac add | del> for Mclag
    Author: [email protected]
    :param dut:
    :param kwargs: optional parameters can be <config|mac|cli_type>
    :return:

    Usage:
    config_gw_mac(dut1, config='add', mac='xx:xx:xx:xx:xx:xx')
    config_gw_mac(dut1, config='del', mac='xx:xx:xx:xx:xx:xx')
    '''
    config = kwargs.get('config', 'add')
    if 'mac' not in kwargs:
        st.error("Mandatory parameter mac address not found")
        return False
    mac_val = kwargs.get('mac')
    cli_type = kwargs.get('cli_type', st.get_ui_type(dut, **kwargs))

    if cli_type == 'click':
        cmd = "config mclag gw-mac {} {}\n".format(config, mac_val)
        st.config(dut, cmd)
    elif cli_type == 'klish':
        config = 'no ' if config == 'del' else ''
        cmd = "{}mclag gateway-mac {}".format(config, mac_val)
        output = st.config(dut, cmd, type="klish", conf=True)
        if "Could not connect to Management REST Server" in output:
            st.error("klish mode not working.")
            return False
    return True
Beispiel #26
0
def config_port_type(dut,
                     interface,
                     stp_type="rpvst",
                     port_type="edge",
                     no_form=False,
                     cli_type="klish"):
    """
    API to config/unconfig the port type in RPVST
    :param dut:
    :param port_type:
    :param no_form:
    :return:
    """
    commands = list()
    command = "spanning-tree port type {}".format(
        port_type) if not no_form else "no spanning-tree port type"
    interface_details = utils.get_interface_number_from_name(interface)
    if not interface_details:
        st.log("Interface details not found {}".format(interface_details))
        return False
    commands.append("interface {} {}".format(interface_details.get("type"),
                                             interface_details.get("number")))
    commands.append(command)
    commands.append('exit')
    st.config(dut, commands, type=cli_type)
    return True
Beispiel #27
0
def udld_block(dut, **kwargs):
    """
    Author: [email protected]
    udld_blockf(dut=data.dut1,intf ='Ethernet10')

    Block the UDLD packtets at interface level
    :param dut:
    :param intf:
    :return:
    """
    if 'config' in kwargs:
        config = kwargs['config']
    else:
        config = 'yes'

    if config.lower() == 'yes':
        config_cmd = 'enable'
    else:
        config_cmd = 'disable'

    if 'intf' in kwargs:
        if type(kwargs['intf']) is list:
            kwargs['intf'] = list(kwargs['intf'])
        else:
            kwargs['intf'] = [kwargs['intf']]
        my_cmd = ''
        for intf in kwargs['intf']:
            if '/' in intf:
                intf = st.get_other_names(dut, [intf])[0]
            my_cmd += 'udldctl rx_drop {} {}\n'.format(config_cmd, intf)
    else:
        st.error("Mandatory argument interface name Not Found")
        return False
    st.config(dut, my_cmd, type="click")
Beispiel #28
0
def rbac_config_user(no_form=0):
    result = True
    st.banner(
        "{}Configuring User(s) to the DUT.".format("Un-" if no_form else ''))
    for each in rbac.cred_list:
        each.update({'no_form': no_form})
        st.banner("Configuring - {}".format(each), delimiter='*')
        config(vars.D1, **each)
        if each['cli_type'] == 'klish':
            st.config(vars.D1,
                      'usermod -s /bin/bash {}'.format(each['username']))
        if not no_form:
            sshapi.ssh_copyid(vars.D2, st.get_mgmt_ip(vars.D1), **each)
    if not no_form:
        if not verify(vars.D1, 'user_list', verify_list=rbac.user_list):
            st.error("Failed to config User in DUT")
            result = False
        if not verify(vars.D1, 'group_list', verify_list=rbac.group_list):
            st.error("Failed to config Groups in DUT")
            result = False
        for username, role in rbac.user_group.items():
            if not verify(
                    vars.D1, user_group=username, verify_list=[{
                        'group': role
                    }]):
                st.error('Failed to config User with group in DUT')
                result = False
        if not result:
            st.report_fail('rbac_user_config')
Beispiel #29
0
def config_intf_udld_mode(dut, **kwargs):
    """
    config_intf_udld_mode(dut=data.dut1,intf ='Ethernet10',udld_mode='yes',config='yes')
    config_intf_udld_mode(dut=data.dut1,intf ='Ethernet10',udld_mode='yes')
    config_intf_udld_mode(dut=data.dut1,intf ='Ethernet10',udld_mode='',config='no')
    udld.config_intf_udld_mode(dut=dut2,intf ='Ethernet37',udld_mode='yes',config='yes',cli_type='rest-put')
    Author: [email protected]
    Enable UDLD mode Aggressive at interface level
    :param dut:
    :param intf:
    :param udld_mode:
    :return:
    """
    cli_type = kwargs.pop('cli_type', st.get_ui_type(dut))
    if 'config' in kwargs:
        config = kwargs['config']
    else:
        config = 'yes'
    if config.lower() == 'yes':
        config_cmd = ''
    else:
        config_cmd = 'no'
    if 'intf' in kwargs:
        if type(kwargs['intf']) is list:
            kwargs['intf'] = list(kwargs['intf'])
        else:
            kwargs['intf'] = [kwargs['intf']]
    my_cmd = ''
    if cli_type == 'klish' or cli_type == 'click':
        for intf in kwargs['intf']:
            intf_details = get_interface_number_from_name(intf)
            my_cmd += 'interface {} {}\n'.format(intf_details['type'],
                                                 intf_details['number'])
            if 'udld_mode' in kwargs:
                my_cmd += '{} udld aggressive\n'.format(config_cmd)
                my_cmd += 'exit\n'
        st.config(dut, my_cmd, type='klish')
    elif cli_type in ['rest-patch', 'rest-put']:
        http_method = kwargs.pop('http_method', cli_type)
        rest_urls = st.get_datastore(dut, 'rest_urls')
        for intf in kwargs['intf']:
            rest_url = rest_urls['udld_interface_aggressive_config'].format(
                intf)
            if config_cmd == '':
                ocdata = {"openconfig-udld-ext:aggressive": bool(1)}
            else:
                ocdata = {"openconfig-udld-ext:aggressive": bool(0)}
            response = config_rest(dut,
                                   http_method=http_method,
                                   rest_url=rest_url,
                                   json_data=ocdata)
            if not response:
                st.log('UDLD mode for interface config/unconfig failed')
                st.log(response)
                return False
            return True
    else:
        st.log("Unsupported CLI TYPE - {}".format(cli_type))
        return False
Beispiel #30
0
def add_static_arp(dut, ipaddress, macaddress, interface="", cli_type=""):
    """
    To add static arp
    Author: Prudvi Mangadu ([email protected])
    :param dut:
    :param ipaddress:
    :param macaddress:
    :param interface:
    :return:
    """
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    command = ''
    if cli_type == "click":
        command = "arp -s {} {}".format(ipaddress, macaddress)
        if interface:
            command += " -i {}".format(interface)
    elif cli_type == "klish":
        if interface:
            intf = get_interface_number_from_name(interface)
            command = "interface {} {}".format(intf['type'], intf['number'])
            command = command + "\n" + "ip arp {} {}".format(
                ipaddress, macaddress) + "\n" + "exit"
        else:
            st.error(
                "'interface' option is mandatory for adding static arp entry in KLISH"
            )
            return False
    elif cli_type in ['rest-patch', 'rest-put']:
        if not interface:
            st.error(
                "'interface' option is mandatory for adding static arp entry in REST"
            )
            return False
        port_index = get_subinterface_index(dut, interface)
        rest_urls = st.get_datastore(dut, 'rest_urls')
        url = rest_urls['config_static_arp'].format(name=interface,
                                                    index=port_index)
        config_data = {
            "openconfig-if-ip:neighbor": [{
                "ip": ipaddress,
                "config": {
                    "ip": ipaddress,
                    "link-layer-address": macaddress
                }
            }]
        }
        if not config_rest(
                dut, rest_url=url, http_method=cli_type,
                json_data=config_data):
            st.error(
                "Failed to configure static ARP with IP: {}, MAC: {}, INTF: {}"
                .format(ipaddress, macaddress, interface))
            return False
    else:
        st.error("Unsupported CLI_TYPE: {}".format(cli_type))
        return False
    if command:
        st.config(dut, command, type=cli_type)
    return True