From 5cd6bc4ce2a32bd7b1b71dbcc85e7390799da7d0 Mon Sep 17 00:00:00 2001 From: SuvarnaMeenakshi <50386592+SuvarnaMeenakshi@users.noreply.github.com> Date: Fri, 22 Apr 2022 16:25:29 -0700 Subject: [PATCH] [portconfig]: Remove try block for db config initialization (#10581) Why I did it Provide fix for comment: https://github.com/Azure/sonic-buildimage/pull/10475/files#r847753187; How I did it Try exception is not required in this scenario, so remove and modify to initial db config according to single or multi-asic platforms. How to verify it Verified on multi-asic device. --- src/sonic-config-engine/portconfig.py | 7 +------ src/sonic-config-engine/sonic-cfggen | 8 +++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/sonic-config-engine/portconfig.py b/src/sonic-config-engine/portconfig.py index 0c056d1cda..ea9985a3be 100644 --- a/src/sonic-config-engine/portconfig.py +++ b/src/sonic-config-engine/portconfig.py @@ -72,12 +72,7 @@ def db_connect_configdb(namespace=None): """ Connect to configdb """ - try: - if namespace is not None: - swsscommon.SonicDBConfig.load_sonic_global_db_config(namespace=namespace) - config_db = swsscommon.ConfigDBConnector(use_unix_socket_path=True, namespace=namespace) - except Exception as e: - return None + config_db = swsscommon.ConfigDBConnector(use_unix_socket_path=True, namespace=namespace) if config_db is None: return None try: diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index aebd4d0544..b10002c408 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -32,7 +32,7 @@ from functools import partial from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role, parse_asic_switch_type from portconfig import get_port_config, get_breakout_mode from redis_bcc import RedisBytecodeCache -from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id +from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id, is_multi_asic from sonic_py_common import device_info from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector @@ -309,6 +309,12 @@ def main(): 'localhost': {'namespace_id': namespace_id} } }) + # load db config + if not SonicDBConfig.isInit(): + if is_multi_asic(): + SonicDBConfig.load_sonic_global_db_config(namespace=asic_name) + else: + SonicDBConfig.load_sonic_db_config() if hwsku is not None: hardware_data = {'DEVICE_METADATA': {'localhost': { 'hwsku': hwsku