This commit is contained in:
Kebo Liu 2024-03-25 09:44:09 +08:00 committed by GitHub
commit ece3a52464
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 # Apache-2.0
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
@ -329,6 +329,12 @@ class Chassis(ChassisBase):
Returns: Returns:
An integer, the number of sfps available on this chassis An integer, the number of sfps available on this chassis
""" """
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() return DeviceDataManager.get_sfp_count()
def get_all_sfps(self): 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 # Apache-2.0
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
@ -169,6 +169,13 @@ class TestChassis:
assert len(sfp_list) == 3 assert len(sfp_list) == 3
assert chassis.sfp_initialized_count == 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): def test_create_sfp_in_multi_thread(self):
DeviceDataManager.get_sfp_count = mock.MagicMock(return_value=3) DeviceDataManager.get_sfp_count = mock.MagicMock(return_value=3)