From 379edffdb81b3901fa14165cf2003e44cfa32f65 Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Tue, 19 Nov 2024 09:26:37 +0200 Subject: [PATCH] Enhance get_error_description to support CMIS cable host mgmt case Signed-off-by: Kebo Liu --- platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py | 6 ++++-- platform/mellanox/mlnx-platform-api/tests/test_sfp.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py index aa3e188ae5f7..0e76f947b839 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py @@ -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"); @@ -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 diff --git a/platform/mellanox/mlnx-platform-api/tests/test_sfp.py b/platform/mellanox/mlnx-platform-api/tests/test_sfp.py index 092179f03fff..fecfadc1d93c 100644 --- a/platform/mellanox/mlnx-platform-api/tests/test_sfp.py +++ b/platform/mellanox/mlnx-platform-api/tests/test_sfp.py @@ -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"); @@ -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 @@ -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()