From 78e4fe771b5ac6ec99282e6797233a17e16bd1d7 Mon Sep 17 00:00:00 2001 From: siqbal1486 Date: Wed, 10 Aug 2022 12:17:56 -0700 Subject: [PATCH] Fixes suggested in review. Signed-off-by: siqbal1486 --- scripts/vnet_route_check.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/vnet_route_check.py b/scripts/vnet_route_check.py index 2abe9c1b7b2..dc02c99930c 100755 --- a/scripts/vnet_route_check.py +++ b/scripts/vnet_route_check.py @@ -47,7 +47,7 @@ RC_OK = 0 RC_ERR = -1 - +default_vrf_oid = "" report_level = syslog.LOG_ERR write_to_syslog = True @@ -194,7 +194,7 @@ def filter_out_vnet_ip2me_routes(vnet_routes): vnet_routes.pop(vnet) -def get_vnet_routes_from_app_db(default_vrf_oid): +def get_vnet_routes_from_app_db(): ''' Returns dictionary of VNET routes configured per each VNET in APP_DB. Format: { : { 'routes': [ ], 'vrf_oid': } } ''' @@ -222,8 +222,13 @@ def get_vnet_routes_from_app_db(default_vrf_oid): if vnet_name not in vnet_intfs: # this route has no vnet_intf and may be part of default VRF. vnet_table = swsscommon.Table(db, 'VNET_TABLE') - scope = vnet_table.get(vnet_name)[1][1][1] - if scope == 'default': + scope_value = "" + # "Vnet_v4_in_v4-0": [("vxlan_tunnel", "tunnel_v4"), ("scope", "default"), ("vni", "10000"), ("peer_list", "")] + for key,value in vnet_table.get(vnet_name)[1]: + if key == "scope": + scope_value = value + break + if scope_value == 'default': vnet_routes[vnet_name]['vrf_oid'] = default_vrf_oid else: assert "Non-default VRF route present without vnet interface." @@ -236,7 +241,7 @@ def get_vnet_routes_from_app_db(default_vrf_oid): return vnet_routes -def get_vnet_routes_from_asic_db(default_vrf_oid): +def get_vnet_routes_from_asic_db(): ''' Returns dictionary of VNET routes configured per each VNET in ASIC_DB. Format: { : { 'routes': [ ], 'vrf_oid': } } ''' @@ -287,7 +292,7 @@ def get_vnet_routes_from_asic_db(default_vrf_oid): return vnet_routes -def get_vnet_routes_diff(default_vrf_oid, routes_1, routes_2, verify_default_vrf_routes = False): +def get_vnet_routes_diff(routes_1, routes_2, verify_default_vrf_routes = False): ''' Returns all routes present in routes_2 dictionary but missed in routes_1 Format: { : { 'routes': [ ] } } ''' @@ -352,15 +357,15 @@ def main(): return rc asic_db = swsscommon.DBConnector('ASIC_DB', 0) virtual_router = swsscommon.Table(asic_db, 'ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER') - default_vrf_oid = "" if virtual_router.getKeys() != []: + global default_vrf_oid default_vrf_oid = virtual_router.getKeys()[0] - app_db_vnet_routes = get_vnet_routes_from_app_db(default_vrf_oid) - asic_db_vnet_routes = get_vnet_routes_from_asic_db(default_vrf_oid) + app_db_vnet_routes = get_vnet_routes_from_app_db() + asic_db_vnet_routes = get_vnet_routes_from_asic_db() - missed_in_asic_db_routes = get_vnet_routes_diff(default_vrf_oid, asic_db_vnet_routes, app_db_vnet_routes,True) - missed_in_app_db_routes = get_vnet_routes_diff(default_vrf_oid, app_db_vnet_routes, asic_db_vnet_routes) + missed_in_asic_db_routes = get_vnet_routes_diff(asic_db_vnet_routes, app_db_vnet_routes,True) + missed_in_app_db_routes = get_vnet_routes_diff(app_db_vnet_routes, asic_db_vnet_routes) missed_in_sdk_routes = get_sdk_vnet_routes_diff(asic_db_vnet_routes) res = {}