Skip to content

Fix: initialize SonicDBConfig differently for single or multi_asic (continued) #1417

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 4 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
Expand Down
11 changes: 8 additions & 3 deletions crm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Copy link
Contributor

@judyjoseph judyjoseph Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isInit() is the check for SonicDBConfig.initialize(), ideal place would be in else: before we call initialize().

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):
Expand Down
2 changes: 2 additions & 0 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions scripts/lldpshow
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions scripts/portconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down