From 0651622a0e9c48d8a51362b1e98507d4aa40adcd Mon Sep 17 00:00:00 2001 From: Volodymyr Samotiy Date: Thu, 14 Jul 2022 15:56:33 +0300 Subject: [PATCH] [vnet_route_check] Align DB data parse logic with format used by swsscommon API * swsscommon API was changed in order to return data from DB as a tuple instead of dictionary. * In some places vnet_route_check still was expecting data from DB in old format - as a dictionary. * But now it is a tuple, so as a result vnet_route_check was failing with "KeyError" exeption. * These changes fixed all the places in vnet_route_check script that used invalid data format. Signed-off-by: Volodymyr Samotiy --- scripts/vnet_route_check.py | 13 ++++--------- tests/vnet_route_check_test.py | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/scripts/vnet_route_check.py b/scripts/vnet_route_check.py index b2c798dfb0..db50503cd9 100755 --- a/scripts/vnet_route_check.py +++ b/scripts/vnet_route_check.py @@ -93,7 +93,7 @@ def get_vnet_intfs(): vnet_intfs = {} for intf_key in intfs_keys: - intf_attrs = intfs_table.get(intf_key)[1] + intf_attrs = dict(intfs_table.get(intf_key)[1]) if 'vnet_name' in intf_attrs: vnet_name = intf_attrs['vnet_name'] @@ -110,14 +110,9 @@ def get_all_rifs_oids(): Format: { : } ''' db = swsscommon.DBConnector('COUNTERS_DB', 0) - rif_table = swsscommon.Table(db, 'COUNTERS_RIF_NAME_MAP') - rif_keys = rif_table.getKeys() - - rif_name_oid_map = {} - for rif_name in rif_keys: - rif_name_oid_map[rif_name] = rif_table.get(rif_name)[1] + rif_name_oid_map = dict(rif_table.get('')[1]) return rif_name_oid_map @@ -156,8 +151,8 @@ def get_vrf_entries(): db_keys = rif_table.getKeys() for db_key in db_keys: - if 'SAI_OBJECT_TYPE_ROUTER_INTERFACE' in db_key: - rif_attrs = rif_table.get(db_key)[1] + if (db_key == f'SAI_OBJECT_TYPE_ROUTER_INTERFACE:{vnet_rifs_oids[vnet_rif_name]}'): + rif_attrs = dict(rif_table.get(db_key)[1]) rif_vrf_map[vnet_rif_name] = rif_attrs['SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID'] return rif_vrf_map diff --git a/tests/vnet_route_check_test.py b/tests/vnet_route_check_test.py index 09f35761a4..c06ea10ea3 100644 --- a/tests/vnet_route_check_test.py +++ b/tests/vnet_route_check_test.py @@ -254,7 +254,7 @@ def getKeys(self): return list(self.data.keys()) def get(self, key): - ret = copy.deepcopy(self.data.get(key, {})) + ret = copy.deepcopy(self.data.get(key, self.data)) return (True, ret)