From a281f9ab771adaa438f01fd5394d7a73ed6bc1d6 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi <50386592+SuvarnaMeenakshi@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:17:01 -0700 Subject: [PATCH] [ciscoPfcExtMIB]: Remove returning first intf index if subid is empty (#322) - What I did When querying for PFC counters MIB cpfcIfTable if there is no interface present on the device, then there is an exception while handing get_next as the implementation tries to return the first index of an empty list. This happens in case of VoQ chassis Supervisor where there are no interfaces present. Anytime a snmp query is made to cpfcIfTable 1.3.6.1.4.1.9.9.813.1.1, the exception message gets logged on the device. - How I did it Currently if sub_id is None, if_range[0] is returned. IF if_range is empty array this can cause an Exception. Removed this check to avoid returning if_range[0]. The check "if not sub_id" is not required here. right = bisect_right(self.if_range, sub_id) will handle if the sub_id is empty or if the if_range is empty by returning 0 index. - How to verify it Verified that no exception is logged upon query in VoQ chassis supervisor. Other platforms like Linecard, single-asic device - no Change in the SNMP result. --- .../mibs/vendor/cisco/ciscoPfcExtMIB.py | 3 --- tests/namespace/test_pfc.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py index bee16d5d6..b2b6bb2de 100644 --- a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py +++ b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py @@ -70,9 +70,6 @@ def get_next(self, sub_id): :return: the next sub id. """ try: - if not sub_id: - return self.if_range[0] - right = bisect_right(self.if_range, sub_id) if right >= len(self.if_range): return None diff --git a/tests/namespace/test_pfc.py b/tests/namespace/test_pfc.py index 7dd7eaf9e..5cb02eb40 100644 --- a/tests/namespace/test_pfc.py +++ b/tests/namespace/test_pfc.py @@ -2,6 +2,11 @@ import sys import importlib +if sys.version_info.major == 3: + from unittest import mock +else: + import mock + # noinspection PyUnresolvedReferences import tests.mock_tables.dbconnector @@ -265,6 +270,18 @@ def test_getPfcSubtree(self): self.assertEqual(str(value0.name), str(expected_oid)) self.assertEqual(value0.data, 209347219842134092490 % pow(2, 64)) # Test integer truncation + def test_no_interfaces(self): + # Test the scenario where there are no interfaces + # like the case of Packet-chassis supervisor + ciscoPfcExtMIB.cpfcIfTable.pfc_updater.if_range = [] + importlib.reload(ciscoPfcExtMIB) + oid = ObjectIdentifier(32, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 813, 1)) + sub_id = () + with mock.patch('sonic_ax_impl.mibs.logger.error') as mock_logger: + get_pdu = ciscoPfcExtMIB.cpfcIfTable.pfc_updater.get_next(sub_id) + self.assertEqual(get_pdu, None) + mock_logger.assert_not_called() + @classmethod def tearDownClass(cls): tests.mock_tables.dbconnector.clean_up_config()