Fix 'key not found' exception in bgp4.py#192
Merged
qiluo-msft merged 2 commits intosonic-net:masterfrom Jan 28, 2021
Merged
Conversation
A 'key not found' exception will be raised in bgp4.py if the state for a given neighbor is not found in STATE_DB. This commit addressed the issue. Signed-off-by: bingwang <bingwang@microsoft.com>
qiluo-msft
reviewed
Jan 26, 2021
| neigh_str = neigh_str.split('|')[1] | ||
| neigh_info = self.db_conn[db_index].get_all(mibs.STATE_DB, neigh_key, blocking=False) | ||
| if neigh_info is not None: | ||
| if neigh_info is not None and 'state' in neigh_info: |
Contributor
There was a problem hiding this comment.
state [](start = 43, length = 5)
@SuvarnaMeenakshi if 'state' is missing, is it a bug in upstream process?
If it is valid use case, what does it mean?
Contributor
There was a problem hiding this comment.
We would like to see if this will fix your test.
Suggested change
| if neigh_info is not None and 'state' in neigh_info: | |
| if neigh_info: | |
| if 'state' not in neigh_info: | |
| mibs.logger.error("Invalid ... in StateDB") | |
| continue |
Contributor
Author
There was a problem hiding this comment.
Thanks. I'll update and verify.
Contributor
Author
There was a problem hiding this comment.
Updated. Thanks
Signed-off-by: bingwang <bingwang@microsoft.com>
qiluo-msft
approved these changes
Jan 28, 2021
ssithaia-ebay
pushed a commit
to ssithaia-ebay/sonic-snmpagent
that referenced
this pull request
May 23, 2025
**- 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): sonic-net#12 File "/usr/local/lib/python3.7/dist-packages/ax_interface/mib.py", line 43, in start sonic-net#12 self.update_data()sonic-net#12 File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/vendor/cisco/bgp4.py", line 42, in update_data sonic-net#12 state = neigh_info['state'] sonic-net#12 File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 345, in __getitem__ sonic-net#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Signed-off-by: bingwang bingwang@microsoft.com
- 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.
It is becaues an empty
dictis returned byget_allwhen nothing is found for the given key. So check forNonecan'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.