Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[snmp] Allow system with no ports in config db run without errors #221

Merged
merged 6 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def init_sync_d_interface_tables(db_conn):

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

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

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

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

# SyncD consistency checks.
if not port_queues_map:
# In the event no queue exists that follows the SONiC pattern, no OIDs are able to be registered.
# A RuntimeError here will prevent the 'main' module from loading. (This is desirable.)
logger.error("No queues found in the Counter DB. SyncD database is incoherent.")
raise RuntimeError('The port_queues_map is not defined')
logger.debug("Counters DB does not contain ports")
return {}, {}, {}
elif not queue_stat_map:
logger.error("No queue stat counters found in the Counter DB. SyncD database is incoherent.")
raise RuntimeError('The queue_stat_map is not defined')
Expand Down
2 changes: 1 addition & 1 deletion src/sonic_ax_impl/mibs/ieee802_1ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def reinit_data(self):
self.if_range.append((if_oid, ))
self.if_range.sort()
if not self.loc_port_data:
logger.warning("0 - b'PORT_TABLE' is empty. No local port information could be retrieved.")
logger.debug("0 - b'PORT_TABLE' is empty. No local port information could be retrieved.")

def _get_if_entry(self, if_name):
if_table = ""
Expand Down
18 changes: 18 additions & 0 deletions tests/test_mibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

import tests.mock_tables.dbconnector

if sys.version_info.major == 3:
from unittest import mock
else:
import mock

modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(modules_path, 'src'))

Expand Down Expand Up @@ -32,3 +37,16 @@ def test_init_sync_d_lag_tables(self):
self.assertTrue("PortChannel_Temp" in lag_name_if_name_map)
self.assertTrue(lag_name_if_name_map["PortChannel_Temp"] == [])
self.assertTrue(lag_sai_map["PortChannel01"] == "2000000000006")

@mock.patch('swsssdk.dbconnector.SonicV2Connector.get_all', mock.MagicMock(return_value=({})))
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 17, 2021

Choose a reason for hiding this comment

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

swsssdk

swsssdk or swsscommon? #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you run python3 -m pytest -s -v -k test_init_sync_d_interface_tables ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

swsssdk is the right one (method get_all is part of class SonicV2Connector which is implemented in sonic-buildimage/sonic-py-swsssdk/src/swsssdk/dbconnector.py).
Yes, I ran python3 -m pytest -s -v -k test_init_sync_d_interface_tables.

def test_init_sync_d_interface_tables(self):
db_conn = Namespace.init_namespace_dbs()

if_name_map, \
if_alias_map, \
if_id_map, \
oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_interface_tables, db_conn)
self.assertTrue(if_name_map == {})
self.assertTrue(if_alias_map == {})
self.assertTrue(if_id_map == {})
self.assertTrue(oid_name_map == {})