Skip to content

Commit

Permalink
[port_util] Allow system without ports in config db run without errors (
Browse files Browse the repository at this point in the history
#109)

**What I did**
Allow system with no ports in config db to run without errors/warnings. 
This is needed for modular system which should boot and run properly without line cards.

**How I did it**
Check if table exists before calling get_all for it and return empty list if there are no ports in COUNTERS_PORT_NAME_MAP table in counters db.

**How to verify it**
Run snmpwalk on the root oid.

**Important**
This PR must be merged before PR sonic-net/sonic-snmpagent#221 is merged.
  • Loading branch information
liorghub authored Sep 1, 2021
1 parent d07682e commit 740a44c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/swsssdk/port_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ def get_index_from_str(if_name):
if match:
return int(match.group(1)) + baseidx

def get_interface_oid_map(db):
def get_interface_oid_map(db, blocking=True):
"""
Get the Interface names from Counters DB
"""
db.connect('COUNTERS_DB')
if_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_PORT_NAME_MAP', blocking=True)
if_lag_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_LAG_NAME_MAP', blocking=True)
if_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_PORT_NAME_MAP', blocking)
if_lag_name_map = db.get_all('COUNTERS_DB', 'COUNTERS_LAG_NAME_MAP', blocking)
if_name_map.update(if_lag_name_map)

if not if_name_map:
return {}, {}

oid_pfx = len("oid:0x")
if_name_map = {if_name: sai_oid[oid_pfx:] for if_name, sai_oid in if_name_map.items()}

Expand Down

0 comments on commit 740a44c

Please sign in to comment.