Skip to content

Commit

Permalink
[ciscoPfcExtMIB]: Remove returning first intf index if subid is empty (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
SuvarnaMeenakshi authored and mssonicbld committed Aug 24, 2024
1 parent 4e19e2c commit 5fec35f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/namespace/test_pfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()

0 comments on commit 5fec35f

Please sign in to comment.