From cc6e3d42fba2fe2c37483f900d19af4bccb52a2c Mon Sep 17 00:00:00 2001 From: Longyin Huang Date: Fri, 16 Feb 2024 16:40:23 -0800 Subject: [PATCH 1/3] Fix sfputil invalid namesapce error --- sfputil/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sfputil/main.py b/sfputil/main.py index eddc43f3dc..937b13fa2d 100644 --- a/sfputil/main.py +++ b/sfputil/main.py @@ -24,6 +24,7 @@ from utilities_common.sfp_helper import covert_application_advertisement_to_output_string from utilities_common.sfp_helper import QSFP_DATA_MAP from tabulate import tabulate +from utilities_common.general import load_db_config VERSION = '3.0' @@ -563,6 +564,7 @@ def load_sfputilhelper(): def load_port_config(): + load_db_config() try: if multi_asic.is_multi_asic(): # For multi ASIC platforms we pass DIR of port_config_file_path and the number of asics From 79cbbca64b9da0c99e6689ddb743fa12ca0e02d9 Mon Sep 17 00:00:00 2001 From: Longyin Huang Date: Thu, 22 Feb 2024 15:09:42 -0800 Subject: [PATCH 2/3] Add test case for loading port configuration --- tests/sfputil_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/sfputil_test.py b/tests/sfputil_test.py index 63814f31c5..e6705be235 100644 --- a/tests/sfputil_test.py +++ b/tests/sfputil_test.py @@ -1412,3 +1412,11 @@ def test_target_firmware(self, mock_chassis): result = runner.invoke(sfputil.cli.commands['firmware'].commands['target'], ["Ethernet0", "1"]) assert result.output == 'Target Mode set failed!\n' assert result.exit_code == EXIT_FAIL + + @patch('sfputil.main.multi_asic.is_multi_asic', MagicMock(return_value=True)) + @patch('sfputil.main.platform_sfputil', MagicMock()) + @patch('sfputil.main.device_info.get_paths_to_platform_and_hwsku_dirs', + MagicMock(return_value=(None, None))) + @patch('sfputil.main.device_info.get_path_to_port_config_file', MagicMock(return_value=(''))) + def test_load_port_config(self): + assert sfputil.load_port_config() == True From c8a67de6d09e4f9668e704635f114977c0891826 Mon Sep 17 00:00:00 2001 From: Longyin Huang Date: Thu, 22 Feb 2024 15:22:40 -0800 Subject: [PATCH 3/3] Improve cov --- tests/sfputil_test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/sfputil_test.py b/tests/sfputil_test.py index e6705be235..e732140f83 100644 --- a/tests/sfputil_test.py +++ b/tests/sfputil_test.py @@ -1413,10 +1413,14 @@ def test_target_firmware(self, mock_chassis): assert result.output == 'Target Mode set failed!\n' assert result.exit_code == EXIT_FAIL - @patch('sfputil.main.multi_asic.is_multi_asic', MagicMock(return_value=True)) + @patch('sfputil.main.multi_asic.is_multi_asic') @patch('sfputil.main.platform_sfputil', MagicMock()) @patch('sfputil.main.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=(None, None))) @patch('sfputil.main.device_info.get_path_to_port_config_file', MagicMock(return_value=(''))) - def test_load_port_config(self): + def test_load_port_config(self, mock_is_multi_asic): + mock_is_multi_asic.return_value = True + assert sfputil.load_port_config() == True + + mock_is_multi_asic.return_value = False assert sfputil.load_port_config() == True