-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mellanox] Add bitmap support for SFP error event (#7605)
#### Why I did it Currently, SONiC use a single value to represent SFP error, however, multiple SFP errors could exist at the same time. This PR is aimed to support it #### How I did it Return bitmap instead of single value when a SFP event occurs Signed-off-by: Stephen Sun <[email protected]>
- Loading branch information
1 parent
0a92ce1
commit 147bf24
Showing
5 changed files
with
244 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
platform/mellanox/mlnx-platform-api/tests/test_sfp_event.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import select | ||
import sys | ||
|
||
from mock import MagicMock | ||
|
||
test_path = os.path.dirname(os.path.abspath(__file__)) | ||
modules_path = os.path.dirname(test_path) | ||
sys.path.insert(0, modules_path) | ||
|
||
from sonic_platform_base.sfp_base import SfpBase | ||
|
||
class TestSfpEvent(object): | ||
@classmethod | ||
def setup_class(cls): | ||
os.environ["MLNX_PLATFORM_API_UNIT_TESTING"] = "1" | ||
select.select = MagicMock(return_value=([99], None, None)) | ||
|
||
def test_check_sfp_status(self): | ||
from sonic_platform.sfp_event import SDK_SFP_STATE_IN, SDK_SFP_STATE_OUT, SDK_SFP_STATE_ERR | ||
from sonic_platform.sfp_event import SDK_ERRORS_TO_ERROR_BITS, SDK_ERRORS_TO_DESCRIPTION, SDK_SFP_BLOCKING_ERRORS | ||
|
||
self.executor(SDK_SFP_STATE_IN, None, SfpBase.SFP_STATUS_BIT_INSERTED) | ||
self.executor(SDK_SFP_STATE_OUT, None, SfpBase.SFP_STATUS_BIT_REMOVED) | ||
for error_type, error_status in SDK_ERRORS_TO_ERROR_BITS.items(): | ||
description = SDK_ERRORS_TO_DESCRIPTION.get(error_type) | ||
if error_type in SDK_SFP_BLOCKING_ERRORS: | ||
error_status |= SfpBase.SFP_ERROR_BIT_BLOCKING | ||
error_status |= SfpBase.SFP_STATUS_BIT_INSERTED | ||
self.executor(SDK_SFP_STATE_ERR, error_type, error_status, description) | ||
|
||
def executor(self, mock_module_state, mock_error_type, expect_status, description=None): | ||
from sonic_platform.sfp_event import sfp_event | ||
|
||
event = sfp_event() | ||
event.on_pmpe = MagicMock(return_value=(True, [0,1], mock_module_state, mock_error_type)) | ||
port_change = {} | ||
error_dict = {} | ||
found = event.check_sfp_status(port_change, error_dict, 0) | ||
assert found | ||
expect_status_str = str(expect_status) | ||
assert 1 in port_change and port_change[1] == expect_status_str | ||
assert 2 in port_change and port_change[2] == expect_status_str | ||
if description: | ||
assert 1 in error_dict and error_dict[1] == description | ||
assert 2 in error_dict and error_dict[2] == description |