Skip to content

Commit

Permalink
Fix: initialize SonicDBConfig differently for single or multi_asic (c…
Browse files Browse the repository at this point in the history
…ontinued) (sonic-net#1417)

**- What I did**
This bug is exposed by sonic-net/sonic-utilities#1392. Previously the `config` command will call `SonicDBConfig.load_sonic_global_db_config()` even on a single ASIC platform, and it will silently failed. After exposed, it will fail with error syslog message:
```
Feb  9 05:04:46.462361 vlab-01 ERR python3: :- initializeGlobalConfig: Sonic database config global file doesn't exist at /var/run/redis/sonic-db/database_global.json
```

**- How to verify it**
Unit test and test in DUT.
  • Loading branch information
qiluo-msft authored Feb 11, 2021
1 parent 23fa39c commit 73e28b9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
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():
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

0 comments on commit 73e28b9

Please sign in to comment.