diff --git a/scripts/dualtor_neighbor_check.py b/scripts/dualtor_neighbor_check.py index c26b833daf..5ceb327c4c 100755 --- a/scripts/dualtor_neighbor_check.py +++ b/scripts/dualtor_neighbor_check.py @@ -35,7 +35,7 @@ -- - HW_MUX_CABLE_TABLE -- - NEIGH_TABLE -- ASIC_DB: --- - ASIC_STATE (route entries, neighbor entries, nexthop entries) +-- - ASIC_STATE -- -- KEYS - None -- ARGV[1] - APPL_DB db index @@ -76,7 +76,6 @@ local asic_fdb = {} local asic_route_table = {} local asic_neighbor_table = {} -local asic_nexthop_table = {} -- read from APPL_DB redis.call('SELECT', APPL_DB) @@ -127,16 +126,12 @@ asic_fdb[mac] = bridge_port_id end --- read ASIC route table with nexthop information +-- read ASIC route table local route_prefix = asic_state_table_name .. ASIC_DB_SEPARATOR .. asic_route_key_prefix local route_entries = redis.call('KEYS', route_prefix .. '*') for i, route_entry in ipairs(route_entries) do local route_details = string.sub(route_entry, string.len(route_prefix) + 2) - local nexthop_id = redis.call('HGET', route_entry, 'SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID') - local route_info = {} - route_info['route_details'] = route_details - route_info['nexthop_id'] = nexthop_id - table.insert(asic_route_table, route_info) + table.insert(asic_route_table, route_details) end -- read ASIC neigh table @@ -147,24 +142,6 @@ table.insert(asic_neighbor_table, neighbor_details) end --- read ASIC nexthop table -local nexthop_prefix = asic_state_table_name .. ASIC_DB_SEPARATOR .. 'SAI_OBJECT_TYPE_NEXT_HOP:' -local nexthop_entries = redis.call('KEYS', nexthop_prefix .. '*') -for i, nexthop_entry in ipairs(nexthop_entries) do - local nexthop_id = string.sub(nexthop_entry, string.len(nexthop_prefix) + 1) - local nexthop_type = redis.call('HGET', nexthop_entry, 'SAI_NEXT_HOP_ATTR_TYPE') - local nexthop_info = {} - nexthop_info['nexthop_id'] = nexthop_id - nexthop_info['nexthop_type'] = nexthop_type - - -- Get tunnel ID if it's a tunnel nexthop - if nexthop_type == 'SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP' then - nexthop_info['tunnel_id'] = redis.call('HGET', nexthop_entry, 'SAI_NEXT_HOP_ATTR_TUNNEL_ID') - end - - asic_nexthop_table[nexthop_id] = nexthop_info -end - local result = {} result['neighbors'] = neighbors result['mux_states'] = mux_states @@ -172,15 +149,13 @@ result['asic_fdb'] = asic_fdb result['asic_route_table'] = asic_route_table result['asic_neigh_table'] = asic_neighbor_table -result['asic_nexthop_table'] = asic_nexthop_table return redis.status_reply(cjson.encode(result)) """ DB_READ_SCRIPT_CONFIG_DB_KEY = "_DUALTOR_NEIGHBOR_CHECK_SCRIPT_SHA1" ZERO_MAC = "00:00:00:00:00:00" -NEIGHBOR_ATTRIBUTES = ["NEIGHBOR", "MAC", "PORT", "MUX_STATE", "IN_MUX_TOGGLE", "NEIGHBOR_IN_ASIC", "PREFIX_ROUTE", - "NEXTHOP_TYPE", "HWSTATUS"] +NEIGHBOR_ATTRIBUTES = ["NEIGHBOR", "MAC", "PORT", "MUX_STATE", "IN_MUX_TOGGLE", "NEIGHBOR_IN_ASIC", "TUNNEL_IN_ASIC", "HWSTATUS"] NOT_AVAILABLE = "N/A" @@ -355,15 +330,13 @@ def _is_script_existed(script_sha1): asic_fdb = {k: v.lstrip("oid:0x") for k, v in tables["asic_fdb"].items()} asic_route_table = tables["asic_route_table"] asic_neigh_table = tables["asic_neigh_table"] - asic_nexthop_table = tables["asic_nexthop_table"] WRITE_LOG_DEBUG("neighbors: %s", json.dumps(neighbors, indent=4)) WRITE_LOG_DEBUG("mux states: %s", json.dumps(mux_states, indent=4)) WRITE_LOG_DEBUG("hw mux states: %s", json.dumps(hw_mux_states, indent=4)) WRITE_LOG_DEBUG("ASIC FDB: %s", json.dumps(asic_fdb, indent=4)) WRITE_LOG_DEBUG("ASIC route table: %s", json.dumps(asic_route_table, indent=4)) WRITE_LOG_DEBUG("ASIC neigh table: %s", json.dumps(asic_neigh_table, indent=4)) - WRITE_LOG_DEBUG("ASIC nexthop table: %s", json.dumps(asic_nexthop_table, indent=4)) - return neighbors, mux_states, hw_mux_states, asic_fdb, asic_route_table, asic_neigh_table, asic_nexthop_table + return neighbors, mux_states, hw_mux_states, asic_fdb, asic_route_table, asic_neigh_table def get_if_br_oid_to_port_name_map(): @@ -417,33 +390,10 @@ def get_mac_to_port_name_map(asic_fdb, if_oid_to_port_name_map): def check_neighbor_consistency(neighbors, mux_states, hw_mux_states, mac_to_port_name_map, - asic_route_table, asic_neigh_table, asic_nexthop_table, - mux_server_to_port_map): + asic_route_table, asic_neigh_table, mux_server_to_port_map): """Checks if neighbors are consistent with mux states.""" - # Parse route table to get route destinations and their nexthop types - route_to_nexthop_map = {} - asic_route_destinations = set() - - for route_info in asic_route_table: - route_details = json.loads(route_info["route_details"]) - route_dest = route_details["dest"].split("/")[0] - asic_route_destinations.add(route_dest) - - nexthop_id = route_info["nexthop_id"] - - nexthop_type = NOT_AVAILABLE - if nexthop_id in asic_nexthop_table: - nexthop_info = asic_nexthop_table[nexthop_id] - if nexthop_info["nexthop_type"] == "SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP": - nexthop_type = "TUNNEL" - elif nexthop_info["nexthop_type"] == "SAI_NEXT_HOP_TYPE_IP": - nexthop_type = "NEIGHBOR" - else: - nexthop_type = nexthop_info["nexthop_type"] - - route_to_nexthop_map[route_dest] = nexthop_type - + asic_route_destinations = set(json.loads(_)["dest"].split("/")[0] for _ in asic_route_table) asic_neighs = set(json.loads(_)["ip"] for _ in asic_neigh_table) check_results = [] @@ -459,14 +409,12 @@ def check_neighbor_consistency(neighbors, mux_states, hw_mux_states, mac_to_port continue check_result["NEIGHBOR_IN_ASIC"] = neighbor_ip in asic_neighs - check_result["PREFIX_ROUTE"] = neighbor_ip in asic_route_destinations - check_result["NEXTHOP_TYPE"] = route_to_nexthop_map.get(neighbor_ip, NOT_AVAILABLE) - + check_result["TUNNEL_IN_ASIC"] = neighbor_ip in asic_route_destinations if is_zero_mac: # NOTE: for zero-mac neighbors, two situations: # 1. new neighbor just learnt, no neighbor entry in ASIC, tunnel route present in ASIC. # 2. neighbor expired, neighbor entry still present in ASIC, no tunnel route in ASIC. - check_result["HWSTATUS"] = check_result["NEIGHBOR_IN_ASIC"] or check_result["PREFIX_ROUTE"] + check_result["HWSTATUS"] = check_result["NEIGHBOR_IN_ASIC"] or check_result["TUNNEL_IN_ASIC"] else: port_name = mac_to_port_name_map[mac] # NOTE: mux server ips are always fixed to the mux port @@ -479,16 +427,9 @@ def check_neighbor_consistency(neighbors, mux_states, hw_mux_states, mac_to_port check_result["IN_MUX_TOGGLE"] = mux_state != hw_mux_state if mux_state == "active": - # For active mux state, neighbor should be in ASIC and route should point to neighbor nexthop - expected_nexthop = "NEIGHBOR" - check_result["HWSTATUS"] = (check_result["NEIGHBOR_IN_ASIC"] and - check_result["PREFIX_ROUTE"] and - check_result["NEXTHOP_TYPE"] == expected_nexthop) + check_result["HWSTATUS"] = (check_result["NEIGHBOR_IN_ASIC"] and (not check_result["TUNNEL_IN_ASIC"])) elif mux_state == "standby": - # For standby mux state, route should point to tunnel nexthop - expected_nexthop = "TUNNEL" - check_result["HWSTATUS"] = (check_result["PREFIX_ROUTE"] and - check_result["NEXTHOP_TYPE"] == expected_nexthop) + check_result["HWSTATUS"] = ((not check_result["NEIGHBOR_IN_ASIC"]) and check_result["TUNNEL_IN_ASIC"]) else: # skip as unknown mux state continue @@ -513,7 +454,7 @@ def parse_check_results(check_results): if not is_zero_mac: check_result["IN_MUX_TOGGLE"] = bool_to_yes_no[in_toggle] check_result["NEIGHBOR_IN_ASIC"] = bool_to_yes_no[check_result["NEIGHBOR_IN_ASIC"]] - check_result["PREFIX_ROUTE"] = bool_to_yes_no[check_result["PREFIX_ROUTE"]] + check_result["TUNNEL_IN_ASIC"] = bool_to_yes_no[check_result["TUNNEL_IN_ASIC"]] check_result["HWSTATUS"] = bool_to_consistency[hwstatus] if (not hwstatus): if is_zero_mac: @@ -558,8 +499,7 @@ def parse_check_results(check_results): mux_server_to_port_map = get_mux_server_to_port_map(mux_cables) if_oid_to_port_name_map = get_if_br_oid_to_port_name_map() - neighbors, mux_states, hw_mux_states, asic_fdb, asic_route_table, asic_neigh_table, \ - asic_nexthop_table = read_tables_from_db(appl_db) + neighbors, mux_states, hw_mux_states, asic_fdb, asic_route_table, asic_neigh_table = read_tables_from_db(appl_db) mac_to_port_name_map = get_mac_to_port_name_map(asic_fdb, if_oid_to_port_name_map) check_results = check_neighbor_consistency( @@ -569,7 +509,6 @@ def parse_check_results(check_results): mac_to_port_name_map, asic_route_table, asic_neigh_table, - asic_nexthop_table, mux_server_to_port_map ) res = parse_check_results(check_results) diff --git a/tests/dualtor_neighbor_check_test.py b/tests/dualtor_neighbor_check_test.py index 4cea47e78e..fb9475129c 100644 --- a/tests/dualtor_neighbor_check_test.py +++ b/tests/dualtor_neighbor_check_test.py @@ -202,10 +202,7 @@ def test_read_from_db(self, mock_log_functions): hw_mux_states = {"Ethernet4": "active"} asic_fdb = {"ee:86:d8:46:7d:01": "oid:0x3a00000000064b"} asic_route_table = [] - asic_neigh_table = \ - ["{\"ip\":\"192.168.0.23\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] - asic_nexthop_table = \ - {'oid:0x40000000005c0': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_IP', 'nexthop_id': 'oid:0x40000000005c0'}} + asic_neigh_table = ["{\"ip\":\"192.168.0.23\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] mock_run_command.side_effect = [ "c53fd5eaad68be1e66a2fe80cd20a9cb18c91259", json.dumps( @@ -215,8 +212,7 @@ def test_read_from_db(self, mock_log_functions): "hw_mux_states": hw_mux_states, "asic_fdb": asic_fdb, "asic_route_table": asic_route_table, - "asic_neigh_table": asic_neigh_table, - "asic_nexthop_table": asic_nexthop_table + "asic_neigh_table": asic_neigh_table } ) ] @@ -238,7 +234,6 @@ def test_read_from_db(self, mock_log_functions): assert {k: v.lstrip("oid:0x") for k, v in asic_fdb.items()} == result[3] assert asic_route_table == result[4] assert asic_neigh_table == result[5] - assert asic_nexthop_table == result[6] def test_read_from_db_script_not_existed(self, mock_log_functions): with patch("dualtor_neighbor_check.run_command") as mock_run_command: @@ -247,10 +242,7 @@ def test_read_from_db_script_not_existed(self, mock_log_functions): hw_mux_states = {"Ethernet4": "active"} asic_fdb = {"ee:86:d8:46:7d:01": "oid:0x3a00000000064b"} asic_route_table = [] - asic_neigh_table = \ - ["{\"ip\":\"192.168.0.23\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] - asic_nexthop_table = \ - {'oid:0x40000000005c0': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_IP', 'nexthop_id': 'oid:0x40000000005c0'}} + asic_neigh_table = ["{\"ip\":\"192.168.0.23\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] mock_run_command.side_effect = [ "(integer) 0", "c53fd5eaad68be1e66a2fe80cd20a9cb18c91259", @@ -261,8 +253,7 @@ def test_read_from_db_script_not_existed(self, mock_log_functions): "hw_mux_states": hw_mux_states, "asic_fdb": asic_fdb, "asic_route_table": asic_route_table, - "asic_neigh_table": asic_neigh_table, - "asic_nexthop_table": asic_nexthop_table + "asic_neigh_table": asic_neigh_table } ) ] @@ -285,7 +276,6 @@ def test_read_from_db_script_not_existed(self, mock_log_functions): assert {k: v.lstrip("oid:0x") for k, v in asic_fdb.items()} == result[3] assert asic_route_table == result[4] assert asic_neigh_table == result[5] - assert asic_nexthop_table == result[6] def test_read_from_db_with_lua_cache(self, mock_log_functions): with patch("dualtor_neighbor_check.run_command") as mock_run_command: @@ -294,10 +284,7 @@ def test_read_from_db_with_lua_cache(self, mock_log_functions): hw_mux_states = {"Ethernet4": "active"} asic_fdb = {"ee:86:d8:46:7d:01": "oid:0x3a00000000064b"} asic_route_table = [] - asic_neigh_table = \ - ["{\"ip\":\"192.168.0.23\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] - asic_nexthop_table = \ - {'oid:0x40000000005c0': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_IP', 'nexthop_id': 'oid:0x40000000005c0'}} + asic_neigh_table = ["{\"ip\":\"192.168.0.23\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] mock_run_command.side_effect = [ "(integer) 1", json.dumps( @@ -307,8 +294,7 @@ def test_read_from_db_with_lua_cache(self, mock_log_functions): "hw_mux_states": hw_mux_states, "asic_fdb": asic_fdb, "asic_route_table": asic_route_table, - "asic_neigh_table": asic_neigh_table, - "asic_nexthop_table": asic_nexthop_table + "asic_neigh_table": asic_neigh_table } ) ] @@ -330,7 +316,6 @@ def test_read_from_db_with_lua_cache(self, mock_log_functions): assert {k: v.lstrip("oid:0x") for k, v in asic_fdb.items()} == result[3] assert asic_route_table == result[4] assert asic_neigh_table == result[5] - assert asic_nexthop_table == result[6] def test_get_mux_server_to_port_map(self, mock_log_functions): mux_cables = { @@ -349,118 +334,6 @@ def test_get_mux_server_to_port_map(self, mock_log_functions): assert mux_server_to_port_map == result - def test_check_neighbor_consistency_soc_ip_neighbor(self, mock_log_functions): - mock_log_error, mock_log_warn, _, _ = mock_log_functions - neighbors = {"192.168.0.1": "aa:bb:cc:dd:ee:ff"} # SOC IP neighbor - mux_states = {"Ethernet4": "active"} - hw_mux_states = {"Ethernet4": "active"} - mac_to_port_name_map = {"aa:bb:cc:dd:ee:ff": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.1/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005c0" - } - ] - asic_neigh_table = \ - ["{\"ip\":\"192.168.0.1\",\"rif\":\"oid:0x6000000000671\"," + - "\"switch_id\":\"oid:0x21000000000000\"}"] - mux_server_to_port_map = {} - expected_output = \ - ["192.168.0.1", "aa:bb:cc:dd:ee:ff", "Ethernet4", "active", "no", "yes", "yes", "NEIGHBOR", "consistent"] - expected_log_output = tabulate.tabulate( - [expected_output], - headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, - tablefmt="simple" - ).split("\n") - expected_log_warn_calls = [call(line) for line in expected_log_output] - - check_results = dualtor_neighbor_check.check_neighbor_consistency( - neighbors, - mux_states, - hw_mux_states, - mac_to_port_name_map, - asic_route_table, - asic_neigh_table, - {'oid:0x40000000005c0': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_IP', 'nexthop_id': 'oid:0x40000000005c0'}}, - mux_server_to_port_map - ) - res = dualtor_neighbor_check.parse_check_results(check_results) - - assert res is True - mock_log_warn.assert_has_calls(expected_log_warn_calls) - mock_log_error.assert_not_called() - - def test_check_neighbor_consistency_multiple_neighbors_with_soc_ips(self, mock_log_functions): - mock_log_error, mock_log_warn, _, _ = mock_log_functions - neighbors = { - "192.168.0.2": "ee:86:d8:46:7d:01", # Server IP - "192.168.0.1": "aa:bb:cc:dd:ee:ff", # SOC IP - "192.168.0.5": "11:22:33:44:55:66" # Regular neighbor - } - mux_states = {"Ethernet4": "active", "Ethernet8": "standby"} - hw_mux_states = {"Ethernet4": "active", "Ethernet8": "standby"} - mac_to_port_name_map = { - "ee:86:d8:46:7d:01": "Ethernet4", - "aa:bb:cc:dd:ee:ff": "Ethernet4", - "11:22:33:44:55:66": "Ethernet8" - } - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005c0" - }, - { - "route_details": "{\"dest\":\"192.168.0.1/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005c0" - }, - { - "route_details": "{\"dest\":\"192.168.0.5/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005ae" - } - ] - asic_neigh_table = [ - "{\"ip\":\"192.168.0.2\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}", - "{\"ip\":\"192.168.0.1\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}", - "{\"ip\":\"192.168.0.5\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}" - ] - mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_outputs = [ - ["192.168.0.1", "aa:bb:cc:dd:ee:ff", "Ethernet4", "active", "no", "yes", "yes", "NEIGHBOR", "consistent"], - ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "active", "no", "yes", "yes", "NEIGHBOR", "consistent"], - ["192.168.0.5", "11:22:33:44:55:66", "Ethernet8", "standby", "no", "yes", "yes", "TUNNEL", "consistent"] - ] - expected_log_output = tabulate.tabulate( - expected_outputs, - headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, - tablefmt="simple" - ).split("\n") - expected_log_warn_calls = [call(line) for line in expected_log_output] - - check_results = dualtor_neighbor_check.check_neighbor_consistency( - neighbors, - mux_states, - hw_mux_states, - mac_to_port_name_map, - asic_route_table, - asic_neigh_table, - { - 'oid:0x40000000005c0': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_IP', - 'nexthop_id': 'oid:0x40000000005c0'}, - 'oid:0x40000000005ae': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP', - 'nexthop_id': 'oid:0x40000000005ae'} - }, - mux_server_to_port_map - ) - res = dualtor_neighbor_check.parse_check_results(check_results) - - assert res is True - mock_log_warn.assert_has_calls(expected_log_warn_calls) - mock_log_error.assert_not_called() - def test_check_neighbor_consistency_no_fdb_entry(self, mock_log_functions): mock_log_error, mock_log_warn, _, _ = mock_log_functions neighbors = {"192.168.0.2": "ee:86:d8:46:7d:01"} @@ -470,7 +343,7 @@ def test_check_neighbor_consistency_no_fdb_entry(self, mock_log_functions): asic_route_table = [] asic_neigh_table = [] mux_server_to_port_map = {} - expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A"] + expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -485,7 +358,6 @@ def test_check_neighbor_consistency_no_fdb_entry(self, mock_log_functions): mac_to_port_name_map, asic_route_table, asic_neigh_table, - {}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -500,18 +372,10 @@ def test_check_neighbor_consistency_consistent_neighbor_mux_active(self, mock_lo mux_states = {"Ethernet4": "active"} hw_mux_states = {"Ethernet4": "active"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005c0" - } - ] - asic_neigh_table = \ - ["{\"ip\":\"192.168.0.2\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] + asic_route_table = [] + asic_neigh_table = ["{\"ip\":\"192.168.0.2\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "active", "no", "yes", "yes", "NEIGHBOR", "consistent"] + expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "active", "no", "yes", "no", "consistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -526,7 +390,6 @@ def test_check_neighbor_consistency_consistent_neighbor_mux_active(self, mock_lo mac_to_port_name_map, asic_route_table, asic_neigh_table, - {'oid:0x40000000005c0': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_IP', 'nexthop_id': 'oid:0x40000000005c0'}}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -541,17 +404,10 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_active_no_asic_nei mux_states = {"Ethernet4": "active"} hw_mux_states = {"Ethernet4": "active"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005ae" - } - ] + asic_route_table = [] asic_neigh_table = [] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "active", "no", "no", "yes", "TUNNEL", "inconsistent"] + expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "active", "no", "no", "no", "inconsistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -568,8 +424,6 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_active_no_asic_nei mac_to_port_name_map, asic_route_table, asic_neigh_table, - {'oid:0x40000000005ae': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP', - 'nexthop_id': 'oid:0x40000000005ae'}}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -584,17 +438,10 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_active_asic_tunnel mux_states = {"Ethernet4": "active"} hw_mux_states = {"Ethernet4": "active"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005ae" - } - ] + asic_route_table = ["{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\",\"vr\":\"oid:0x3000000000024\"}"] asic_neigh_table = [] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "active", "no", "no", "yes", "TUNNEL", "inconsistent"] + expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "active", "no", "no", "yes", "inconsistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -611,8 +458,6 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_active_asic_tunnel mac_to_port_name_map, asic_route_table, asic_neigh_table, - {'oid:0x40000000005ae': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP', - 'nexthop_id': 'oid:0x40000000005ae'}}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -627,17 +472,10 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_active_in_toggle(s mux_states = {"Ethernet4": "active"} hw_mux_states = {"Ethernet4": "standby"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005ae" - } - ] + asic_route_table = [] asic_neigh_table = [] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "active", "yes", "no", "yes", "TUNNEL", "inconsistent"] + expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "active", "yes", "no", "no", "inconsistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -652,8 +490,6 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_active_in_toggle(s mac_to_port_name_map, asic_route_table, asic_neigh_table, - {'oid:0x40000000005ae': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP', - 'nexthop_id': 'oid:0x40000000005ae'}}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -668,17 +504,10 @@ def test_check_neighbor_consistency_consistent_neighbor_mux_standby(self, mock_l mux_states = {"Ethernet4": "standby"} hw_mux_states = {"Ethernet4": "standby"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005ae" - } - ] + asic_route_table = ["{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\",\"vr\":\"oid:0x3000000000024\"}"] asic_neigh_table = [] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "standby", "no", "no", "yes", "TUNNEL", "consistent"] + expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "standby", "no", "no", "yes", "consistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -693,8 +522,6 @@ def test_check_neighbor_consistency_consistent_neighbor_mux_standby(self, mock_l mac_to_port_name_map, asic_route_table, asic_neigh_table, - {'oid:0x40000000005ae': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP', - 'nexthop_id': 'oid:0x40000000005ae'}}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -703,23 +530,16 @@ def test_check_neighbor_consistency_consistent_neighbor_mux_standby(self, mock_l mock_log_warn.assert_has_calls(expected_log_warn_calls) mock_log_error.assert_not_called() - def test_check_nbr_consistency_inconsistent_nbr_mux_standby_no_asic_tunnel_route(self, mock_log_functions): + def test_check_neighbor_consistency_inconsistent_neighbor_mux_standby_no_asic_tunnel_route(self, mock_log_functions): mock_log_error, mock_log_warn, _, _ = mock_log_functions neighbors = {"192.168.0.2": "ee:86:d8:46:7d:01"} mux_states = {"Ethernet4": "standby"} hw_mux_states = {"Ethernet4": "standby"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005c0" - } - ] + asic_route_table = [] asic_neigh_table = [] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "standby", "no", "no", "yes", "NEIGHBOR", "inconsistent"] + expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "standby", "no", "no", "no", "inconsistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -736,7 +556,6 @@ def test_check_nbr_consistency_inconsistent_nbr_mux_standby_no_asic_tunnel_route mac_to_port_name_map, asic_route_table, asic_neigh_table, - {'oid:0x40000000005c0': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_IP', 'nexthop_id': 'oid:0x40000000005c0'}}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -751,18 +570,10 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_standby_asic_neigh mux_states = {"Ethernet4": "standby"} hw_mux_states = {"Ethernet4": "standby"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005ae" - } - ] - asic_neigh_table = \ - ["{\"ip\":\"192.168.0.2\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] + asic_route_table = [] + asic_neigh_table = ["{\"ip\":\"192.168.0.2\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "standby", "no", "yes", "yes", "NEIGHBOR", "inconsistent"] + expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "standby", "no", "yes", "no", "inconsistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -779,8 +590,6 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_standby_asic_neigh mac_to_port_name_map, asic_route_table, asic_neigh_table, - {'oid:0x40000000005ae': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_IP', - 'nexthop_id': 'oid:0x40000000005ae'}}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -795,17 +604,10 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_standby_in_toggle( mux_states = {"Ethernet4": "standby"} hw_mux_states = {"Ethernet4": "active"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.2/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005ae" - } - ] + asic_route_table = [] asic_neigh_table = [] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "standby", "yes", "no", "yes", "NEIGHBOR", "inconsistent"] + expected_output = ["192.168.0.2", "ee:86:d8:46:7d:01", "Ethernet4", "standby", "yes", "no", "no", "inconsistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -820,8 +622,6 @@ def test_check_neighbor_consistency_inconsistent_neighbor_mux_standby_in_toggle( mac_to_port_name_map, asic_route_table, asic_neigh_table, - {'oid:0x40000000005ae': {'nexthop_type': 'SAI_NEXT_HOP_TYPE_IP', - 'nexthop_id': 'oid:0x40000000005ae'}}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -836,17 +636,10 @@ def test_check_neighbor_consistency_zero_mac_neighbor(self, mock_log_functions): mux_states = {"Ethernet4": "active"} hw_mux_states = {"Ethernet4": "active"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} - asic_route_table = [ - { - "route_details": "{\"dest\":\"192.168.0.102/32\",\"switch_id\":\"oid:0x21000000000000\"," + - "\"vr\":\"oid:0x3000000000024\"}", - "nexthop_id": "oid:0x40000000005ae" - } - ] + asic_route_table = ["{\"dest\":\"192.168.0.102/32\",\"switch_id\":\"oid:0x21000000000000\",\"vr\":\"oid:0x3000000000024\"}"] asic_neigh_table = [] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.102", "00:00:00:00:00:00", "N/A", "N/A", "N/A", "no", "yes", "N/A", "consistent"] + expected_output = ["192.168.0.102", "00:00:00:00:00:00", "N/A", "N/A", "N/A", "no", "yes", "consistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -861,7 +654,6 @@ def test_check_neighbor_consistency_zero_mac_neighbor(self, mock_log_functions): mac_to_port_name_map, asic_route_table, asic_neigh_table, - {}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -877,11 +669,9 @@ def test_check_neighbor_consistency_zero_mac_expired_neighbor(self, mock_log_fun hw_mux_states = {"Ethernet4": "active"} mac_to_port_name_map = {"ee:86:d8:46:7d:01": "Ethernet4"} asic_route_table = [] - asic_neigh_table = \ - ["{\"ip\":\"192.168.0.102\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] + asic_neigh_table = ["{\"ip\":\"192.168.0.102\",\"rif\":\"oid:0x6000000000671\",\"switch_id\":\"oid:0x21000000000000\"}"] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = \ - ["192.168.0.102", "00:00:00:00:00:00", "N/A", "N/A", "N/A", "yes", "no", "N/A", "consistent"] + expected_output = ["192.168.0.102", "00:00:00:00:00:00", "N/A", "N/A", "N/A", "yes", "no", "consistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, @@ -896,7 +686,6 @@ def test_check_neighbor_consistency_zero_mac_expired_neighbor(self, mock_log_fun mac_to_port_name_map, asic_route_table, asic_neigh_table, - {}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results) @@ -914,15 +703,14 @@ def test_check_neighbor_consistency_inconsistent_zero_mac_neighbor(self, mock_lo asic_route_table = [] asic_neigh_table = [] mux_server_to_port_map = {"192.168.0.2": "Ethernet4"} - expected_output = ["192.168.0.102", "00:00:00:00:00:00", "N/A", "N/A", "N/A", "no", "no", "N/A", "inconsistent"] + expected_output = ["192.168.0.102", "00:00:00:00:00:00", "N/A", "N/A", "N/A", "no", "no", "inconsistent"] expected_log_output = tabulate.tabulate( [expected_output], headers=dualtor_neighbor_check.NEIGHBOR_ATTRIBUTES, tablefmt="simple" ).split("\n") expected_log_warn_calls = [call(line) for line in expected_log_output] - expected_log_error_calls = \ - [call("Found neighbors that are inconsistent with mux states: %s", ["192.168.0.102"])] + expected_log_error_calls = [call("Found neighbors that are inconsistent with mux states: %s", ["192.168.0.102"])] expected_log_error_calls.extend([call(line) for line in expected_log_output]) check_results = dualtor_neighbor_check.check_neighbor_consistency( @@ -932,7 +720,6 @@ def test_check_neighbor_consistency_inconsistent_zero_mac_neighbor(self, mock_lo mac_to_port_name_map, asic_route_table, asic_neigh_table, - {}, mux_server_to_port_map ) res = dualtor_neighbor_check.parse_check_results(check_results)