From cd55670cc2110648af8f30af98515264eeabf56a Mon Sep 17 00:00:00 2001 From: liora Date: Sun, 13 Jun 2021 02:46:52 +0000 Subject: [PATCH 1/5] [snmp] Allow system with no ports in config db run without errors Signed-off-by: liora --- src/sonic_ax_impl/mibs/__init__.py | 18 +++++++----------- src/sonic_ax_impl/mibs/ieee802_1ab.py | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index fe7e74ddb..bd8177167 100644 --- a/src/sonic_ax_impl/mibs/__init__.py +++ b/src/sonic_ax_impl/mibs/__init__.py @@ -269,12 +269,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.info("Config DB does not contain ports") + 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 '{}'" @@ -355,7 +351,9 @@ 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 = {} + if db_conn.exists(COUNTERS_DB, COUNTERS_QUEUE_NAME_MAP): + queue_name_map = db_conn.get_all(COUNTERS_DB, COUNTERS_QUEUE_NAME_MAP, blocking=True) logger.debug("Queue name map:\n" + pprint.pformat(queue_name_map, indent=2)) # Parse the queue_name_map and create the following maps: @@ -386,10 +384,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.info("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') diff --git a/src/sonic_ax_impl/mibs/ieee802_1ab.py b/src/sonic_ax_impl/mibs/ieee802_1ab.py index 852635236..9e4148db6 100644 --- a/src/sonic_ax_impl/mibs/ieee802_1ab.py +++ b/src/sonic_ax_impl/mibs/ieee802_1ab.py @@ -184,7 +184,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.info("0 - b'PORT_TABLE' is empty. No local port information could be retrieved.") def _get_if_entry(self, if_name): if_table = "" From aed2020b64fb4d48d5e77871ab447d5f476d313d Mon Sep 17 00:00:00 2001 From: liora Date: Sun, 13 Jun 2021 02:46:52 +0000 Subject: [PATCH 2/5] [snmp] Allow system with no ports in config db run without errors Signed-off-by: liora --- src/sonic_ax_impl/mibs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index bd8177167..4b60bcc50 100644 --- a/src/sonic_ax_impl/mibs/__init__.py +++ b/src/sonic_ax_impl/mibs/__init__.py @@ -269,7 +269,7 @@ def init_sync_d_interface_tables(db_conn): # SyncD consistency checks. if not oid_name_map: - logger.info("Config DB does not contain ports") + 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 From f21641eaed87c9ecc82c4bb9a9eebeefd423f426 Mon Sep 17 00:00:00 2001 From: liora Date: Sun, 13 Jun 2021 02:46:52 +0000 Subject: [PATCH 3/5] [snmp] Allow system with no ports in config db run without errors Signed-off-by: liora --- src/sonic_ax_impl/mibs/__init__.py | 2 +- src/sonic_ax_impl/mibs/ieee802_1ab.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index 4b60bcc50..afbbc7fb0 100644 --- a/src/sonic_ax_impl/mibs/__init__.py +++ b/src/sonic_ax_impl/mibs/__init__.py @@ -384,7 +384,7 @@ def init_sync_d_queue_tables(db_conn): # SyncD consistency checks. if not port_queues_map: - logger.info("Counters DB does not contain ports") + 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.") diff --git a/src/sonic_ax_impl/mibs/ieee802_1ab.py b/src/sonic_ax_impl/mibs/ieee802_1ab.py index 9e4148db6..6685d8ab2 100644 --- a/src/sonic_ax_impl/mibs/ieee802_1ab.py +++ b/src/sonic_ax_impl/mibs/ieee802_1ab.py @@ -184,7 +184,7 @@ def reinit_data(self): self.if_range.append((if_oid, )) self.if_range.sort() if not self.loc_port_data: - logger.info("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 = "" From 49188eca44b0644a1d581e3b9afd13c75051c480 Mon Sep 17 00:00:00 2001 From: liora Date: Sun, 13 Jun 2021 02:46:52 +0000 Subject: [PATCH 4/5] [snmp] Allow system with no ports in config db run without errors Signed-off-by: liora --- src/sonic_ax_impl/mibs/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index afbbc7fb0..e6faf11dd 100644 --- a/src/sonic_ax_impl/mibs/__init__.py +++ b/src/sonic_ax_impl/mibs/__init__.py @@ -243,7 +243,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 \ @@ -351,9 +351,7 @@ def init_sync_d_queue_tables(db_conn): # { Port name : Queue index (SONiC) -> sai_id } # ex: { "Ethernet0:2" : "1000000000023" } - queue_name_map = {} - if db_conn.exists(COUNTERS_DB, COUNTERS_QUEUE_NAME_MAP): - 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: From 501b7128464046f368b24ef4f9bc754718d59fe4 Mon Sep 17 00:00:00 2001 From: liora Date: Tue, 10 Aug 2021 14:47:53 +0000 Subject: [PATCH 5/5] [snmp] Add unitest for system without ports in config db Signed-off-by: liora --- tests/test_mibs.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_mibs.py b/tests/test_mibs.py index 87a5f3e86..e6992e0a2 100644 --- a/tests/test_mibs.py +++ b/tests/test_mibs.py @@ -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')) @@ -30,3 +35,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"] == []) + + @mock.patch('swsssdk.dbconnector.SonicV2Connector.get_all', mock.MagicMock(return_value=({}))) + 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 == {})