diff --git a/src/sonic_ax_impl/mibs/ietf/rfc2863.py b/src/sonic_ax_impl/mibs/ietf/rfc2863.py index e5a41a0b8..1a4d17b77 100644 --- a/src/sonic_ax_impl/mibs/ietf/rfc2863.py +++ b/src/sonic_ax_impl/mibs/ietf/rfc2863.py @@ -289,6 +289,15 @@ def _get_if_entry(self, oid): return Namespace.dbs_get_all(self.db_conn, db, if_table, blocking=True) + def _get_mgmt_speed(self, oid): + interface = self.mgmt_oid_name_map[oid] + try: + with open(f'/sys/class/net/{interface}/speed', 'r') as f: + speed = int(f.read().strip()) + return speed + except: + return 0 + def get_high_speed(self, sub_id): """ :param sub_id: The 1-based sub-identifier query. @@ -298,6 +307,9 @@ def get_high_speed(self, sub_id): if not oid: return + if oid in self.mgmt_oid_name_map: + return self._get_mgmt_speed(oid) + if oid in self.oid_lag_name_map: speed = 0 for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]: diff --git a/tests/namespace/test_hc_interfaces.py b/tests/namespace/test_hc_interfaces.py index e93ecb04f..6d4e31ccf 100644 --- a/tests/namespace/test_hc_interfaces.py +++ b/tests/namespace/test_hc_interfaces.py @@ -9,6 +9,7 @@ sys.path.insert(0, os.path.join(modules_path, 'src')) from unittest import TestCase +from unittest.mock import patch, mock_open from ax_interface import ValueType from ax_interface.pdu import PDU @@ -222,7 +223,8 @@ def test_mgmt_iface_alias(self): self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 1, 10001)))) self.assertEqual(str(value0.data), 'mgmt1') - def test_mgmt_iface_speed(self): + @patch("builtins.open", new_callable=mock_open, read_data="1000\n") + def test_mgmt_iface_speed(self, mock_file): """ Test that mgmt port speed is 1000 """ diff --git a/tests/test_hc_interfaces.py b/tests/test_hc_interfaces.py index ea5638c3a..76ebd8ea5 100644 --- a/tests/test_hc_interfaces.py +++ b/tests/test_hc_interfaces.py @@ -9,6 +9,7 @@ sys.path.insert(0, os.path.join(modules_path, 'src')) from unittest import TestCase +from unittest.mock import patch, mock_open from ax_interface import ValueType from ax_interface.pdu import PDU @@ -225,7 +226,8 @@ def test_mgmt_iface_alias(self): self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 1, 10001)))) self.assertEqual(str(value0.data), 'mgmt1') - def test_mgmt_iface_speed(self): + @patch("builtins.open", new_callable=mock_open, read_data="1000\n") + def test_mgmt_iface_speed(self, mock_file): """ Test that mgmt port speed is 1000 """