fix wrong sfp counter on SN2201 platform

Signed-off-by: Kebo Liu <kebol@nvidia.com>
This commit is contained in:
Kebo Liu 2024-03-15 10:13:00 +02:00
parent a33330941c
commit 2907cc8c5f
2 changed files with 16 additions and 3 deletions

View File

@ -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):
"""

View File

@ -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)