Skip to content

Commit c2d4945

Browse files
authored
[snmp] Allow system with no ports in config db run without errors (#221)
**What I did** Allow system with no ports in config db run without errors. This is needed for modular system which should boot properly without line cards. **How I did it** Remove snmpagent error exit if there are no ports in config DB or in counters DB. **How to verify it** Run snmpwalk on the root oid.
1 parent fccb21b commit c2d4945

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/sonic_ax_impl/mibs/__init__.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def init_sync_d_interface_tables(db_conn):
271271

272272
# { if_name (SONiC) -> sai_id }
273273
# ex: { "Ethernet76" : "1000000000023" }
274-
if_name_map_util, if_id_map_util = port_util.get_interface_oid_map(db_conn)
274+
if_name_map_util, if_id_map_util = port_util.get_interface_oid_map(db_conn, blocking=False)
275275
for if_name, sai_id in if_name_map_util.items():
276276
if_name_str = if_name
277277
if (re.match(port_util.SONIC_ETHERNET_RE_PATTERN, if_name_str) or \
@@ -297,12 +297,8 @@ def init_sync_d_interface_tables(db_conn):
297297

298298
# SyncD consistency checks.
299299
if not oid_name_map:
300-
# In the event no interface exists that follows the SONiC pattern, no OIDs are able to be registered.
301-
# A RuntimeError here will prevent the 'main' module from loading. (This is desirable.)
302-
message = "No interfaces found matching pattern '{}'. SyncD database is incoherent." \
303-
.format(port_util.SONIC_ETHERNET_RE_PATTERN)
304-
logger.error(message)
305-
raise RuntimeError(message)
300+
logger.debug("There are no ports in counters DB")
301+
return {}, {}, {}, {}
306302
elif len(if_id_map) < len(if_name_map) or len(oid_name_map) < len(if_name_map):
307303
# a length mismatch indicates a bad interface name
308304
logger.warning("SyncD database contains incoherent interface names. Interfaces must match pattern '{}'"
@@ -424,7 +420,7 @@ def init_sync_d_queue_tables(db_conn):
424420

425421
# { Port name : Queue index (SONiC) -> sai_id }
426422
# ex: { "Ethernet0:2" : "1000000000023" }
427-
queue_name_map = db_conn.get_all(COUNTERS_DB, COUNTERS_QUEUE_NAME_MAP, blocking=True)
423+
queue_name_map = db_conn.get_all(COUNTERS_DB, COUNTERS_QUEUE_NAME_MAP, blocking=False)
428424
logger.debug("Queue name map:\n" + pprint.pformat(queue_name_map, indent=2))
429425

430426
# Parse the queue_name_map and create the following maps:
@@ -455,10 +451,8 @@ def init_sync_d_queue_tables(db_conn):
455451

456452
# SyncD consistency checks.
457453
if not port_queues_map:
458-
# In the event no queue exists that follows the SONiC pattern, no OIDs are able to be registered.
459-
# A RuntimeError here will prevent the 'main' module from loading. (This is desirable.)
460-
logger.error("No queues found in the Counter DB. SyncD database is incoherent.")
461-
raise RuntimeError('The port_queues_map is not defined')
454+
logger.debug("Counters DB does not contain ports")
455+
return {}, {}, {}
462456
elif not queue_stat_map:
463457
logger.error("No queue stat counters found in the Counter DB. SyncD database is incoherent.")
464458
raise RuntimeError('The queue_stat_map is not defined')

src/sonic_ax_impl/mibs/ieee802_1ab.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def reinit_data(self):
196196
self.if_range.append((if_oid, ))
197197
self.if_range.sort()
198198
if not self.loc_port_data:
199-
logger.warning("0 - b'PORT_TABLE' is empty. No local port information could be retrieved.")
199+
logger.debug("0 - b'PORT_TABLE' is empty. No local port information could be retrieved.")
200200

201201
def _get_if_entry(self, if_name):
202202
if_table = ""

tests/test_mibs.py

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
import tests.mock_tables.dbconnector
66

7+
if sys.version_info.major == 3:
8+
from unittest import mock
9+
else:
10+
import mock
11+
712
modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
813
sys.path.insert(0, os.path.join(modules_path, 'src'))
914

@@ -32,3 +37,16 @@ def test_init_sync_d_lag_tables(self):
3237
self.assertTrue("PortChannel_Temp" in lag_name_if_name_map)
3338
self.assertTrue(lag_name_if_name_map["PortChannel_Temp"] == [])
3439
self.assertTrue(lag_sai_map["PortChannel01"] == "2000000000006")
40+
41+
@mock.patch('swsssdk.dbconnector.SonicV2Connector.get_all', mock.MagicMock(return_value=({})))
42+
def test_init_sync_d_interface_tables(self):
43+
db_conn = Namespace.init_namespace_dbs()
44+
45+
if_name_map, \
46+
if_alias_map, \
47+
if_id_map, \
48+
oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, db_conn)
49+
self.assertTrue(if_name_map == {})
50+
self.assertTrue(if_alias_map == {})
51+
self.assertTrue(if_id_map == {})
52+
self.assertTrue(oid_name_map == {})

0 commit comments

Comments
 (0)