From 2907cc8c5fffad705c70af9586fbf0d2deedeca9 Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Fri, 15 Mar 2024 10:13:00 +0200 Subject: [PATCH] fix wrong sfp counter on SN2201 platform Signed-off-by: Kebo Liu --- .../mlnx-platform-api/sonic_platform/chassis.py | 10 ++++++++-- .../mellanox/mlnx-platform-api/tests/test_chassis.py | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py index 5870d7e6b6..f216f6de2c 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. +# Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES. # Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -329,7 +329,13 @@ class Chassis(ChassisBase): Returns: An integer, the number of sfps available on this chassis """ - return DeviceDataManager.get_sfp_count() + if not self._RJ45_port_inited: + self._RJ45_port_list = extract_RJ45_ports_index() + self._RJ45_port_inited = True + if self._RJ45_port_list is not None: + return DeviceDataManager.get_sfp_count() + len(self._RJ45_port_list) + else: + return DeviceDataManager.get_sfp_count() def get_all_sfps(self): """ diff --git a/platform/mellanox/mlnx-platform-api/tests/test_chassis.py b/platform/mellanox/mlnx-platform-api/tests/test_chassis.py index ffe86aaf3d..ad23cd8dde 100644 --- a/platform/mellanox/mlnx-platform-api/tests/test_chassis.py +++ b/platform/mellanox/mlnx-platform-api/tests/test_chassis.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. +# Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES. # Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -169,6 +169,13 @@ class TestChassis: assert len(sfp_list) == 3 assert chassis.sfp_initialized_count == 3 + # Get all SFPs, with RJ45 ports + sonic_platform.chassis.extract_RJ45_ports_index = mock.MagicMock(return_value=[0,1,2]) + DeviceDataManager.get_sfp_count = mock.MagicMock(return_value=3) + chassis = Chassis() + assert chassis.get_num_sfps() == 6 + sonic_platform.chassis.extract_RJ45_ports_index = mock.MagicMock(return_value=[]) + def test_create_sfp_in_multi_thread(self): DeviceDataManager.get_sfp_count = mock.MagicMock(return_value=3)