示例#1
0
def config_server(dut, no_form=False, skip_error_check=False, **kwargs):
    """
    Config / Unconfig radius server using provided parameters
    Author: Chaitanya Vella ([email protected])
    :param dut:
    :param family:
    :param no_form:
    :param kwargs:
    :return:
    """
    st.log("Configuring RADIUS SERVER Parameters ...")
    cli_type = kwargs["cli_type"] if kwargs.get("cli_type") else "klish"
    if "ip_address" not in kwargs:
        st.log("IP Address not provided")
        return False
    ipaddress_li = common_utils.make_list(kwargs["ip_address"])
    for each_ip in ipaddress_li:
        if cli_type == "klish":
            cmd = "radius-server host {}".format(each_ip)
            if "auth_type" in kwargs:
                cmd += " auth-type {}".format(kwargs["auth_type"])
            if "auth_port" in kwargs:
                cmd += " auth-port {}".format(kwargs["auth_port"])
            if "key" in kwargs:
                cmd += " key {}".format(kwargs["key"])
            if "priority" in kwargs:
                cmd += " priority {}".format(kwargs["priority"])
            if "timeout" in kwargs:
                cmd += " timeout {}".format(kwargs["timeout"])
            if "use_mgmt_vrf" in kwargs:
                cmd += " vrf {}".format(kwargs.get("use_mgmt_vrf"))
            if "retransmit" in kwargs:
                cmd += " re-transmit {}".format(kwargs["retransmit"])
            command = "no {}".format(cmd) if no_form else cmd
            st.cli_config(dut, command, "mgmt-config", skip_error_check)
        elif cli_type == "click":
            action = kwargs["action"] if "action" in kwargs else "add"
            command = "config radius {} {}".format(action, each_ip)
            if "retransmit" in kwargs:
                command += " -r {}".format(kwargs["retransmit"])
            if "auth_type" in kwargs:
                command += " -a {}".format(kwargs["auth_type"])
            if "timeout" in kwargs:
                command += " -t {}".format(kwargs["timeout"])
            if "key" in kwargs:
                command += " -k {}".format(kwargs["key"])
            if "auth_port" in kwargs:
                command += " -o {}".format(kwargs["auth_port"])
            if "priority" in kwargs:
                command += " -p {}".format(kwargs["priority"])
            if "use_mgmt_vrf" in kwargs:
                command += " -m"
            st.config(dut, command, skip_error_check=skip_error_check)
示例#2
0
def config(dut, **kwargs):
    """
    API to configure storm control on DUT
    Author : Chaitanya Vella ([email protected])
    :param dut:
    :param kwargs: bits_per_sec, type, interface_name, cli_type, no_form, action
    :return:
    """
    mandatory_args = ["bits_per_sec", "type", "interface_name"]
    cli_type = kwargs["cli_type"] if "cli_type" in kwargs else "click"
    no_form = kwargs["no_form"] if "no_form" in kwargs else ""
    action = kwargs["action"] if "action" in kwargs else "add"
    for arg in mandatory_args:
        if arg not in kwargs:
            st.log("Expecting {} value".format(arg))
            return False
    if cli_type != "click":
        if not no_form:
            command = "storm-control {} {}".format(kwargs["type"],
                                                   kwargs["bits_per_sec"])
        else:
            command = "no storm-control {}".format(kwargs["type"])
        st.cli_config(dut,
                      command,
                      "mgmt-intf-config",
                      interface=kwargs["interface_name"])
    else:
        if action == "add":
            command = "config interface storm-control {} {} {} {}".format(
                kwargs["type"], action, kwargs["interface_name"],
                kwargs["bits_per_sec"])
        else:
            command = "config interface storm-control {} {} {}".format(
                kwargs["type"], action, kwargs["interface_name"])
        st.config(dut,
                  command,
                  skip_error_check=kwargs.get("skip_error_check", False))
    return True
示例#3
0
def config_global_server_params(dut,
                                skip_error_check=False,
                                params=dict(),
                                cli_type="klish"):
    """
    Config / Unconfig global server params using provided parameters
    Author: Chaitanya Vella ([email protected])
    :param dut:
    :param params: {"source_ip":{"value":"10.20.3.1", "no_form": False}, "key":{"value":"ABCD", "no_form": True},
                "auth_port":{"value":"56", "no_form": False}, "timeout":{"value":"30", "no_form": True}}
    :return:
    """
    st.log("Configuring GLOBAL SERVER Parameters ...")
    if not params:
        st.log("Invalid parameters provided ..")
        return False
    count = 0
    if cli_type == "klish":
        cmd = "radius-server"
        fields = {
            "source_ip": "source-ip",
            "key": "key",
            "auth_type": "auth-type",
            "timeout": "timeout",
            "retransmit": "retransmit"
        }
        for key, value in params.items():
            if value.get("no_form"):
                command = "no {} {}".format(cmd, fields[key])
            else:
                command = "{} {} {}".format(cmd, fields[key], value["value"])
            output = st.cli_config(dut, command, "mgmt-config",
                                   skip_error_check)
            if "Syntax error: Illegal parameter" in utils.remove_last_line_from_string(
                    output):
                st.log(utils.remove_last_line_from_string(output))
                return False
            count += 1
    elif cli_type == "click":
        cmd = "config radius"
        fields = {
            "source_ip": "sourceip",
            "key": "passkey",
            "auth_type": "authtype",
            "timeout": "timeout",
            "retransmit": "retransmit"
        }
        for key, value in params.items():
            if value.get("no_form"):
                if key == "source_ip":
                    command = "{} default {} {}".format(
                        cmd, fields[key], value["value"])
                else:
                    command = "{} default {}".format(cmd, fields[key])
            else:
                command = "{} {} {}".format(cmd, fields[key], value["value"])
            output = st.config(dut, command, skip_error_check=skip_error_check)
            if "Valid chars are" in utils.remove_last_line_from_string(output):
                st.log(utils.remove_last_line_from_string(output))
                return False
            count += 1
    if count > 0:
        return True
    st.log(
        "Returning False as the command execution is not happened with the provided parameters .. "
    )
    return False
示例#4
0
def test_vtysh_mgmt_prompt_modes_check_2():
    vars = st.get_testbed_vars()

    st.show(vars.D1, "show platform summary")

    st.change_prompt(vars.D1, "vtysh-user")
    st.cli_show(vars.D1, "show ip route")
    st.change_prompt(vars.D1, "mgmt-user")
    st.cli_show(vars.D1, "show interface counters", skip_tmpl=True)
    st.change_prompt(vars.D1, "vtysh-user")
    st.cli_show(vars.D1, "show ip route")

    st.change_prompt(vars.D1, "normal-user")

    st.change_prompt(vars.D1, "vtysh-intf-config", interface="Ethernet40")
    st.cli_config(vars.D1, "shutdown")
    st.cli_config(vars.D1, "no shutdown")
    st.change_prompt(vars.D1, "mgmt-intf-config", interface="Ethernet4")
    st.cli_config(vars.D1, "shutdown")
    st.cli_config(vars.D1, "no shutdown")
    st.cli_show(vars.D1, "show interface counters", skip_tmpl=True)
    st.change_prompt(vars.D1, "vtysh-intf-config", interface="Ethernet40")
    st.cli_config(vars.D1, "shutdown")
    st.cli_config(vars.D1, "no shutdown")

    st.change_prompt(vars.D1, "normal-user")

    st.change_prompt(vars.D1, "vtysh-router-config", router="bgp", instance="1")
    st.cli_config(vars.D1, "aggregate-address 1.2.3.4/24")
    st.change_prompt(vars.D1, "mgmt-ipv4-acl-config", aclname="MyACL")
    st.cli_config(vars.D1, "seq 2 permit udp any any")
    st.cli_config(vars.D1, "no seq 2")
    st.cli_show(vars.D1, "show interface counters", skip_tmpl=True)
    st.change_prompt(vars.D1, "vtysh-router-config", router="bgp", instance="1")
    st.cli_config(vars.D1, "aggregate-address 1.2.3.4/24")

    st.show(vars.D1, "show vlan config")
    st.report_pass("operation_successful")
示例#5
0
def test_vtysh_prompt_modes_check_5():
    vars = st.get_testbed_vars()

    st.change_prompt(vars.D1, "normal-user")

    st.cli_config(vars.D1, "list", "vtysh-intf-config", interface="Ethernet40")
    st.cli_config(vars.D1, "list", "vtysh-bfd-peer-config", peer_ip="1.2.3.4")
    st.cli_config(vars.D1, "list", "vtysh-key-chain-config", key_chain="testkeychain")
    st.cli_config(vars.D1, "list", "vtysh-key-chain-Identifier-config", key_id="1")
    st.cli_config(vars.D1, "list", "vtysh-l2vpn-config", l2vpn_name="testl2vpn")
    st.cli_config(vars.D1, "list", "vtysh-nhgroup-config", group_name="testnhgroup")
    st.cli_config(vars.D1, "list", "vtysh-pbr-map-config", map_name="testpbrmap", seq_id="1")
    st.cli_config(vars.D1, "list", "vtysh-pseudowire-config", interface="Ethernet4")
    st.cli_config(vars.D1, "list", "vtysh-route-map-config", tag_name="testroutemap", action="deny", seq_num="1")
    st.cli_config(vars.D1, "list", "vtysh-router-config", router="bgp", instance="1")
    st.cli_config(vars.D1, "list", "vtysh-router-af-config", addr_family="ipv4", modifier="unicast")
    st.cli_config(vars.D1, "list", "vtysh-router-config", router="rip")
    st.cli_config(vars.D1, "list", "vtysh-vrf-config", vrf_name="testvrfname")

    st.show(vars.D1, "show vlan config")
    st.report_pass("operation_successful")
示例#6
0
def test_vtysh_prompt_modes_check_4():
    vars = st.get_testbed_vars()

    st.change_prompt(vars.D1, "normal-user")

    st.cli_config(vars.D1, "no shutdown", "vtysh-intf-config", interface="Ethernet40")
    st.cli_config(vars.D1, "receive-interval 10", "vtysh-bfd-peer-config", peer_ip="1.2.3.4")
    st.cli_config(vars.D1, "list", "vtysh-key-chain-config", key_chain="testkeychain")
    st.cli_config(vars.D1, "key-string teststring", "vtysh-key-chain-Identifier-config", key_id="1")
    st.cli_config(vars.D1, "vc type ethernet", "vtysh-l2vpn-config", l2vpn_name="testl2vpn")
    st.cli_config(vars.D1, "nexthop 1.2.3.4", "vtysh-nhgroup-config", group_name="testnhgroup")
    st.cli_config(vars.D1, "set nexthop 1.2.3.4", "vtysh-pbr-map-config", map_name="testpbrmap", seq_id="1")
    st.cli_config(vars.D1, "neighbor 1.2.3.4", "vtysh-pseudowire-config", interface="Ethernet4")
    st.cli_config(vars.D1, "set community none", "vtysh-route-map-config", tag_name="testroutemap", action="deny", seq_num="1")

    st.cli_config(vars.D1, "aggregate-address 1.2.3.4/24", "vtysh-router-config", router="bgp", instance="1")
    st.cli_config(vars.D1, "allow-ecmp", "vtysh-router-config", router="rip")
    st.cli_config(vars.D1, "aggregate-address 1.2.3.4/24", "vtysh-router-config", router="bgp", instance="1")
    st.cli_config(vars.D1, "bgp dampening", "vtysh-router-af-config", addr_family="ipv4", modifier="unicast")
    st.cli_config(vars.D1, "allow-ecmp", "vtysh-router-config", router="rip")
    st.cli_config(vars.D1, "bgp dampening", "vtysh-router-af-config", router="bgp", instance="1", addr_family="ipv4", modifier="unicast")
    st.cli_config(vars.D1, "aggregate-address 1.2.3.4/24", "vtysh-router-config", router="bgp", instance="1")

    st.cli_config(vars.D1, "ip protocol any route-map test", "vtysh-vrf-config", vrf_name="testvrfname")

    st.show(vars.D1, "show vlan config")
    st.report_pass("operation_successful")
示例#7
0
def test_mgmt_cli_mode_check_3():
    vars = st.get_testbed_vars()

    # from sonic to mgmt-cli interface mode and commands along with mode change
    st.cli_config(vars.D1, "shutdown", "mgmt-intf-config", interface="Ethernet40")
    st.cli_config(vars.D1, "no shutdown")

    # from mgmt-cli interface mode to mgmt-cli acl mode and commands along with mode change
    st.cli_config(vars.D1, "seq 3 permit udp any any", "mgmt-ipv4-acl-config", aclname="MyTestACL")
    st.cli_config(vars.D1, "no seq 3")

    st.cli_config(vars.D1, "shutdown", "mgmt-intf-config", interface="Ethernet4")
    st.cli_config(vars.D1, "no shutdown")

    st.show(vars.D1, "show interfaces status")
    st.report_pass("operation_successful")