Exemplo n.º 1
0
def test_tacacs_global_tc5_add_config(duthost):
    """ Test add tacacs global config

    This test is for default setting when configDB doesn't
    contian TACACS table. So we remove TACACS config at first.
    """
    tacacs_add_init_config_without_table(duthost)
    TACACS_ADD_CONFIG = {
        "auth_type": "login",
        "passkey": "testing123",
        "timeout": "10"
    }
    json_patch = [{
        "op": "add",
        "path": "/TACPLUS",
        "value": {
            "global": TACACS_ADD_CONFIG
        }
    }]
    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        for tacacs_global_type, value in TACACS_ADD_CONFIG.items():
            pytest_assert(
                get_tacacs_global_type_value(duthost,
                                             tacacs_global_type) == value,
                "TACACS global {} failed to apply".format(tacacs_global_type))
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 2
0
def test_lo_interface_tc3_xfail(duthost, op, name,
        dummy_lo_interface_v4, dummy_lo_interface_v6):
    """ Test expect fail testcase

    ("add", "Loopback0", "587.1.0.32~132", "FC00:1::32~1128"), ADD Invalid IPv4 address
    ("add", "Loopback0", "10.1.0.32~132", "FC00:1::xyz~1128"), ADD Invalid IPv6 address
    ("remove", "Loopback0", "10.1.0.33~132", "FC00:1::32~1128"), REMOVE Unexist IPv4 address
    ("remove", "Loopback0", "10.1.0.32~132", "FC00:1::33~1128") REMOVE Unexist IPv6 address
    """
    dummy_lo_interface_v4 = name + "|" + dummy_lo_interface_v4
    dummy_lo_interface_v6 = name + "|" + dummy_lo_interface_v6

    json_patch = [
        {
            "op": "{}".format(op),
            "path": "/LOOPBACK_INTERFACE/{}".format(dummy_lo_interface_v4),
            "value": {}
        },
        {
            "op": "{}".format(op),
            "path": "/LOOPBACK_INTERFACE/{}".format(dummy_lo_interface_v6),
            "value": {}
        }
    ]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_failure(output)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 3
0
def test_lo_interface_tc2_add_duplicate(duthost):
    """ Add v4 and v6 duplicate lo intf to config

    Note: the Identifier '/' as changed to '~1'
    Initial Loopback setup in t0
    "LOOPBACK_INTERFACE": {
        "Loopback0": {},
        "Loopback0|10.1.0.32/32": {},
        "Loopback0|FC00:1::32/128": {}
    }
    """
    json_patch = [
        {
            "op": "add",
            "path": "/LOOPBACK_INTERFACE/Loopback0|10.1.0.32~132",
            "value": {}
        },
        {
            "op": "add",
            "path": "/LOOPBACK_INTERFACE/Loopback0|FC00:1::32~1128",
            "value": {}
        }
    ]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32"], [], is_ipv4=True)
        check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128"], [], is_ipv4=False)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 4
0
def setup_env(duthosts, rand_one_dut_hostname, cfg_facts):
    """
    Setup/teardown fixture for acl config
    Args:
        duthosts: list of DUTs.
        rand_selected_dut: The fixture returns a randomly selected DuT.
        cfg_facts: config facts for selected DUT
    """
    duthost = duthosts[rand_one_dut_hostname]

    config_tmpfile = generate_tmpfile(duthost)
    logger.info(
        "config_tmpfile {} Backing up config_db.json".format(config_tmpfile))
    duthost.shell(
        "sudo cp /etc/sonic/config_db.json {}".format(config_tmpfile))

    # Cleanup acl config
    duthost.shell(
        'sonic-db-cli CONFIG_DB keys "ACL_RULE|*" | xargs --no-run-if-empty sonic-db-cli CONFIG_DB del'
    )
    duthost.shell(
        'sonic-db-cli CONFIG_DB keys "ACL_TABLE|*" | xargs --no-run-if-empty sonic-db-cli CONFIG_DB del'
    )

    yield

    logger.info("Restoring config_db.json")
    duthost.shell(
        "sudo cp {} /etc/sonic/config_db.json".format(config_tmpfile))
    delete_tmpfile(duthost, config_tmpfile)

    # Cleanup acl config
    config_reload(duthost)
Exemplo n.º 5
0
def test_cacl_tc7_replace_rule(duthost):
    """ Replace a value from acl rule test
    """
    json_patch = [{
        "op": "replace",
        "path": "/ACL_RULE/TEST_1|TEST_DROP/SRC_IP",
        "value": "8.8.8.8/32"
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
    expect_op_success(duthost, output)

    expected_content_list = [
        "-A INPUT -s 8.8.8.8/32 -p tcp -m tcp --dport 22 -j DROP"
    ]
    unexpected_content_list = [
        "-A INPUT -s 9.9.9.9/32 -p tcp -m tcp --dport 22 -j DROP"
    ]
    expect_res_success_acl_rule(duthost, expected_content_list,
                                unexpected_content_list)

    delete_tmpfile(duthost, tmpfile)
Exemplo n.º 6
0
def bgpmon_tc1_remove(duthost):
    """ Test to remove bgpmon config
    """
    json_patch = [
        {
            "op": "remove",
            "path": "/BGP_MONITORS"
        }
    ]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        output = duthost.shell("show ip bgp summary")
        pytest_assert(not output['rc'],
            "Failed to get info from BGP summary"
        )
        pytest_assert("BGPMonitor" not in output['stdout'],
            "Failed to remove BGPMonitor"
        )
    finally:
        delete_tmpfile(duthost, tmpfile)
def test_portchannel_interface_tc2_xfail(duthost, op, name,
        dummy_portchannel_interface_v4, dummy_portchannel_interface_v6):
    """ Test invalid ip address and remove unexited interface

    ("add", "PortChannel0001", "10.0.0.256/31", "FC00::71/126"), ADD Invalid IPv4 address
    ("add", "PortChannel0001", "10.0.0.56/31", "FC00::xyz/126"), ADD Invalid IPv6 address
    ("remove", "PortChannel0001", "10.0.0.57/31", "FC00::71/126"), REMOVE Unexist IPv4 address
    ("remove", "PortChannel0001", "10.0.0.56/31", "FC00::72/126"), REMOVE Unexist IPv6 address
    """

    dummy_portchannel_interface_v4 = name + "|" + dummy_portchannel_interface_v4
    dummy_portchannel_interface_v6 = name + "|" + dummy_portchannel_interface_v6
    json_patch = [
        {
            "op": "{}".format(op),
            "path": create_path(["PORTCHANNEL_INTERFACE", dummy_portchannel_interface_v4]),
            "value": {}
        },
        {
            "op": "{}".format(op),
            "path": create_path(["PORTCHANNEL_INTERFACE", dummy_portchannel_interface_v6]),
            "value": {}
        }
    ]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_failure(output)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 8
0
def test_pfcwd_interval_config_updates(duthost, ensure_dut_readiness, operation, field_pre_status, is_valid_config_update):
    new_interval = get_new_interval(duthost, is_valid_config_update)

    operation_to_new_value_map = {"add": "{}".format(new_interval), "replace": "{}".format(new_interval), "remove": ""}
    detection_time, restoration_time = get_detection_restoration_times(duthost)
    pre_status = max(detection_time, restoration_time)
    field_pre_status_to_value_map = {"existing": "{}".format(pre_status), "nonexistent": ""}
    
    prepare_pfcwd_interval_config(duthost, field_pre_status_to_value_map[field_pre_status]) 

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {} created for json patch of pfcwd poll interval and operation: {}".format(tmpfile, operation))
    value = operation_to_new_value_map[operation]
    logger.info("value to be added to json patch: {}".format(value))

    json_patch = [
        {
            "op": "{}".format(operation), 
            "path": "/PFC_WD/GLOBAL/POLL_INTERVAL", 
            "value": "{}".format(value)
        }]
    
    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
    
        if is_valid_config_update:
            expect_op_success(duthost, output)
            ensure_application_of_updated_config(duthost, value)
        else:
            expect_op_failure(output)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 9
0
def test_ipv6_neighbor_admin_change(duthost):
    ipv6_neighbor_address, ipv6_neighbor_config = get_ipv6_neighbor(duthost)
    json_patch = [{
        "op":
        "replace",
        "path":
        "/BGP_NEIGHBOR/{}/admin_status".format(ipv6_neighbor_address),
        "value":
        "down"
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        cmds = "show ipv6 bgp su | grep -w {}".format(ipv6_neighbor_address)
        output = duthost.shell(cmds)
        pytest_assert(
            not output['rc'] and "Idle (Admin)" in output['stdout'],
            "BGP Neighbor with addr {} failed to admin down.".format(
                ipv6_neighbor_address))
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 10
0
def test_tacacs_server_tc12_add_duplicate(duthost):
    """ Test tacacs server add duplicate server

    Mannually add DEFAULT_TACACS_SERVER, then add duplicate for test.
    """
    add_tacacs_server(duthost, DEFAULT_TACACS_SERVER)

    json_patch = [{
        "op": "add",
        "path": "/TACPLUS_SERVER/{}".format(DEFAULT_TACACS_SERVER),
        "value": {
            "priority": "1",
            "tcp_port": "49"
        }
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        tacacs_servers = parse_tacacs_server(duthost)
        pytest_assert(DEFAULT_TACACS_SERVER in tacacs_servers,
                      "tacacs server add duplicate failed.")

    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 11
0
def bgp_speaker_tc1_rm_dummy_ip_range(duthost):
    """ Test to remove dummy ip range to existed config
    """
    json_patch = [{
        "op": "remove",
        "path": "/BGP_PEER_RANGE/{}/ip_range/1".format(BGPSPEAKER_V4)
    }, {
        "op": "remove",
        "path": "/BGP_PEER_RANGE/{}/ip_range/1".format(BGPSPEAKER_V6)
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        bgp_config = show_bgp_running_config(duthost)
        pytest_assert(
            not re.search(
                BGPSPEAKER_IP_RANGE_RE.format(DUMMY_IP_RANGE_V4,
                                              BGPSPEAKER_V4), bgp_config)
            and not re.search(
                BGPSPEAKER_IP_RANGE_RE.format(DUMMY_IP_RANGE_V6,
                                              BGPSPEAKER_V6), bgp_config),
            "Failed to remove bgp speaker dummy ip range.")

    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 12
0
def test_tacacs_server_tc11_add_invalid(duthost, tacacs_server_options,
                                        invalid_input):
    """ Test invalid input for tacacs server

    valid input restriction:
        auth_type:[chap, pap, mschap, login]
        passkey: cannot contain space, "#" and ","
        priority: range[1, 64]
        tcp_port: [0, 65535]
        timeout: range[1, 60]
    """
    cleanup_tacacs_server(duthost)

    json_patch = [{
        "op": "add",
        "path": "/TACPLUS_SERVER",
        "value": {
            DEFAULT_TACACS_SERVER: {
                tacacs_server_options: invalid_input
            }
        }
    }]
    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_failure(output)

    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 13
0
def test_tacacs_global_tc7_duplicate_input(duthost):
    """ Test tacacs global duplicate input
    """
    tacacs_add_init_config_with_table(duthost)

    TACACS_ADD_CONFIG = {
        "auth_type": "pap",
        "passkey": "testing123",
        "timeout": "5"
    }
    json_patch = [{
        "op": "add",
        "path": "/TACPLUS",
        "value": {
            "global": TACACS_ADD_CONFIG
        }
    }]
    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        for tacacs_global_type, value in TACACS_ADD_CONFIG.items():
            pytest_assert(
                get_tacacs_global_type_value(duthost,
                                             tacacs_global_type) == value,
                "TACACS global {} failed to apply".format(tacacs_global_type))
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 14
0
def test_tacacs_global_tc6_invalid_input(duthost, tacacs_global_type,
                                         invalid_input):
    """ Test tacacs global invalid input

    option restriction:
        auth_type:[chap, pap, mschap, login]
        passkey: cannot contain space, "#" and ","
        timeout: range[1, 60]
    """
    json_patch = [{
        "op": "add",
        "path": "/TACPLUS",
        "value": {
            "global": {
                tacacs_global_type: invalid_input
            }
        }
    }]
    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_failure(output)

    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 15
0
def bgpmon_tc1_add_duplicate(duthost, bgpmon_setup_info):
    """ Test to add duplicate config to bgpmon
    """
    peer_addr, local_addr, bgp_asn = bgpmon_setup_info
    json_patch = [
        {
            "op": "add",
            "path": "/BGP_MONITORS/{}".format(peer_addr),
            "value": {
                "admin_status": "up",
                "asn": bgp_asn,
                "holdtime": "180",
                "keepalive": "60",
                "local_addr": local_addr,
                "name": "BGPMonitor",
                "nhopself": "0",
                "rrclient": "0"
            }
        }
    ]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        check_bgpmon_with_addr(duthost, peer_addr)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 16
0
def test_add_deleted_ipv6_neighbor(duthost, ensure_dut_readiness):
    ipv6_neighbor_address, ipv6_neighbor_config = get_ipv6_neighbor(duthost)
    neighbor_exists = check_neighbor_existence(duthost, ipv6_neighbor_address)
    pytest_assert(neighbor_exists, "Nonexistent ipv6 BGP neighbor")

    duthost.shell(
        'config bgp remove neighbor {}'.format(ipv6_neighbor_address))
    neighbor_exists = check_neighbor_existence(duthost, ipv6_neighbor_address)
    pytest_assert(not neighbor_exists,
                  "Failed to remove ipv6 BGP neighbor under test")

    json_patch = [{
        "op": "add",
        "path": "/BGP_NEIGHBOR/{}".format(ipv6_neighbor_address),
        "value": ipv6_neighbor_config
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)
        neighbor_exists = check_neighbor_existence(duthost,
                                                   ipv6_neighbor_address)
        pytest_assert(neighbor_exists,
                      "GCU failed to add back deleted ipv6 BGP neighbor")
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 17
0
def bgpmon_tc1_admin_change(duthost, bgpmon_setup_info):
    """ Test to admin down bgpmon config
    """
    peer_addr, _, _ = bgpmon_setup_info
    json_patch = [
        {
            "op": "replace",
            "path": "/BGP_MONITORS/{}/admin_status".format(peer_addr),
            "value": "down"
        }
    ]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        cmds = "show ip bgp summary | grep -w {}".format(peer_addr)
        output = duthost.shell(cmds)
        pytest_assert(not output['rc'] and "Idle (Admin)" in output['stdout'],
            "BGPMonitor with addr {} failed to admin down.".format(peer_addr)
        )
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 18
0
def test_vlan_interface_tc2_xfail(duthost, op, name, dummy_vlan_interface_v4,
                                  dummy_vlan_interface_v6):
    """ Test expect fail testcase

    ("add", "Vlan1000", "587.168.0.1/21", "fc02:1000::1/64"), ADD Invalid IPv4 address
    ("add", "Vlan1000", "192.168.0.1/21", "fc02:1000::xyz/64"), ADD Invalid IPv6 address
    ("remove", "Vlan1000", "192.168.0.2/21", "fc02:1000::1/64"), REMOVE Unexist IPv4 address
    ("remove", "Vlan1000", "192.168.0.1/21", "fc02:1000::2/64") REMOVE Unexist IPv6 address
    """
    dummy_vlan_interface_v4 = name + "|" + dummy_vlan_interface_v4
    dummy_vlan_interface_v6 = name + "|" + dummy_vlan_interface_v6

    json_patch = [{
        "op":
        "{}".format(op),
        "path":
        create_path(["VLAN_INTERFACE", dummy_vlan_interface_v4]),
        "value": {}
    }, {
        "op":
        "{}".format(op),
        "path":
        create_path(["VLAN_INTERFACE", dummy_vlan_interface_v6]),
        "value": {}
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_failure(output)
    finally:
        delete_tmpfile(duthost, tmpfile)
def test_portchannel_interface_tc2_add_duplicate(duthost):
    """ Test adding duplicate portchannel interface
    """
    json_patch = [
        {
            "op": "add",
            "path": create_path(["PORTCHANNEL_INTERFACE", "PortChannel0001|10.0.0.56/31"]),
            "value": {}
        },
        {
            "op": "add",
            "path": create_path(["PORTCHANNEL_INTERFACE", "PortChannel0001|FC00::71/126"]),
            "value": {}
        }
    ]

    logger.info("json patch {}".format(json_patch))

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        check_show_ip_intf(duthost, "PortChannel0001", ["10.0.0.56/31"], [], is_ipv4=True)
        check_show_ip_intf(duthost, "PortChannel0001", ["fc00::71/126"], [], is_ipv4=False)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 20
0
def cacl_tc7_add_duplicate_rule(duthost):
    """ Add duplicate acl rule for test
    """
    json_patch = [{
        "op": "add",
        "path": "/ACL_RULE",
        "value": {
            "SSH_ONLY|TEST_DROP": {
                "L4_DST_PORT": "22",
                "IP_PROTOCOL": "6",
                "IP_TYPE": "IP",
                "PACKET_ACTION": "DROP",
                "PRIORITY": "9998",
                "SRC_IP": "9.9.9.9/32"
            }
        }
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)
    finally:
        delete_tmpfile(duthost, tmpfile)
def test_portchannel_interface_tc5_modify_attribute(duthost, op, name, attr, value):
    """Test PortChannelXXXX attribute change

    ("replace", "PortChannel0001", "mtu", "3324"), mtu change
    ("replace", "PortChannel0001", "min_links", "2"), min_link change
    ("replace", "PortChannel0001", "admin_status", "down"), admin_status change
    """
    json_patch = [
        {
            "op": "{}".format(op),
            "path": "/PORTCHANNEL/{}/{}".format(name, attr),
            "value": "{}".format(value)
        }
    ]

    logger.info("json patch {}".format(json_patch))

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        verify_po_running(duthost)
        verify_attr_change(duthost, name, attr, value)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 22
0
def test_incremental_qos_config_updates(duthost, tbinfo, ensure_dut_readiness,
                                        configdb_field, operation):
    pytest_require('2700' in duthost.facts['hwsku'],
                   "This test only runs on Mellanox 2700 devices")
    tmpfile = generate_tmpfile(duthost)
    logger.info(
        "tmpfile {} created for json patch of field: {} and operation: {}".
        format(tmpfile, configdb_field, operation))

    if operation == "remove":
        value = ""
    else:
        value = calculate_field_value(duthost, tbinfo, configdb_field)
    logger.info(
        "value to be added to json patch: {} operation: {} field: {}".format(
            value, operation, configdb_field))

    json_patch = [{
        "op": "{}".format(operation),
        "path": "/BUFFER_POOL/{}".format(configdb_field),
        "value": "{}".format(value)
    }]

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)
        ensure_application_of_updated_config(duthost, configdb_field, value)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 23
0
def test_cacl_tc5_add_init_rule(duthost):
    """ Add acl rule for test
    """
    json_patch = [{
        "op": "add",
        "path": "/ACL_RULE",
        "value": {
            "TEST_1|TEST_DROP": {
                "L4_DST_PORT": "22",
                "IP_PROTOCOL": "6",
                "IP_TYPE": "IP",
                "PACKET_ACTION": "DROP",
                "PRIORITY": "9998",
                "SRC_IP": "9.9.9.9/32"
            }
        }
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
    expect_op_success(duthost, output)

    expected_content_list = [
        "-A INPUT -s 9.9.9.9/32 -p tcp -m tcp --dport 22 -j DROP"
    ]
    expect_res_success_acl_rule(duthost, expected_content_list, [])

    delete_tmpfile(duthost, tmpfile)
Exemplo n.º 24
0
def test_syslog_server_tc3_xfail(duthost, init_syslog_config, op,
                                 dummy_syslog_server_v4,
                                 dummy_syslog_server_v6):
    """ Test expect fail testcase

    ("add", "10.0.0.587", "cc98:2008::1"), ADD Invalid IPv4 address
    ("add", "10.0.0.5", "cc98:2008::xyz"), ADD Invalid IPv6 address
    ("remove", "10.0.0.6", "cc98:2008:1"), REMOVE Unexist IPv4 address
    ("remove", "10.0.0.5", "cc98:2008::2") REMOVE Unexist IPv6 address
    """
    if init_syslog_config != CONFIG_ADD_DEFAULT:
        pytest.skip("Unsupported initial config")

    json_patch = [{
        "op": "{}".format(op),
        "path": "/SYSLOG_SERVER/{}".format(dummy_syslog_server_v4),
        "value": {}
    }, {
        "op": "{}".format(op),
        "path": "/SYSLOG_SERVER/{}".format(dummy_syslog_server_v6),
        "value": {}
    }]
    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_failure(output)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 25
0
def test_cacl_tc1_add_init_table(duthost):
    """ Add acl table for test

    Sample output
    admin@vlab-01:~$ show acl table
    Name    Type       Binding    Description    Stage
    ------  ---------  ---------  -------------  -------
    TEST_1  CTRLPLANE  SNMP       Test Table 1   ingress
    """
    json_patch = [{
        "op": "add",
        "path": "/ACL_TABLE",
        "value": {
            "TEST_1": {
                "policy_desc": "Test Table 1",
                "services": ["SNMP"],
                "stage": "ingress",
                "type": "CTRLPLANE"
            }
        }
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
    expect_op_success(duthost, output)

    expected_content_list = ["TEST_1", "SNMP"]
    expect_res_success_acl_table(duthost, expected_content_list, [])

    delete_tmpfile(duthost, tmpfile)
Exemplo n.º 26
0
def test_syslog_server_tc4_remove(duthost, init_syslog_config, op,
                                  dummy_syslog_server_v4,
                                  dummy_syslog_server_v6):
    """ Remove v4 and v6 syslog server

    admin@vlab-01:~$ show runningconfiguration syslog
    Sample output:
    Syslog Servers
    ----------------
    """
    if init_syslog_config != CONFIG_ADD_DEFAULT:
        pytest.skip("Unsupported initial config")

    json_patch = [{"op": "{}".format(op), "path": "/SYSLOG_SERVER"}]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        unexpected_content_list = [
            "[{}]".format(dummy_syslog_server_v4),
            "[{}]".format(dummy_syslog_server_v6)
        ]
        expect_res_success_syslog(duthost, [], unexpected_content_list)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 27
0
def test_lo_interface_tc6_vrf_change(duthost):
    """ Replace lo interface vrf

    admin@vlab-01:~$ show ip interfaces | grep Loopback0
    Loopback0        Vrf_02    10.1.0.32/32         up/up         N/A             N/A
    admin@vlab-01:~$ show ipv6 interfaces | grep Loopback0
    Loopback0        Vrf_02           fc00:1::32/128                              up/up         N/A             N/A
                                      fe80::a8cb:e8ff:fe6e:df6e%Loopback0/64                    N/A             N/A
    admin@vlab-01:~$ show ip route vrf Vrf_02
    VRF Vrf_02:
    C>* 10.1.0.32/32 is directly connected, Loopback0, 00:00:17
    """
    setup_vrf_config(duthost)
    json_patch = [
        {
            "op": "replace",
            "path": "/LOOPBACK_INTERFACE/Loopback0/vrf_name",
            "value": "Vrf_02"
        }
    ]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32", "Vrf_02"], [], is_ipv4=True)
        check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128", "Vrf_02"], [], is_ipv4=False)

        check_vrf_route_for_intf(duthost, "Vrf_02", "Loopback0", is_ipv4=True)
        check_vrf_route_for_intf(duthost, "Vrf_02", "Loopback0", is_ipv4=False)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 28
0
def test_replace_mtu(duthost, ensure_dut_readiness):
    # Can't directly change mtu of the port channel member
    # So find a ethernet port that are not in a port channel
    port_name = get_ethernet_port_not_in_portchannel(duthost)
    pytest_assert(
        port_name,
        "No available ethernet ports, all ports are in port channels.")
    target_mtu = "1514"
    json_patch = [{
        "op": "replace",
        "path": "/PORT/{}/mtu".format(port_name),
        "value": "{}".format(target_mtu)
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)
        current_status_mtu = check_interface_status(duthost, "MTU", port_name)
        pytest_assert(
            current_status_mtu == target_mtu,
            "Failed to properly configure interface MTU to requested value {}".
            format(target_mtu))
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 29
0
def test_update_speed(duthost, ensure_dut_readiness, speed, is_valid):
    json_patch = [{
        "op": "replace",
        "path": "/PORT/Ethernet0/speed",
        "value": "{}".format(speed)
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        if is_valid:
            expect_op_success(duthost, output)
            current_status_speed = check_interface_status(duthost,
                                                          "Speed").replace(
                                                              "G", "000")
            pytest_assert(
                current_status_speed == speed,
                "Failed to properly configure interface speed to requested value {}"
                .format(speed))
        else:
            expect_op_failure(output)
    finally:
        delete_tmpfile(duthost, tmpfile)
Exemplo n.º 30
0
def test_aaa_tc3_add_duplicate(duthost):
    """ Test add duplicate config in AAA sub type
    """
    aaa_add_init_config_with_table(duthost)
    json_patch = [{
        "op": "add",
        "path": "/AAA/authorization/login",
        "value": "local"
    }, {
        "op": "add",
        "path": "/AAA/authentication/login",
        "value": "local"
    }, {
        "op": "add",
        "path": "/AAA/accounting/login",
        "value": "local"
    }]

    tmpfile = generate_tmpfile(duthost)
    logger.info("tmpfile {}".format(tmpfile))

    try:
        output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
        expect_op_success(duthost, output)

        for aaa_type in AAA_CATEGORY:
            pytest_assert(
                get_aaa_sub_options_value(duthost, aaa_type,
                                          "login") == "local",
                "Failed to verify AAA {} {}".format(aaa_type, "login"))
    finally:
        delete_tmpfile(duthost, tmpfile)