From 91f465d2515f8f6f1a8b9ea99330dd2c7bad6720 Mon Sep 17 00:00:00 2001 From: longhuan-cisco <84595962+longhuan-cisco@users.noreply.github.com> Date: Fri, 23 Feb 2024 11:14:30 -0800 Subject: [PATCH 1/4] Fix sfputil CLI failure for multi-asic platforms (#3168) * Fix sfputil invalid namesapce error * Add test case for loading port configuration * Improve cov --- sfputil/main.py | 2 ++ tests/sfputil_test.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/sfputil/main.py b/sfputil/main.py index 42630de7e3..514bc3a4af 100644 --- a/sfputil/main.py +++ b/sfputil/main.py @@ -23,6 +23,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' @@ -548,6 +549,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 diff --git a/tests/sfputil_test.py b/tests/sfputil_test.py index 6224cef51b..5bd14180d6 100644 --- a/tests/sfputil_test.py +++ b/tests/sfputil_test.py @@ -839,3 +839,15 @@ def test_update_firmware_info_to_state_db(self, mock_chassis): mock_sfp.get_transceiver_info_firmware_versions.return_value = ['a.b.c', 'd.e.f'] sfputil.update_firmware_info_to_state_db("Ethernet0") + + @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, 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 \ No newline at end of file From 227348a1c7e52116da9dbf7a33446efbc76bc45a Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Tue, 19 Mar 2024 22:53:17 -0700 Subject: [PATCH 2/4] Update port2alias (#3217) Basically port2alias Cli became broken on multi-asic platforms after introduction of sonic-net/sonic-buildimage#10960 which removed the initialization of global DB config from portconfig.py (library side) and expects application to do it, but here application side (port2alias) was not updated accordingly. How I did it Add load_db_config call to port2alias for initialization --- scripts/port2alias | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/port2alias b/scripts/port2alias index 5a4ff8dd79..c993890699 100755 --- a/scripts/port2alias +++ b/scripts/port2alias @@ -7,6 +7,7 @@ from io import StringIO from portconfig import get_port_config from sonic_py_common import device_info from sonic_py_common import multi_asic +from utilities_common.general import load_db_config # mock the redis for unit test purposes # try: @@ -50,6 +51,7 @@ def translate_line(line, ports): def main(): (platform, hwsku) = device_info.get_platform_and_hwsku() ports = {} + load_db_config() for ns in multi_asic.get_namespace_list(): (ports_ns, _, _) = get_port_config(hwsku=hwsku, platform=platform, asic_name=ns) ports.update(ports_ns) From 5b281bb72545704d74604f5115ead8b086e46f61 Mon Sep 17 00:00:00 2001 From: wumiao_nokia Date: Mon, 22 Apr 2024 15:11:38 -0400 Subject: [PATCH 3/4] Fix db_migrator.py where need check before calling initializeGlobalConfig or initialize(). This is a porting fix effort from master https://github.com/sonic-net/sonic-utilities/pull/3257. --- scripts/db_migrator.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index b6ae5a7e6e..4d6d3f45b5 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -1045,10 +1045,14 @@ def main(): socket_path = args.socket namespace = args.namespace + # Can't load global config base on the result of is_multi_asic(), because on multi-asic device, when db_migrate.py + # run on the local database, ASIC instance will have not created the /var/run/redis0/sonic-db/database-config.json if args.namespace is not None: - SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace) + if not SonicDBConfig.isGlobalInit(): + SonicDBConfig.initializeGlobalConfig() else: - SonicDBConfig.initialize() + if not SonicDBConfig.isInit(): + SonicDBConfig.initialize() if socket_path: dbmgtr = DBMigrator(namespace, socket=socket_path) From 3e9a1a94babe436473a1820ebe5f79ecbd1cb350 Mon Sep 17 00:00:00 2001 From: wumiao_nokia Date: Mon, 22 Apr 2024 16:36:53 -0400 Subject: [PATCH 4/4] Revert "Fix db_migrator.py where need check before calling initializeGlobalConfig or initialize(). This is a porting fix effort from master https://github.com/sonic-net/sonic-utilities/pull/3257." This reverts commit 5b281bb72545704d74604f5115ead8b086e46f61. --- scripts/db_migrator.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index 4d6d3f45b5..b6ae5a7e6e 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -1045,14 +1045,10 @@ def main(): socket_path = args.socket namespace = args.namespace - # Can't load global config base on the result of is_multi_asic(), because on multi-asic device, when db_migrate.py - # run on the local database, ASIC instance will have not created the /var/run/redis0/sonic-db/database-config.json if args.namespace is not None: - if not SonicDBConfig.isGlobalInit(): - SonicDBConfig.initializeGlobalConfig() + SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace) else: - if not SonicDBConfig.isInit(): - SonicDBConfig.initialize() + SonicDBConfig.initialize() if socket_path: dbmgtr = DBMigrator(namespace, socket=socket_path)