diff --git a/src/sonic_ax_impl/mibs/ietf/rfc3433.py b/src/sonic_ax_impl/mibs/ietf/rfc3433.py index b389e6813..89be78327 100644 --- a/src/sonic_ax_impl/mibs/ietf/rfc3433.py +++ b/src/sonic_ax_impl/mibs/ietf/rfc3433.py @@ -372,6 +372,7 @@ def __init__(self): self.fan_sensor = [] self.psu_sensor = [] self.thermal_sensor = [] + self.broken_transceiver_info = [] def reinit_data(self): """ @@ -422,8 +423,17 @@ def update_xcvr_dom_data(self): in STATE_DB, skipping".format(transceiver_dom_entry)) continue - # skip RJ45 port transceiver_info_entry_data = Namespace.dbs_get_all(self.statedb, mibs.STATE_DB, mibs.transceiver_info_table(interface)) + if 'type' not in transceiver_info_entry_data: + # Only write error log once + if interface not in self.broken_transceiver_info: + mibs.logger.warn( + "Invalid interface {} in STATE_DB, \ + attribute 'type' missing in transceiver_info '{}'".format(interface, transceiver_info_entry_data)) + self.broken_transceiver_info.append(interface) + continue + + # skip RJ45 port if transceiver_info_entry_data['type'] == RJ45_PORT_TYPE: continue diff --git a/tests/test_rfc3433.py b/tests/test_rfc3433.py new file mode 100644 index 000000000..dd6e94f40 --- /dev/null +++ b/tests/test_rfc3433.py @@ -0,0 +1,28 @@ +import os +import sys +from unittest import TestCase + +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')) + +from sonic_ax_impl.mibs.ietf.rfc3433 import PhysicalSensorTableMIBUpdater + +class TestPhysicalSensorTableMIBUpdater(TestCase): + + @mock.patch('sonic_ax_impl.mibs.Namespace.dbs_get_all', mock.MagicMock(return_value=({"hardwarerev": "1.0"}))) + def test_PhysicalSensorTableMIBUpdater_transceiver_info_key_missing(self): + updater = PhysicalSensorTableMIBUpdater() + updater.transceiver_dom.append("TRANSCEIVER_INFO|Ethernet0") + + with mock.patch('sonic_ax_impl.mibs.logger.warn') as mocked_warn: + updater.update_data() + + # check warning + mocked_warn.assert_called() + + self.assertTrue(len(updater.sub_ids) == 0) \ No newline at end of file