Skip to content

Commit

Permalink
[Mellanox] [SFP API] Add support to the get_error_description functio…
Browse files Browse the repository at this point in the history
…n for when CMIS cable host management is enabled. (#20964)

- Why I did it
get_error_description is not supported when CMIS cable host mgmt. enabled, now enable this function and use the community common implementation.

- How I did it
When CMIS cable host mgmt. enabled, call the common platform API. Keep using original implementation in FW control mode.

- How to verify it
Test this API on different platforms in different modes.
Run SFP related sonic-mgmt test cases

Signed-off-by: Kebo Liu <[email protected]>
  • Loading branch information
keboliu authored Dec 3, 2024
1 parent d06ef9a commit 9e64ebe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -675,7 +676,8 @@ def get_error_description(self):
"""
try:
if self.is_sw_control():
return 'Not supported'
api = self.get_xcvr_api()
return api.get_error_description() if api else None
except:
return self.SFP_STATUS_INITIALIZING

Expand Down
6 changes: 4 additions & 2 deletions platform/mellanox/mlnx-platform-api/tests/test_sfp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -59,6 +60,7 @@ def test_sfp_index(self, mock_max_port):
@mock.patch('sonic_platform.sfp.SFP._get_module_info')
@mock.patch('sonic_platform.chassis.Chassis.get_num_sfps', mock.MagicMock(return_value=2))
@mock.patch('sonic_platform.chassis.extract_RJ45_ports_index', mock.MagicMock(return_value=[]))
@mock.patch('sonic_platform.sfp.SFP.get_xcvr_api', mock.MagicMock(return_value=None))
def test_sfp_get_error_status(self, mock_get_error_code, mock_control):
sfp = SFP(1)
mock_control.return_value = False
Expand Down Expand Up @@ -87,7 +89,7 @@ def test_sfp_get_error_status(self, mock_get_error_code, mock_control):

mock_control.return_value = True
description = sfp.get_error_description()
assert description == 'Not supported'
assert description == None

mock_control.side_effect = RuntimeError('')
description = sfp.get_error_description()
Expand Down

0 comments on commit 9e64ebe

Please sign in to comment.