Skip to content

Support to get MEDIA_SETTING and OPTICS_SI from both platform folder and HWSKU folder #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,14 @@ def test_init_port_sfp_status_tbl(self):
task = SfpStateUpdateTask(DEFAULT_NAMESPACE, port_mapping, stop_event, sfp_error_event)
task._init_port_sfp_status_tbl(port_mapping, xcvr_table_helper, stop_event)

@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/invalid/path', None)))
@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/invalid/path', '/invalid/path')))
def test_load_media_settings_missing_file(self):
assert media_settings_parser.load_media_settings() == {}

@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/invalid/path', '/invalid/path')))
def test_load_optical_si_settings_missing_file(self):
assert optics_si_parser.load_optics_si_settings() == {}

@patch('xcvrd.xcvrd.platform_chassis')
@patch('xcvrd.xcvrd.is_cmis_api')
def test_get_media_settings_key(self, mock_is_cmis_api, mock_chassis):
Expand Down Expand Up @@ -2489,6 +2493,21 @@ def test_DaemonXcvrd_init_deinit_cold(self):

status_tbl.hdel.assert_called()

@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=(test_path, '/invalid/path')))
def test_load_optical_si_file_from_platform_folder(self):
assert optics_si_parser.load_optics_si_settings() != {}

@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/invalid/path', test_path)))
def test_load_optical_si_file_from_hwsku_folder(self):
assert optics_si_parser.load_optics_si_settings() != {}

@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=(test_path, '/invalid/path')))
def test_load_media_settings_file_from_platform_folder(self):
assert media_settings_parser.load_media_settings() != {}

@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/invalid/path', test_path)))
def test_load_media_settings_file_from_hwsku_folder(self):
assert media_settings_parser.load_media_settings() != {}

def wait_until(total_wait_time, interval, call_back, *args, **kwargs):
wait_time = 0
Expand Down
13 changes: 10 additions & 3 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@

def load_media_settings():
global g_dict
(platform_path, _) = device_info.get_paths_to_platform_and_hwsku_dirs()
(platform_path, hwsku_path) = device_info.get_paths_to_platform_and_hwsku_dirs()

media_settings_file_path = os.path.join(platform_path, "media_settings.json")
if not os.path.isfile(media_settings_file_path):
# Support to fetch media_settings.json both from platform folder and HWSKU folder
media_settings_file_path_platform = os.path.join(platform_path, "media_settings.json")
media_settings_file_path_hwsku = os.path.join(hwsku_path, "media_settings.json")

if os.path.isfile(media_settings_file_path_hwsku):
media_settings_file_path = media_settings_file_path_hwsku
elif os.path.isfile(media_settings_file_path_platform):
media_settings_file_path = media_settings_file_path_platform
else:
helper_logger.log_info("xcvrd: No media file exists")
return {}

Expand Down
13 changes: 10 additions & 3 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/optics_si_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,17 @@ def fetch_optics_si_setting(physical_port, lane_speed, sfp):

def load_optics_si_settings():
global g_optics_si_dict
(platform_path, _) = device_info.get_paths_to_platform_and_hwsku_dirs()
(platform_path, hwsku_path) = device_info.get_paths_to_platform_and_hwsku_dirs()

optics_si_settings_file_path = os.path.join(platform_path, "optics_si_settings.json")
if not os.path.isfile(optics_si_settings_file_path):
# Support to fetch optics_si_settings.json both from platform folder and HWSKU folder
optics_si_settings_file_path_platform = os.path.join(platform_path, "optics_si_settings.json")
optics_si_settings_file_path_hwsku = os.path.join(hwsku_path, "optics_si_settings.json")

if os.path.isfile(optics_si_settings_file_path_hwsku):
optics_si_settings_file_path = optics_si_settings_file_path_hwsku
elif os.path.isfile(optics_si_settings_file_path_platform):
optics_si_settings_file_path = optics_si_settings_file_path_platform
else:
helper_logger.log_info("No optics SI file exists")
return {}

Expand Down