Skip to content

Fix 'key not found' exception in bgp4.py#192

Merged
qiluo-msft merged 2 commits intosonic-net:masterfrom
bingwang-ms:fix_bgp4
Jan 28, 2021
Merged

Fix 'key not found' exception in bgp4.py#192
qiluo-msft merged 2 commits intosonic-net:masterfrom
bingwang-ms:fix_bgp4

Conversation

@bingwang-ms
Copy link
Copy Markdown
Contributor

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.

ERR snmp#snmp-subagent [ax_interface] ERROR: MIBUpdater.start() caught an unexpected exception during update_data()
#012Traceback (most recent call last):
#012  File "/usr/local/lib/python3.7/dist-packages/ax_interface/mib.py", line 43, in start
#012    self.update_data()#012  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/vendor/cisco/bgp4.py", line 42, in update_data
#012    state = neigh_info['state']
#012  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 345, in __getitem__
#012    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.

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>
@sonic-net sonic-net deleted a comment from svc-acs 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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll update and verify.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Thanks

Signed-off-by: bingwang <bingwang@microsoft.com>
@qiluo-msft qiluo-msft merged commit ad302d4 into sonic-net:master 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants