Skip to content

Commit 6dea53d

Browse files
volodymyrsamotiyqiluo-msft
authored andcommitted
[vnet_route_check] Align DB data parse logic with format used by swsscommon 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 <[email protected]>
1 parent e462c09 commit 6dea53d

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

scripts/vnet_route_check.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def get_vnet_intfs():
9393
vnet_intfs = {}
9494

9595
for intf_key in intfs_keys:
96-
intf_attrs = intfs_table.get(intf_key)[1]
96+
intf_attrs = dict(intfs_table.get(intf_key)[1])
9797

9898
if 'vnet_name' in intf_attrs:
9999
vnet_name = intf_attrs['vnet_name']
@@ -110,14 +110,9 @@ def get_all_rifs_oids():
110110
Format: { <rif_name>: <rif_oid> }
111111
'''
112112
db = swsscommon.DBConnector('COUNTERS_DB', 0)
113-
114113
rif_table = swsscommon.Table(db, 'COUNTERS_RIF_NAME_MAP')
115-
rif_keys = rif_table.getKeys()
116-
117-
rif_name_oid_map = {}
118114

119-
for rif_name in rif_keys:
120-
rif_name_oid_map[rif_name] = rif_table.get(rif_name)[1]
115+
rif_name_oid_map = dict(rif_table.get('')[1])
121116

122117
return rif_name_oid_map
123118

@@ -156,8 +151,8 @@ def get_vrf_entries():
156151
db_keys = rif_table.getKeys()
157152

158153
for db_key in db_keys:
159-
if 'SAI_OBJECT_TYPE_ROUTER_INTERFACE' in db_key:
160-
rif_attrs = rif_table.get(db_key)[1]
154+
if (db_key == f'SAI_OBJECT_TYPE_ROUTER_INTERFACE:{vnet_rifs_oids[vnet_rif_name]}'):
155+
rif_attrs = dict(rif_table.get(db_key)[1])
161156
rif_vrf_map[vnet_rif_name] = rif_attrs['SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID']
162157

163158
return rif_vrf_map

tests/vnet_route_check_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def getKeys(self):
254254
return list(self.data.keys())
255255

256256
def get(self, key):
257-
ret = copy.deepcopy(self.data.get(key, {}))
257+
ret = copy.deepcopy(self.data.get(key, self.data))
258258
return (True, ret)
259259

260260

0 commit comments

Comments
 (0)