Skip to content

Commit ad302d4

Browse files
authored
Fix: 'key not found' exception in bgp4.py (#192)
**- What I did** A 'key not found' exception will be raised in bgp4.py if the state for a given neighbor is not found in STATE_DB. ``` ERR snmp#snmp-subagent [ax_interface] ERROR: MIBUpdater.start() caught an unexpected exception during update_data() #012Traceback (most recent call last): #12 File "/usr/local/lib/python3.7/dist-packages/ax_interface/mib.py", line 43, in start #12 self.update_data()#12 File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/vendor/cisco/bgp4.py", line 42, in update_data #12 state = neigh_info['state'] #12 File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 345, in __getitem__ #12 return _swsscommon.FieldValueMap___getitem__(self, key) #012IndexError: key not found ``` It is becaues an empty ```dict``` is returned by ```get_all``` when nothing is found for the given key. So check for ```None``` can't detect the error. **- How I did it** This commit addressed the issue by checking the key ```state```. **- How to verify it** Verified on A7260. No exception is observed after the update. **- Description for the changelog** This PR fix exception caused by non existing key.
1 parent 59e2a1c commit ad302d4

File tree

1 file changed

+2
-4
lines changed
  • src/sonic_ax_impl/mibs/vendor/cisco

1 file changed

+2
-4
lines changed

src/sonic_ax_impl/mibs/vendor/cisco/bgp4.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import socket
21
from bisect import bisect_right
32
from sonic_ax_impl import mibs
43
from ax_interface import MIBMeta, ValueType, MIBUpdater, SubtreeMIBEntry
5-
from ax_interface.mib import MIBEntry
64
from sonic_ax_impl.mibs import Namespace
75
import ipaddress
86

@@ -22,7 +20,7 @@ def __init__(self):
2220
super().__init__()
2321
self.db_conn = Namespace.init_namespace_dbs()
2422

25-
self.neigh_state_map = {}
23+
self.neigh_state_map = {}
2624
self.session_status_map = {}
2725
self.session_status_list = []
2826

@@ -38,7 +36,7 @@ def update_data(self):
3836
neigh_str = neigh_key
3937
neigh_str = neigh_str.split('|')[1]
4038
neigh_info = self.db_conn[db_index].get_all(mibs.STATE_DB, neigh_key, blocking=False)
41-
if neigh_info is not None:
39+
if neigh_info:
4240
state = neigh_info['state']
4341
ip = ipaddress.ip_address(neigh_str)
4442
if type(ip) is ipaddress.IPv4Address:

0 commit comments

Comments
 (0)