diff --git a/acl_loader/main.py b/acl_loader/main.py index 0d8386f5c7..e0df7eec8b 100644 --- a/acl_loader/main.py +++ b/acl_loader/main.py @@ -9,7 +9,7 @@ import tabulate import pyangbind.lib.pybindJSON as pybindJSON from natsort import natsorted -from sonic_py_common import device_info +from sonic_py_common import device_info, multi_asic from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig @@ -114,8 +114,13 @@ def __init__(self): self.tables_db_info = {} self.rules_db_info = {} self.rules_info = {} - # Load global db config. This call is no-op in single npu platforms - SonicDBConfig.load_sonic_global_db_config() + + if multi_asic.is_multi_asic(): + # Load global db config + SonicDBConfig.load_sonic_global_db_config() + else: + SonicDBConfig.initialize() + self.sessions_db_info = {} self.configdb = ConfigDBConnector() self.configdb.connect() diff --git a/crm/main.py b/crm/main.py index caf0108b12..fdde198b1a 100644 --- a/crm/main.py +++ b/crm/main.py @@ -211,15 +211,20 @@ def cli(ctx): # Use the db object if given as input. db = None if ctx.obj is None else ctx.obj.cfgdb + # Note: SonicDBConfig may be already initialized in unit test, then skip + if not SonicDBConfig.isInit(): + if multi_asic.is_multi_asic(): + # Load the global config file database_global.json once. + SonicDBConfig.load_sonic_global_db_config() + else: + SonicDBConfig.initialize() + context = { "crm": Crm(db) } ctx.obj = context - # Load the global config file database_global.json once. - SonicDBConfig.load_sonic_global_db_config() - @cli.group() @click.pass_context def config(ctx): diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index c5d8232e4a..6e18ca4034 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -555,6 +555,8 @@ def main(): if args.namespace is not None: SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace) + else: + SonicDBConfig.initialize() if socket_path: dbmgtr = DBMigrator(namespace, socket=socket_path) diff --git a/scripts/lldpshow b/scripts/lldpshow index b6682b8df1..c41e78db00 100755 --- a/scripts/lldpshow +++ b/scripts/lldpshow @@ -25,7 +25,7 @@ import subprocess import sys import xml.etree.ElementTree as ET -from sonic_py_common import device_info +from sonic_py_common import device_info, multi_asic from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig from tabulate import tabulate @@ -47,7 +47,11 @@ class Lldpshow(object): # So far only find Router and Bridge two capabilities in lldpctl, so any other capacility types will be read as Other # if further capability type is supported like WLAN, can just add the tag definition here self.ctags = {'Router': 'R', 'Bridge': 'B'} - SonicDBConfig.load_sonic_global_db_config() + + if multi_asic.is_multi_asic(): + SonicDBConfig.load_sonic_global_db_config() + else: + SonicDBConfig.initialize() # For multi-asic platforms we will get only front-panel interface to display namespaces = device_info.get_all_namespaces() diff --git a/scripts/portconfig b/scripts/portconfig index 9a7cc545a3..b22e547101 100755 --- a/scripts/portconfig +++ b/scripts/portconfig @@ -82,6 +82,8 @@ def main(): if args.namespace is not None: SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace) + else: + SonicDBConfig.initialize() try: port = portconfig(args.verbose, args.port, args.namespace)