Skip to content

Commit 13b975b

Browse files
[rfc1213] Handle error seen when interface counter is not available in COUNTERS_DB (#351)
- What I did Fix to handle error seen: ERR snmp#snmp-subagent [ax_interface] ERROR: SubtreeMIBEntry.__call__() caught an unexpected exception during _callable_.__call__()#012Traceback (most recent call last):#12 File "/usr/local/lib/python3.11/dist-packages/ax_interface/mib.py", line 248, in __call__#012 return self._callable_.__call__(sub_id, *self._callable_args)#12 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#12 File "/usr/local/lib/python3.11/dist-packages/sonic_ax_impl/mibs/ietf/rfc1213.py", line 414, in get_counter#012 counter_value += self._get_counter(mibs.get_index_from_str(lag_member), table_name)#012TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType' Above error can be seen if certain COUNTER is not supported in COUNTERS_DB. The counters present in DbTables is collected and returned in rfc1213 MIB implementation. Certain platform might not support all of these counters and can lead to the above exception. - How I did it Added logic to handle scenario where _get_counters returns None for any port-channel member interface. - How to verify it Added unit-test. Verified on platform where "SAI_PORT_STAT_IF_OUT_QLEN" is not available. Before fix: docker exec -it snmp snmpwalk -v2c -c <comm> <IP> 1.3.6.1.2.1.2.2.1.21 WARNING snmp#snmp-subagent [sonic_ax_impl] WARNING: SyncD 'COUNTERS_DB' missing attribute ''SAI_PORT_STAT_IF_OUT_QLEN''. ERR snmp#snmp-subagent [ax_interface] ERROR: SubtreeMIBEntry.__call__() caught an unexpected exception during _callable_.__call__()#012Traceback (most recent call last):#12 File "/usr/local/lib/python3.11/dist-packages/ax_interface/mib.py", line 248, in __call__#012 return self._callable_.__call__(sub_id, *self._callable_args)#12 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#12 File "/usr/local/lib/python3.11/dist-packages/sonic_ax_impl/mibs/ietf/rfc1213.py", line 414, in get_counter#012 counter_value += self._get_counter(mibs.get_index_from_str(lag_member), table_name)#012TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType' After fix: docker exec -it snmp snmpwalk -v2c -c <comm> <IP> 1.3.6.1.2.1.2.2.1.21 WARNING snmp#snmp-subagent [sonic_ax_impl] WARNING: SyncD 'COUNTERS_DB' missing attribute ''SAI_PORT_STAT_IF_OUT_QLEN''.
1 parent f55bee8 commit 13b975b

2 files changed

Lines changed: 65 additions & 3 deletions

File tree

src/sonic_ax_impl/mibs/ietf/rfc1213.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ def get_counter(self, sub_id, table_name):
411411
# mibs.get_index_from_str('Ethernet112') = 113 (because Ethernet N = N + 1)
412412
# self._get_counter retrieves the counter per oid and table.
413413
for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]:
414-
counter_value += self._get_counter(mibs.get_index_from_str(lag_member), table_name)
414+
member_counter = self._get_counter(mibs.get_index_from_str(lag_member), table_name)
415+
if member_counter is not None:
416+
counter_value += member_counter
417+
else:
418+
return None
415419
# Check if we need to add a router interface count.
416420
# Example:
417421
# self.lag_sai_map = {'PortChannel01': '2000000000006', 'PortChannel02': '2000000000005', 'PortChannel03': '2000000000004'}

tests/test_rfc1213.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1313
sys.path.insert(0, os.path.join(modules_path, 'src'))
1414

15-
from sonic_ax_impl.mibs.ietf.rfc1213 import NextHopUpdater, InterfacesUpdater
15+
from sonic_ax_impl.mibs.ietf.rfc1213 import NextHopUpdater, InterfacesUpdater, DbTables
1616

1717

1818
class TestNextHopUpdater(TestCase):
@@ -104,4 +104,62 @@ def mock_get_sync_d_from_all_namespace(per_namespace_func, db_conn):
104104
updater.reinit_data()
105105

106106
# check re-init
107-
connect_namespace_dbs.assert_called()
107+
connect_namespace_dbs.assert_called()
108+
109+
110+
def test_InterfaceUpdater_get_counters(self):
111+
112+
def mock_lag_entry_table(lag_name):
113+
if lag_name == "PortChannel103":
114+
return "PORT_TABLE:Ethernet120"
115+
116+
return
117+
118+
def mock_get_counter(oid, table_name):
119+
if oid == 121:
120+
return None
121+
else:
122+
return updater._get_counter(oid, table_name, mask)
123+
124+
def mock_get_sync_d_from_all_namespace(per_namespace_func, dbs):
125+
if per_namespace_func == sonic_ax_impl.mibs.init_sync_d_lag_tables:
126+
return [{'PortChannel999': [], 'PortChannel103': ['Ethernet120']}, # lag_name_if_name_map
127+
{},
128+
{1999: 'PortChannel999', 1103: 'PortChannel103'}, # oid_lag_name_map
129+
{},
130+
{}]
131+
132+
if per_namespace_func == sonic_ax_impl.mibs.init_sync_d_interface_tables:
133+
return [{},
134+
{},
135+
{},
136+
{121: 'Ethernet120'}]
137+
138+
if per_namespace_func == sonic_ax_impl.mibs.init_sync_d_rif_tables:
139+
return [{},{}]
140+
141+
142+
return [{},{},{}]
143+
144+
def mock_init_mgmt_interface_tables(db_conn):
145+
return [{},{}]
146+
147+
def mock_dbs_get_all(dbs, db_name, hash, *args, **kwargs):
148+
if hash == "PORT_TABLE:Ethernet120":
149+
return {'admin_status': 'up', 'alias': 'fortyGigE0/120', 'description': 'ARISTA03T1:Ethernet1', 'index': '30', 'lanes': '101,102,103,104', 'mtu': '9100', 'oper_status': 'up', 'pfc_asym': 'off', 'speed': '40000', 'tpid': '0x8100'}
150+
151+
return
152+
153+
with mock.patch('sonic_ax_impl.mibs.Namespace.get_sync_d_from_all_namespace', mock_get_sync_d_from_all_namespace):
154+
with mock.patch('sonic_ax_impl.mibs.lag_entry_table', mock_lag_entry_table):
155+
with mock.patch('sonic_ax_impl.mibs.init_mgmt_interface_tables', mock_init_mgmt_interface_tables):
156+
with mock.patch('sonic_ax_impl.mibs.Namespace.dbs_get_all', mock_dbs_get_all):
157+
updater = InterfacesUpdater()
158+
updater.reinit_data()
159+
updater.update_data()
160+
161+
try:
162+
counter = updater.get_counter((1103,), DbTables(21))
163+
except TypeError:
164+
self.fail("Caught Type error")
165+
self.assertTrue(counter == None)

0 commit comments

Comments
 (0)