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)
Example #2
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)
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)
Example #4
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)
Example #5
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)
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
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)
Example #11
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)
Example #12
0
def bgp_prefix_tc1_remove(duthost, community):
    """ Test to remove prefix config
    """
    json_patch = [
        {
            "op": "remove",
            "path": "/BGP_ALLOWED_PREFIXES"
        }
    ]

    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(PREFIXES_V4_RE.format(community, PREFIXES_V4_DUMMY), bgp_config),
            "Failed to remove bgp prefix v4 config."
        )
        pytest_assert(
            not re.search(PREFIXES_V6_RE.format(community, PREFIXES_V6_DUMMY), bgp_config),
            "Failed to remove bgp prefix v6 config."
        )

    finally:
        delete_tmpfile(duthost, tmpfile)
Example #13
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)
Example #14
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)
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)
Example #16
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)
Example #17
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)
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)
Example #19
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)
Example #20
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)
Example #21
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)
Example #22
0
def test_aaa_tc1_add_config(duthost, aaa_type, aaa_sub_options):
    """ Test AAA add initial config for its sub type

    This test is for default setting when configDB doesn't
    contian AAA table. So we remove AAA config at first.
    """
    aaa_add_init_config_without_table(duthost)
    json_patch = [{
        "op": "add",
        "path": "/AAA",
        "value": {
            "{}".format(aaa_type): aaa_sub_options
        }
    }]

    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 option, value in aaa_sub_options.items():
            pytest_assert(
                get_aaa_sub_options_value(duthost, aaa_type, option) == value,
                "Failed to verify AAA {} {}".format(aaa_type, option))
    finally:
        delete_tmpfile(duthost, tmpfile)
Example #23
0
def bgp_speaker_tc1_replace_src_address(duthost):
    """ Test to replace dummy src_address to existed config
    """
    json_patch = [
        {
            "op": "replace",
            "path": "/BGP_PEER_RANGE/{}/src_address".format(BGPSPEAKER_V4),
            "value": "{}".format(DUMMY_SRC_ADDRESS_V4)
        },
        {
            "op": "replace",
            "path": "/BGP_PEER_RANGE/{}/src_address".format(BGPSPEAKER_V6),
            "value": "{}".format(DUMMY_SRC_ADDRESS_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(
            re.search(BGPSPEAKER_SRC_ADDR_RE.format(BGPSPEAKER_V4, DUMMY_SRC_ADDRESS_V4), bgp_config) and
            re.search(BGPSPEAKER_SRC_ADDR_RE.format(BGPSPEAKER_V6, DUMMY_SRC_ADDRESS_V6), bgp_config),
            "Failed to replace bgp speaker src address."
        )

    finally:
        delete_tmpfile(duthost, tmpfile)
Example #24
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)
Example #25
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)
Example #26
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)
Example #27
0
def test_portchannel_interface_tc1_add_new_portchannel(duthost):
    """ Clean up original portchannel intf and apply-patch to default config

    Expected output
    admin@vlab-01:~$ show ip interfaces
    Interface        Master    IPv4 address/mask    Admin/Oper    BGP Neighbor    Neighbor IP
    ---------------  --------  -------------------  ------------  --------------  -------------
    ...
    PortChannel0005            10.0.0.64/31         up/down       N/A             N/A
    admin@vlab-01:~$ show ipv6 interfaces
    Interface        Master           IPv4 address/mask                           Admin/Oper    BGP Neighbor    Neighbor IP
    ---------------  ---------------  ------------------------------------------  ------------  --------------  -------------
    ...
    PortChannel0005                   fc00::81/126                                up/down       N/A             N/A
    """

    json_patch = [{
        "op": "add",
        "path": "/PORTCHANNEL/PortChannel0005",
        "value": {
            "admin_status": "up"
        }
    }, {
        "op": "add",
        "path": "/PORTCHANNEL_INTERFACE/PortChannel0005",
        "value": {}
    }, {
        "op":
        "add",
        "path":
        create_path(["PORTCHANNEL_INTERFACE", "PortChannel0005|10.0.0.64/31"]),
        "value": {}
    }, {
        "op":
        "add",
        "path":
        create_path(["PORTCHANNEL_INTERFACE", "PortChannel0005|FC00::81/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,
                           "PortChannel0005", ["10.0.0.64/31"], [],
                           is_ipv4=True)
        check_show_ip_intf(duthost,
                           "PortChannel0005", ["fc00::81/126"], [],
                           is_ipv4=False)
    finally:
        delete_tmpfile(duthost, tmpfile)
Example #28
0
def test_portchannel_interface_tc3_replace(duthost, portchannel_table):
    """ Test portchannel interface replace ip address
    """
    org_ip = portchannel_table["PortChannel101"]["ip"]
    org_ipv6 = portchannel_table["PortChannel101"]["ipv6"]
    rep_ip = "10.0.0.156/31"
    rep_ipv6 = "fc00::171/126"
    json_patch = [{
        "op":
        "remove",
        "path":
        create_path(
            ["PORTCHANNEL_INTERFACE", "PortChannel101|{}".format(org_ip)])
    }, {
        "op":
        "remove",
        "path":
        create_path([
            "PORTCHANNEL_INTERFACE",
            "PortChannel101|{}".format(org_ipv6.upper())
        ])
    }, {
        "op":
        "add",
        "path":
        create_path(
            ["PORTCHANNEL_INTERFACE", "PortChannel101|{}".format(rep_ip)]),
        "value": {}
    }, {
        "op":
        "add",
        "path":
        create_path(
            ["PORTCHANNEL_INTERFACE", "PortChannel101|{}".format(rep_ipv6)]),
        "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,
                           "PortChannel101", [rep_ip], [org_ip],
                           is_ipv4=True)
        check_show_ip_intf(duthost,
                           "PortChannel101", [rep_ipv6], [org_ipv6],
                           is_ipv4=False)
    finally:
        delete_tmpfile(duthost, tmpfile)
Example #29
0
def test_dhcp_relay_tc7_add_rm(duthost, init_dhcp_server_config,
                               vlan_intfs_list):
    """Test mixed add and rm ops for dhcp server on default setup

    This VLAN detail should show below after test
    +-----------+------------------+-----------+----------------+-------------+-----------------------+
    |   VLAN ID | IP Address       | Ports     | Port Tagging   | Proxy ARP   | DHCP Helper Address   |
    +===========+==================+===========+================+=============+=======================+
    |       108 | 192.168.108.1/24 | Ethernet4 | tagged         | disabled    | 192.0.108.1           |
    |           |                  |           |                |             | 192.0.108.2           |
    |           |                  |           |                |             | 192.0.108.3           |
    |           |                  |           |                |             | 192.0.108.4           |
    |           |                  |           |                |             | 192.0.108.5           |
    +-----------+------------------+-----------+----------------+-------------+-----------------------+
    |       109 | 192.168.109.1/24 | Ethernet4 | tagged         | disabled    | 192.0.109.1           |
    |           |                  |           |                |             | 192.0.109.2           |
    |           |                  |           |                |             | 192.0.109.3           |
    +-----------+------------------+-----------+----------------+-------------+-----------------------+
    """
    if init_dhcp_server_config != CONFIG_ADD_DEFAULT:
        pytest.skip("Unsupported init config")

    dhcp_add_rm_json = [{
        "op":
        "remove",
        "path":
        "/VLAN/Vlan" + str(vlan_intfs_list[1]) + "/dhcp_servers/3"
    }, {
        "op": "add",
        "path": "/VLAN/Vlan" + str(vlan_intfs_list[0]) + "/dhcp_servers/4",
        "value": "192.0." + str(vlan_intfs_list[0]) + ".5"
    }]

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

    try:
        output = apply_patch(duthost,
                             json_data=dhcp_add_rm_json,
                             dest_file=tmpfile)
        expect_op_success(duthost, output)
        pytest_assert(duthost.is_service_fully_started('dhcp_relay'),
                      "dhcp_relay service is not running")

        expected_content_list = ["192.0." + str(vlan_intfs_list[0]) + ".5"]
        unexpected_content_list = ["192.0." + str(vlan_intfs_list[1]) + ".4"]
        expect_res_success_by_vlanid(duthost, vlan_intfs_list[0],
                                     expected_content_list, [])
        expect_res_success_by_vlanid(duthost, vlan_intfs_list[1], [],
                                     unexpected_content_list)
    finally:
        delete_tmpfile(duthost, tmpfile)
Example #30
0
def test_syslog_server_tc5_replace(duthost, init_syslog_config, op,
                                   replace_syslog_server_v4,
                                   replace_syslog_server_v6):
    """ Add v4 and v6 duplicate syslog server to config

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

    json_patch = [{
        "op": "remove",
        "path": "/SYSLOG_SERVER/{}".format(SYSLOG_DUMMY_IPV6_SERVER)
    }, {
        "op": "remove",
        "path": "/SYSLOG_SERVER/{}".format(SYSLOG_DUMMY_IPV4_SERVER)
    }, {
        "op": "{}".format(op),
        "path": "/SYSLOG_SERVER/{}".format(replace_syslog_server_v4),
        "value": {}
    }, {
        "op": "{}".format(op),
        "path": "/SYSLOG_SERVER/{}".format(replace_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_success(duthost, output)

        expected_content_list = [
            "[{}]".format(replace_syslog_server_v4),
            "[{}]".format(replace_syslog_server_v6)
        ]
        unexpected_content_list = [
            "[{}]".format(SYSLOG_DUMMY_IPV4_SERVER),
            "[{}]".format(SYSLOG_DUMMY_IPV6_SERVER)
        ]
        expect_res_success_syslog(duthost, expected_content_list,
                                  unexpected_content_list)
    finally:
        delete_tmpfile(duthost, tmpfile)