Skip to content

Commit 73e28b9

Browse files
authored
Fix: initialize SonicDBConfig differently for single or multi_asic (continued) (#1417)
**- What I did** This bug is exposed by #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.
1 parent 23fa39c commit 73e28b9

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

acl_loader/main.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import tabulate
1010
import pyangbind.lib.pybindJSON as pybindJSON
1111
from natsort import natsorted
12-
from sonic_py_common import device_info
12+
from sonic_py_common import device_info, multi_asic
1313
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig
1414

1515

@@ -114,8 +114,13 @@ def __init__(self):
114114
self.tables_db_info = {}
115115
self.rules_db_info = {}
116116
self.rules_info = {}
117-
# Load global db config. This call is no-op in single npu platforms
118-
SonicDBConfig.load_sonic_global_db_config()
117+
118+
if multi_asic.is_multi_asic():
119+
# Load global db config
120+
SonicDBConfig.load_sonic_global_db_config()
121+
else:
122+
SonicDBConfig.initialize()
123+
119124
self.sessions_db_info = {}
120125
self.configdb = ConfigDBConnector()
121126
self.configdb.connect()

crm/main.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,20 @@ def cli(ctx):
211211
# Use the db object if given as input.
212212
db = None if ctx.obj is None else ctx.obj.cfgdb
213213

214+
# Note: SonicDBConfig may be already initialized in unit test, then skip
215+
if not SonicDBConfig.isInit():
216+
if multi_asic.is_multi_asic():
217+
# Load the global config file database_global.json once.
218+
SonicDBConfig.load_sonic_global_db_config()
219+
else:
220+
SonicDBConfig.initialize()
221+
214222
context = {
215223
"crm": Crm(db)
216224
}
217225

218226
ctx.obj = context
219227

220-
# Load the global config file database_global.json once.
221-
SonicDBConfig.load_sonic_global_db_config()
222-
223228
@cli.group()
224229
@click.pass_context
225230
def config(ctx):

scripts/db_migrator.py

+2
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ def main():
555555

556556
if args.namespace is not None:
557557
SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace)
558+
else:
559+
SonicDBConfig.initialize()
558560

559561
if socket_path:
560562
dbmgtr = DBMigrator(namespace, socket=socket_path)

scripts/lldpshow

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import subprocess
2525
import sys
2626
import xml.etree.ElementTree as ET
2727

28-
from sonic_py_common import device_info
28+
from sonic_py_common import device_info, multi_asic
2929
from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig
3030
from tabulate import tabulate
3131

@@ -47,7 +47,11 @@ class Lldpshow(object):
4747
# So far only find Router and Bridge two capabilities in lldpctl, so any other capacility types will be read as Other
4848
# if further capability type is supported like WLAN, can just add the tag definition here
4949
self.ctags = {'Router': 'R', 'Bridge': 'B'}
50-
SonicDBConfig.load_sonic_global_db_config()
50+
51+
if multi_asic.is_multi_asic():
52+
SonicDBConfig.load_sonic_global_db_config()
53+
else:
54+
SonicDBConfig.initialize()
5155

5256
# For multi-asic platforms we will get only front-panel interface to display
5357
namespaces = device_info.get_all_namespaces()

scripts/portconfig

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def main():
8282

8383
if args.namespace is not None:
8484
SonicDBConfig.load_sonic_global_db_config(namespace=args.namespace)
85+
else:
86+
SonicDBConfig.initialize()
8587

8688
try:
8789
port = portconfig(args.verbose, args.port, args.namespace)

0 commit comments

Comments
 (0)