Skip to content

Commit

Permalink
[Mellanox] [202106] Fix issue: SFP might not be re-initialized after …
Browse files Browse the repository at this point in the history
…cable plug in
  • Loading branch information
Junchao-Mellanox committed Nov 29, 2021
1 parent 1ebe528 commit 3ce7a3c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
18 changes: 7 additions & 11 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self):

# Initialize DMI data
self.dmi_data = None

# move the initialization of each components to their dedicated initializer
# which will be called from platform
#
Expand Down Expand Up @@ -261,15 +261,15 @@ def get_model(self):
def get_revision(self):
"""
Retrieves the hardware revision of the device
Returns:
string: Revision value of device
"""
if self.dmi_data is None:
self.dmi_data = self._parse_dmi(DMI_FILE)

return self.dmi_data.get(DMI_VERSION, "N/A")

##############################################
# SFP methods
##############################################
Expand All @@ -290,7 +290,7 @@ def get_all_sfps(self):
Retrieves all sfps available on this chassis
Returns:
A list of objects derived from SfpBase representing all sfps
A list of objects derived from SfpBase representing all sfps
available on this chassis
"""
if not self.sfp_module_full_initialized:
Expand Down Expand Up @@ -361,7 +361,7 @@ def get_watchdog(self):
Note:
We overload this method to ensure that watchdog is only initialized
when it is referenced. Currently, only one daemon can open the watchdog.
To initialize watchdog in the constructor causes multiple daemon
To initialize watchdog in the constructor causes multiple daemon
try opening watchdog when loading and constructing a chassis object
and fail. By doing so we can eliminate that risk.
"""
Expand Down Expand Up @@ -450,7 +450,7 @@ def _parse_dmi(self, filename):

def _verify_reboot_cause(self, filename):
'''
Open and read the reboot cause file in
Open and read the reboot cause file in
/var/run/hwmanagement/system (which is defined as REBOOT_CAUSE_ROOT)
If a reboot cause file doesn't exists, returns '0'.
'''
Expand Down Expand Up @@ -550,7 +550,7 @@ def get_change_event(self, timeout=0):
- True if call successful, False if not;
- A nested dictionary where key is a device type,
value is a dictionary with key:value pairs in the format of
{'device_id':'device_event'},
{'device_id':'device_event'},
where device_id is the device ID for this device and
device_event,
status='1' represents device inserted,
Expand Down Expand Up @@ -594,10 +594,6 @@ def reinit_sfps(self, port_dict):
:param port_dict: SFP event data
:return:
"""
# SFP not initialize yet, do nothing
if not self.sfp_module_full_initialized:
return

from . import sfp
for index, status in port_dict.items():
if status == sfp.SFP_STATUS_INSERTED:
Expand Down
17 changes: 15 additions & 2 deletions platform/mellanox/mlnx-platform-api/tests/test_sfp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
import pytest
from mock import MagicMock
from mock import MagicMock, patch
from .mock_platform import MockFan

test_path = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -11,7 +11,7 @@
os.environ["PLATFORM_API_UNIT_TESTING"] = "1"

from sonic_py_common import device_info
from sonic_platform.sfp import SFP, SX_PORT_MODULE_STATUS_INITIALIZING, SX_PORT_MODULE_STATUS_PLUGGED, SX_PORT_MODULE_STATUS_UNPLUGGED, SX_PORT_MODULE_STATUS_PLUGGED_WITH_ERROR, SX_PORT_MODULE_STATUS_PLUGGED_DISABLED
from sonic_platform.sfp import SFP, SX_PORT_MODULE_STATUS_INITIALIZING, SX_PORT_MODULE_STATUS_PLUGGED, SX_PORT_MODULE_STATUS_UNPLUGGED, SX_PORT_MODULE_STATUS_PLUGGED_WITH_ERROR, SX_PORT_MODULE_STATUS_PLUGGED_DISABLED, SFP_STATUS_INSERTED

from sonic_platform.chassis import Chassis

Expand Down Expand Up @@ -123,3 +123,16 @@ def test_sfp_get_error_status():
description = sfp.get_error_description()

assert description == expected_description


@patch('sonic_platform.sfp.SFP.reinit')
def test_reinit_sfps(mock_reinit_sfps):
port_dict = {}
chassis = Chassis()
chassis.reinit_sfps(port_dict)
assert not mock_reinit_sfps.called

port_dict = {1: SFP_STATUS_INSERTED}
chassis.reinit_sfps(port_dict)
assert mock_reinit_sfps.called
assert chassis._sfp_list[0] is not None

0 comments on commit 3ce7a3c

Please sign in to comment.