Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix key missing exception when invalied transiver info in STATE_DB #289

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/sonic_ax_impl/mibs/ietf/rfc3433.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ def __init__(self):
self.fan_sensor = []
self.psu_sensor = []
self.thermal_sensor = []
self.broken_transceiver_info = []

def reinit_data(self):
"""
Expand Down Expand Up @@ -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)
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broken_transceiver_info

Not an issue and just comment: since the broken_transceiver_info is indexed by interface, and interface is validated above, so there are limited number of possible interface, so the broken_transceiver_info will have size limitation. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by flush broken_transceiver_info in reinit_data()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for misleading, my point is this is not an issue or a bug. Because broken_transceiver_info has limited size by its current usage. No need to reinit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary change reverted.

continue

# skip RJ45 port
if transceiver_info_entry_data['type'] == RJ45_PORT_TYPE:
continue

Expand Down
28 changes: 28 additions & 0 deletions tests/test_rfc3433.py
Original file line number Diff line number Diff line change
@@ -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)