Skip to content

[port_util] Fix issue: port_util.get_vlan_interface_oid_map should not raise exception when DB has not RIF data#117

Merged
qiluo-msft merged 5 commits intosonic-net:masterfrom
Junchao-Mellanox:fix-get-vlan-oid
Mar 21, 2022
Merged

[port_util] Fix issue: port_util.get_vlan_interface_oid_map should not raise exception when DB has not RIF data#117
qiluo-msft merged 5 commits intosonic-net:masterfrom
Junchao-Mellanox:fix-get-vlan-oid

Conversation

@Junchao-Mellanox
Copy link
Contributor

Why I did this?

port_util.get_vlan_interface_oid_map would raise exception when there is no RIF configured, and it would causes snmpagent not work. This PR is to fix it.

#012Traceback (most recent call last):
#012File "/usr/local/lib/python3.7/dist-packages/ax_interface/mib.py", line 37, in start
#012    self.reinit_data()#012  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/ietf/rfc1213.py", line 233, in reinit_data
#012    self.vlan_oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_vlan_tables, self.db_conn)
#012  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 651, in get_sync_d_from_all_namespace
#012    ns_tuple = per_namespace_func(db_conn)
#012  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 341, in init_sync_d_vlan_tables
#012    vlan_name_map = port_util.get_vlan_interface_oid_map(db_conn)
#012  File "/usr/local/lib/python3.7/dist-packages/swsssdk/port_util.py", line 167, in get_vlan_interface_oid_map
#012    rif_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_NAME_MAP', blocking=True)
#012  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1751, in get_all
#012    return dict(super(SonicV2Connector, self).get_all(db_name, _hash, blocking))
#012  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1708, in get_all
#012    return _swsscommon.SonicV2Connector_Native_get_all(self, db_name, _hash, blocking)
#012RuntimeError: Key '{COUNTERS_RIF_NAME_MAP}' unavailable in database '{COUNTERS_DB}'

How I did this:
check redis key exists first before calling get_all.

keboliu
keboliu previously approved these changes Feb 24, 2022
keboliu
keboliu previously approved these changes Feb 24, 2022
liat-grozovik
liat-grozovik previously approved these changes Feb 24, 2022
@liat-grozovik
Copy link

liat-grozovik commented Feb 24, 2022

@qiluo-msft could you please help to signoff?
Due to permission issue we cannot add label. Can you please help to add required for 202111 label?

@Junchao-Mellanox
Copy link
Contributor Author

Hi @qiluo-msft , could you please review and sign-off?

@dprital
Copy link

dprital commented Mar 2, 2022

Hi @qiluo-msft - Can you please direct this PR to the relevant maintainer ?

@liat-grozovik
Copy link

@qiluo-msft due to limited permission please add a label of bug as well as requested for 202111

@qiluo-msft
Copy link
Contributor

qiluo-msft commented Mar 15, 2022

def get_vlan_interface_oid_map(db):

you can add a new parameter blocking with default value True.

Change the internal blocking accordingly. No need to check exists.

The benefit is to keep old behavior, and allow client code to change behavior case by case.


In reply to: 1067627217


Refers to: src/swsssdk/port_util.py:162 in 9beb381. [](commit_id = 9beb381, deletion_comment = False)

@Junchao-Mellanox
Copy link
Contributor Author

def get_vlan_interface_oid_map(db):

you can add a new parameter blocking with default value True.

Change the internal blocking accordingly. No need to check exists.

The benefit is to keep old behavior, and allow client code to change behavior case by case.

Refers to: src/swsssdk/port_util.py:162 in 9beb381. [](commit_id = 9beb381, deletion_comment = False)

Hi @qiluo-msft , I would like to confirm your comment here:

  1. add a parameter to get_vlan_interface_oid_map
def get_vlan_interface_oid_map(db, blocking=True):
    ...
  1. and change snmpagent code to call it like:
get_vlan_interface_oid_map(db, blocking=False)

Correct?

@SuvarnaMeenakshi
Copy link
Contributor

def get_vlan_interface_oid_map(db):

you can add a new parameter blocking with default value True.
Change the internal blocking accordingly. No need to check exists.
The benefit is to keep old behavior, and allow client code to change behavior case by case.
Refers to: src/swsssdk/port_util.py:162 in 9beb381. [](commit_id = 9beb381, deletion_comment = False)

Hi @qiluo-msft , I would like to confirm your comment here:

  1. add a parameter to get_vlan_interface_oid_map
def get_vlan_interface_oid_map(db, blocking=True):
    ...
  1. and change snmpagent code to call it like:
get_vlan_interface_oid_map(db, blocking=False)

Correct?

--- a/src/swsssdk/port_util.py
+++ b/src/swsssdk/port_util.py
@@ -164,13 +164,13 @@ def get_rif_port_map(db):
 
     return rif_port_oid_map
 
-def get_vlan_interface_oid_map(db):
+def get_vlan_interface_oid_map(db, blocking=True):
     """
         Get Vlan Interface names and sai oids
     """
     db.connect('COUNTERS_DB')
-    rif_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_NAME_MAP', blocking=True)
-    rif_type_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_TYPE_MAP', blocking=True)
+    rif_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_NAME_MAP', blocking=blocking)
+    rif_type_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_TYPE_MAP', blocking=blocking)

@SuvarnaMeenakshi
Copy link
Contributor

@mlok-nokia - fyi

@SuvarnaMeenakshi
Copy link
Contributor

@Junchao-Mellanox created snmp PR sonic-net/sonic-snmpagent#246, depends on this PR.

@qiluo-msft
Copy link
Contributor

Yes.


In reply to: 1068646058

@Junchao-Mellanox Junchao-Mellanox dismissed stale reviews from liat-grozovik and keboliu via 049d4cc March 18, 2022 01:20
@Junchao-Mellanox
Copy link
Contributor Author

I removed previous added unit test case as this change is hard to be covered by unit test.

@Junchao-Mellanox
Copy link
Contributor Author

@qiluo-msft could you please review and sign off?

qiluo-msft
qiluo-msft previously approved these changes Mar 18, 2022
@Junchao-Mellanox
Copy link
Contributor Author

/azpw run Azure.sonic-py-swsssdk

@mssonicbld
Copy link

/AzurePipelines run Azure.sonic-py-swsssdk

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 117 in repo Azure/sonic-py-swsssdk

@Junchao-Mellanox
Copy link
Contributor Author

Hi @qiluo-msft , I run the build locally and cannot reproduce the build failure. Could you please help take a look?

@SuvarnaMeenakshi
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft
Copy link
Contributor

@Junchao-Mellanox We recently add coverage >= 50% enforcement to most of the repos. Could you add a unit test to coverage the missing lines? https://dev.azure.com/mssonic/build/_build/results?buildId=82325&view=codecoverage-tab

@Junchao-Mellanox
Copy link
Contributor Author

Hi @qiluo-msft , could you please review and sign off?

@qiluo-msft qiluo-msft merged commit 96c0590 into sonic-net:master Mar 21, 2022
@dprital
Copy link

dprital commented Mar 21, 2022

@qiluo-msft - There is no 202111 branch for this repository. Is there a plan to open one ?

@SuvarnaMeenakshi
Copy link
Contributor

@vperumal @anamehra @VenkatCisco fyi

@Junchao-Mellanox Junchao-Mellanox deleted the fix-get-vlan-oid branch March 23, 2022 08:52
judyjoseph pushed a commit that referenced this pull request Mar 28, 2022
…t raise exception when DB has not RIF data (#117)

**Why I did this?**

port_util.get_vlan_interface_oid_map would raise exception when there is no RIF configured, and it would causes snmpagent not work. This PR is to fix it.

```
#012Traceback (most recent call last):
#012File "/usr/local/lib/python3.7/dist-packages/ax_interface/mib.py", line 37, in start
#12    self.reinit_data()#12  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/ietf/rfc1213.py", line 233, in reinit_data
#12    self.vlan_oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_vlan_tables, self.db_conn)
#12  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 651, in get_sync_d_from_all_namespace
#12    ns_tuple = per_namespace_func(db_conn)
#12  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 341, in init_sync_d_vlan_tables
#12    vlan_name_map = port_util.get_vlan_interface_oid_map(db_conn)
#12  File "/usr/local/lib/python3.7/dist-packages/swsssdk/port_util.py", line 167, in get_vlan_interface_oid_map
#12    rif_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_NAME_MAP', blocking=True)
#12  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1751, in get_all
#12    return dict(super(SonicV2Connector, self).get_all(db_name, _hash, blocking))
#12  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1708, in get_all
#12    return _swsscommon.SonicV2Connector_Native_get_all(self, db_name, _hash, blocking)
#012RuntimeError: Key '{COUNTERS_RIF_NAME_MAP}' unavailable in database '{COUNTERS_DB}'
```

**How I did this:**
check redis key exists first before calling get_all.
SuvarnaMeenakshi added a commit to sonic-net/sonic-snmpagent that referenced this pull request Mar 28, 2022
…246)

fixes sonic-net/sonic-buildimage#9996
Handle error seen on system where vlan interface map is not present.
This change requires: sonic-net/sonic-py-swsssdk#117
On chassis platform, on supervisor there are not ports available in config_db. So, there is no vlan interface map in counters db, which causes this error in syslog:

ERROR: MIBUpdater.start() caught an unexpected exception during update_data(). RuntimeError: Key '{COUNTERS_RIF_NAME_MAP}' unavailable in database '{COUNTERS_DB}'
- How I did it
Return empty dict if vlan interface map is not present in DB.
SuvarnaMeenakshi added a commit to SuvarnaMeenakshi/sonic-snmpagent that referenced this pull request Apr 11, 2022
…resent

fixes sonic-net/sonic-buildimage#9996
Handle error seen on system where vlan interface map is not present.
This change requires: sonic-net/sonic-py-swsssdk#117
On chassis platform, on supervisor there are not ports available in config_db. So, there is no vlan interface map in counters db, which causes this error in syslog:

ERROR: MIBUpdater.start() caught an unexpected exception during update_data(). RuntimeError: Key '{COUNTERS_RIF_NAME_MAP}' unavailable in database '{COUNTERS_DB}'
- How I did it
Return empty dict if vlan interface map is not present in DB.

(cherry picked from commit 2151731)
Signed-off-by: Suvarna Meenakshi <[email protected]>
SuvarnaMeenakshi added a commit to sonic-net/sonic-snmpagent that referenced this pull request Apr 13, 2022
…present (#252)

- What I did
cherrypick of: #246
fixes sonic-net/sonic-buildimage#9996
Handle error seen on system where vlan interface map is not present.
This change requires: sonic-net/sonic-py-swsssdk#117
On chassis platform, on supervisor there are not ports available in config_db. So, there is no vlan interface map in counters db, which causes this error in syslog:

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 37, in start#012    self.reinit_data()#12  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/ietf/rfc1213.py", line 233, in reinit_data#012    self.vlan_oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_vlan_tables, self.db_conn)#12  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 649, in get_sync_d_from_all_namespace#012    ns_tuple = per_namespace_func(db_conn)#12  File "/usr/local/lib/python3.7/dist-packages/sonic_ax_impl/mibs/__init__.py", line 339, in init_sync_d_vlan_tables#012    vlan_name_map = port_util.get_vlan_interface_oid_map(db_conn)#12  File "/usr/local/lib/python3.7/dist-packages/swsssdk/port_util.py", line 167, in get_vlan_interface_oid_map#012    rif_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_RIF_NAME_MAP', blocking=True)#12  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1751, in get_all#012    return dict(super(SonicV2Connector, self).get_all(db_name, _hash, blocking))#12  File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 1708, in get_all#012    return _swsscommon.SonicV2Connector_Native_get_all(self, db_name, _hash, blocking)#012RuntimeError: Key '{COUNTERS_RIF_NAME_MAP}' unavailable in database '{COUNTERS_DB}'
- How I did it
Return empty dict if vlan interface map is not present in DB.
- How to verify it
With this fix, no error in syslog message.
Able to execute other MIB queries on supervisor.
UT passes.
ssithaia-ebay pushed a commit to ssithaia-ebay/sonic-snmpagent that referenced this pull request May 23, 2025
…onic-net#246)

fixes sonic-net/sonic-buildimage#9996
Handle error seen on system where vlan interface map is not present.
This change requires: sonic-net/sonic-py-swsssdk#117
On chassis platform, on supervisor there are not ports available in config_db. So, there is no vlan interface map in counters db, which causes this error in syslog:

ERROR: MIBUpdater.start() caught an unexpected exception during update_data(). RuntimeError: Key '{COUNTERS_RIF_NAME_MAP}' unavailable in database '{COUNTERS_DB}'
- How I did it
Return empty dict if vlan interface map is not present in DB.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants