Skip to content

Commit

Permalink
[multi-asic][cli][chassis-db] Avoid connecting to chassis db for cli …
Browse files Browse the repository at this point in the history
…commands executed from linecard (sonic-net#1707)

* [multi-asic][cli][chassis-db] Avoid connecting to chassis db

Currently, for all the cli commands, we connect to all databases
mentioned in the database_config.json. The database_config.json also
includes the databases from chassis redis server from supervisor card.
It is unneccessary to connect to databases from chassis redis server
when cli commands are executed form linecard. But we need to allow
connection to chassis databases when the cli commands are executed from
supervisor card.

The changes in this PR fixes this problem. The constructor of Db() class
which is instantiated for every CLI command execution is changed to skip
chassis databases from the list of collected databases if the card is not
supervisor card.

Signed-off-by: vedganes <vedavinayagam.ganesan@nokia.com>
  • Loading branch information
vganesan-nokia authored Oct 12, 2021
1 parent 1edf934 commit 476b3a4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions utilities_common/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sonic_py_common import multi_asic
from sonic_py_common import multi_asic, device_info
from swsscommon.swsscommon import ConfigDBConnector, SonicV2Connector
from utilities_common import constants
from utilities_common.multi_asic import multi_asic_ns_choices
Expand All @@ -11,7 +11,17 @@ def __init__(self):
self.cfgdb = ConfigDBConnector()
self.cfgdb.connect()
self.db = SonicV2Connector(host="127.0.0.1")
for db_id in self.db.get_db_list():

# Skip connecting to chassis databases in line cards
db_list = list(self.db.get_db_list())
if not device_info.is_supervisor():
try:
db_list.remove('CHASSIS_APP_DB')
db_list.remove('CHASSIS_STATE_DB')
except Exception:
pass

for db_id in db_list:
self.db.connect(db_id)

self.cfgdb_clients[constants.DEFAULT_NAMESPACE] = self.cfgdb
Expand Down

0 comments on commit 476b3a4

Please sign in to comment.