Skip to content

Commit

Permalink
Update SonicDBConfig APIs for centralize_database (#1441)
Browse files Browse the repository at this point in the history
The DB backup during warmboot has started failing recently after the changes made to deprecate the usage of SonicDBConfig methods originally implemented by python in https://github.com/Azure/sonic-py-swsssdk/. The new implementation is based on hiredis C++ library.

How I did it: The centralize_database script still uses the Python APIs instead of C++, update the method names which are now defined in sonic-swss-common.
With the new changes, the warm-boot goes ahead without DB save errors.
  • Loading branch information
vaibhavhd authored Feb 22, 2021
1 parent d8b224f commit d79d189
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions scripts/centralize_database
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import redis
import argparse

def centralize_to_target_db(target_dbname):
target_dbport = SonicDBConfig.get_port(target_dbname)
target_dbhost = SonicDBConfig.get_hostname(target_dbname)
target_dbport = SonicDBConfig.getDbPort(target_dbname)
target_dbhost = SonicDBConfig.getDbHostname(target_dbname)

dblists = SonicDBConfig.get_dblist()
dblists = SonicDBConfig.getDbList()
for dbname in dblists:
dbport = SonicDBConfig.get_port(dbname)
dbhost = SonicDBConfig.get_hostname(dbname)
dbport = SonicDBConfig.getDbPort(dbname)
dbhost = SonicDBConfig.getDbHostname(dbname)
# if the db is on the same instance, no need to move
if dbport == target_dbport and dbhost == target_dbhost:
continue

dbsocket = SonicDBConfig.get_socket(dbname)
dbid = SonicDBConfig.get_dbid(dbname)
dbsocket = SonicDBConfig.getDbSock(dbname)
dbid = SonicDBConfig.getDbId(dbname)

r = redis.Redis(host=dbhost, unix_socket_path=dbsocket, db=dbid)

Expand Down Expand Up @@ -49,7 +49,7 @@ Example : centralize_database APPL_DB
if args.target_db:
try:
centralize_to_target_db(args.target_db)
print(SonicDBConfig.get_instancename(args.target_db))
print(SonicDBConfig.getDbInst(args.target_db))
except Exception as ex:
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
Expand Down

0 comments on commit d79d189

Please sign in to comment.