Skip to content

Commit

Permalink
Enhance get_error_description to support CMIS cable host mgmt case
Browse files Browse the repository at this point in the history
Signed-off-by: Kebo Liu <kebol@nvidia.com>
  • Loading branch information
keboliu committed Nov 19, 2024
1 parent 3cb17c0 commit 379edff
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 379edff

Please sign in to comment.