Skip to content

Commit

Permalink
[vnet_route_check] Align DB data parse logic with format used by swss…
Browse files Browse the repository at this point in the history
…common API (#2268)

* 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 <volodymyrs@nvidia.com>
  • Loading branch information
volodymyrsamotiy authored Jul 18, 2022
1 parent ea11b22 commit e49b1e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions scripts/vnet_route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -110,14 +110,9 @@ def get_all_rifs_oids():
Format: { <rif_name>: <rif_oid> }
'''
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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/vnet_route_check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit e49b1e8

Please sign in to comment.