|
| 1 | +import pytest |
| 2 | +import logging |
| 3 | + |
| 4 | +from tests.common.helpers.assertions import pytest_assert |
| 5 | +from tests.common.utilities import wait_until |
| 6 | +from tests.common.vxlan_ecmp_utils import Ecmp_Utils |
| 7 | +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError |
| 8 | + |
| 9 | +pytestmark = [ |
| 10 | + # This script is only meant to be run on T1 switches. |
| 11 | + pytest.mark.topology("t1", "t1-64-lag", "t1-56-lag", "t1-lag"), |
| 12 | + # loganalyzer is disabled to avoid catching unrelated errors and the same error twice. |
| 13 | + pytest.mark.disable_loganalyzer |
| 14 | +] |
| 15 | + |
| 16 | +logger = logging.getLogger(__name__) |
| 17 | +ecmp_utils = Ecmp_Utils() |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture(scope="module", autouse=True) |
| 21 | +def setup_ecmp_utils(duthost): |
| 22 | + # Need to set these constants before calling any ecmp_utils function. |
| 23 | + ecmp_utils.Constants["KEEP_TEMP_FILES"] = False |
| 24 | + ecmp_utils.Constants["DEBUG"] = True |
| 25 | + ecmp_utils.Constants["DUT_HOSTID"] = 1 |
| 26 | + |
| 27 | + |
| 28 | +@pytest.fixture |
| 29 | +def configure_vxlan_global_params(duthost): |
| 30 | + """ |
| 31 | + Fixture to configure global VxLAN parameters before a test and restore previous values after the test. |
| 32 | + """ |
| 33 | + logger.info("Configuring global VxLAN parameters...") |
| 34 | + prev_vxlan_port = duthost.shell("sonic-db-cli APPL_DB HGET 'SWITCH_TABLE:switch' 'vxlan_port'")["stdout"].strip() |
| 35 | + prev_vxlan_router_mac = \ |
| 36 | + duthost.shell("sonic-db-cli APPL_DB HGET 'SWITCH_TABLE:switch' 'vxlan_router_mac'")["stdout"].strip() |
| 37 | + router_mac = duthost.facts["router_mac"] |
| 38 | + ecmp_utils.configure_vxlan_switch(duthost, dutmac=router_mac) |
| 39 | + yield |
| 40 | + if prev_vxlan_port: |
| 41 | + ecmp_utils.configure_vxlan_switch(duthost, vxlan_port=int(prev_vxlan_port), dutmac=prev_vxlan_router_mac) |
| 42 | + else: |
| 43 | + ecmp_utils.configure_vxlan_switch(duthost, dutmac=prev_vxlan_router_mac) |
| 44 | + duthost.shell("sonic-db-cli APPL_DB HDEL 'SWITCH_TABLE:switch' 'vxlan_port'") |
| 45 | + if not prev_vxlan_router_mac: |
| 46 | + duthost.shell("sonic-db-cli APPL_DB HDEL 'SWITCH_TABLE:switch' 'vxlan_router_mac'") |
| 47 | + |
| 48 | + |
| 49 | +def are_keys_in_app_db(duthost, table, keys, check_exist="all"): |
| 50 | + """ |
| 51 | + Function to check if all or none of keys in "keys" exist in APP DB under the specified table. |
| 52 | + :param check_exist: "all" to check if all keys exist, "none" to check if none of the keys exist. |
| 53 | + """ |
| 54 | + for key in keys: |
| 55 | + result = duthost.shell(f"sonic-db-cli APPL_DB KEYS '{table}:{key}'")["stdout_lines"] |
| 56 | + if check_exist == "all" and not result: |
| 57 | + return False |
| 58 | + if check_exist == "none" and result: |
| 59 | + return False |
| 60 | + return True |
| 61 | + |
| 62 | + |
| 63 | +def are_vnet_routes_in_asic_db(duthost, dests, check_exist="all"): |
| 64 | + """ |
| 65 | + Function to check if all of or none of VNET routes to destinations in dests are present in ASIC DB. |
| 66 | + :param check_exist: "all" to check if VNET routes to all destinations exist, |
| 67 | + "none" to check if no VNET route to destinations exist. |
| 68 | + """ |
| 69 | + for dest in dests: |
| 70 | + result = duthost.shell(f"sonic-db-cli ASIC_DB KEYS \ |
| 71 | + 'ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY*{dest}*'")["stdout_lines"] |
| 72 | + if check_exist == "all" and not result: |
| 73 | + return False |
| 74 | + if check_exist == "none" and result: |
| 75 | + return False |
| 76 | + return True |
| 77 | + |
| 78 | + |
| 79 | +@pytest.fixture |
| 80 | +def setup(duthost, tbinfo, configure_vxlan_global_params): |
| 81 | + tunnel_v4 = "" |
| 82 | + tunnel_v6 = "" |
| 83 | + vnet4 = "" |
| 84 | + vnet6 = "" |
| 85 | + vnet4_dest_to_endpoint_map = {} |
| 86 | + vnet6_dest_to_endpoint_map = {} |
| 87 | + try: |
| 88 | + minigraph_facts = duthost.get_extended_minigraph_facts(tbinfo) |
| 89 | + |
| 90 | + loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix="TestVxlanError") |
| 91 | + loganalyzer.match_regex = \ |
| 92 | + [r".*SAI_NEXT_HOP_ATTR_TUNNEL_ID:SAI_ATTR_VALUE_TYPE_OBJECT_ID object on list \[0\] is NULL, but not allowed.*"] # noqa E501 |
| 93 | + with loganalyzer: |
| 94 | + logger.info("Creating IPv4 and IPv6 VxLAN tunnels...") |
| 95 | + tunnel_v4 = ecmp_utils.create_vxlan_tunnel(duthost, minigraph_facts, af="v4") |
| 96 | + tunnel_v6 = ecmp_utils.create_vxlan_tunnel(duthost, minigraph_facts, af="v6") |
| 97 | + pytest_assert(wait_until(10, 2, 0, are_keys_in_app_db, duthost, "VXLAN_TUNNEL_TABLE", |
| 98 | + [tunnel_v4, tunnel_v6]), "VxLAN tunnels are not configured in APP DB.") |
| 99 | + |
| 100 | + logger.info("Creating IPv4 and IPv6 VNETs...") |
| 101 | + vnet4_dict = ecmp_utils.create_vnets(duthost, tunnel_v4, scope="default", |
| 102 | + vnet_name_prefix="Vnet_v4", advertise_prefix="true") |
| 103 | + vnet4 = next(iter(vnet4_dict)) # The first (and only) key is the VNET name |
| 104 | + vnet6_dict = ecmp_utils.create_vnets(duthost, tunnel_v6, scope="default", |
| 105 | + vnet_name_prefix="Vnet_v6", advertise_prefix="true") |
| 106 | + vnet6 = next(iter(vnet6_dict)) # The first (and only) key is the VNET name |
| 107 | + pytest_assert(wait_until(10, 2, 0, are_keys_in_app_db, duthost, "VNET_TABLE", [vnet4, vnet6]), |
| 108 | + "VNETs are not configured in APP DB.") |
| 109 | + |
| 110 | + logger.info("Creating IPv4 and IPv6 VNET routes...") |
| 111 | + vnet4_dest_to_endpoint_map = ecmp_utils.create_vnet_routes(duthost, [vnet4], dest_af="v4", nh_af="v4", |
| 112 | + number_of_available_nexthops=1, |
| 113 | + number_of_ecmp_nhs=1) |
| 114 | + vnet6_dest_to_endpoint_map = ecmp_utils.create_vnet_routes(duthost, [vnet6], dest_af="v6", nh_af="v6", |
| 115 | + number_of_available_nexthops=1, |
| 116 | + number_of_ecmp_nhs=1) |
| 117 | + dests = [] |
| 118 | + dests.extend(vnet4_dest_to_endpoint_map[vnet4].keys()) |
| 119 | + dests.extend(vnet6_dest_to_endpoint_map[vnet6].keys()) |
| 120 | + pytest_assert(wait_until(10, 2, 0, are_vnet_routes_in_asic_db, duthost, dests), |
| 121 | + "VNET routes are not in ASIC DB.") |
| 122 | + yield |
| 123 | + except LogAnalyzerError as err: |
| 124 | + pytest.fail(str(err)) |
| 125 | + finally: |
| 126 | + logger.info("Deleting VNET routes...") |
| 127 | + dests = [] |
| 128 | + if vnet4_dest_to_endpoint_map: |
| 129 | + ecmp_utils.set_routes_in_dut(duthost, vnet4_dest_to_endpoint_map, "v4", "DEL") |
| 130 | + dests.extend(vnet4_dest_to_endpoint_map[vnet4].keys()) |
| 131 | + if vnet6_dest_to_endpoint_map: |
| 132 | + ecmp_utils.set_routes_in_dut(duthost, vnet6_dest_to_endpoint_map, "v6", "DEL") |
| 133 | + dests.extend(vnet6_dest_to_endpoint_map[vnet6].keys()) |
| 134 | + pytest_assert(wait_until(10, 2, 0, are_vnet_routes_in_asic_db, duthost, dests, "none"), |
| 135 | + "Could not remove VNET routes from ASIC DB.") |
| 136 | + |
| 137 | + logger.info("Deleting VNETs...") |
| 138 | + vnets = [] |
| 139 | + if vnet4: |
| 140 | + duthost.shell(f"sonic-db-cli CONFIG_DB DEL 'VNET|{vnet4}'") |
| 141 | + vnets.append(vnet4) |
| 142 | + if vnet6: |
| 143 | + duthost.shell(f"sonic-db-cli CONFIG_DB DEL 'VNET|{vnet6}'") |
| 144 | + vnets.append(vnet6) |
| 145 | + pytest_assert(wait_until(10, 2, 0, are_keys_in_app_db, duthost, "VNET_TABLE", vnets, "none"), |
| 146 | + "Could not remove VNETS from APP DB.") |
| 147 | + |
| 148 | + logger.info("Deleting VxLAN tunnels...") |
| 149 | + tunnels = [] |
| 150 | + if tunnel_v4: |
| 151 | + duthost.shell(f"sonic-db-cli CONFIG_DB DEL 'VXLAN_TUNNEL|{tunnel_v4}'") |
| 152 | + tunnels.append(tunnel_v4) |
| 153 | + if tunnel_v6: |
| 154 | + duthost.shell(f"sonic-db-cli CONFIG_DB DEL 'VXLAN_TUNNEL|{tunnel_v6}'") |
| 155 | + tunnels.append(tunnel_v6) |
| 156 | + pytest_assert(wait_until(10, 2, 0, are_keys_in_app_db, duthost, "VXLAN_TUNNEL_TABLE", tunnels, "none"), |
| 157 | + "Could not remove VxLAN tunnels from APP DB.") |
| 158 | + |
| 159 | + |
| 160 | +def test_vxlan_error_null_tunnel_id(setup): |
| 161 | + """ |
| 162 | + This test ensures that the following error does not happen |
| 163 | + when configuring IPv4 and IPv6 VxLAN, VNET, and VNET routes: |
| 164 | + ERR swss#orchagent: :- meta_generic_validation_objlist: SAI_NEXT_HOP_ATTR_TUNNEL_ID:SAI_ATTR_VALUE_TYPE_OBJECT_ID object on list [0] is NULL, but not allowed # noqa E501 |
| 165 | + """ |
| 166 | + pass |
0 commit comments