[MultiDB] (./dockers dir) : replace redis-cli with sonic-db-cli and use new DBConnector (#3923)

* [MultiDB] (./dockers dirs): replace redis-cli with sonic-db-cli and use new DBConnector

* remove unnecessary quota

* update typo
This commit is contained in:
Dong Zhang 2020-01-22 11:27:21 -08:00 committed by Qi Luo
parent 7aa0baf709
commit 5057ac3122
7 changed files with 19 additions and 28 deletions

View File

@ -1,7 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
STATE_DB_IDX="6"
function wait_until_iface_ready function wait_until_iface_ready
{ {
IFACE_NAME=$1 IFACE_NAME=$1
@ -12,7 +10,7 @@ function wait_until_iface_ready
# Wait for the interface to come up # Wait for the interface to come up
# (i.e., interface is present in STATE_DB and state is "ok") # (i.e., interface is present in STATE_DB and state is "ok")
while true; do while true; do
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null) RESULT=$(sonic-db-cli STATE_DB HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
if [ x"$RESULT" == x"ok" ]; then if [ x"$RESULT" == x"ok" ]; then
break break
fi fi

View File

@ -86,9 +86,10 @@ class Daemon(object):
self.callbacks = defaultdict(lambda : defaultdict(list)) # db -> table -> [] self.callbacks = defaultdict(lambda : defaultdict(list)) # db -> table -> []
self.subscribers = set() self.subscribers = set()
def add_manager(self, db, table_name, callback): def add_manager(self, db_name, table_name, callback):
db = swsscommon.SonicDBConfig.getDbId(db_name)
if db not in self.db_connectors: if db not in self.db_connectors:
self.db_connectors[db] = swsscommon.DBConnector(db, swsscommon.DBConnector.DEFAULT_UNIXSOCKET, 0) self.db_connectors[db] = swsscommon.DBConnector(db_name, 0)
if table_name not in self.callbacks[db]: if table_name not in self.callbacks[db]:
conn = self.db_connectors[db] conn = self.db_connectors[db]
@ -225,7 +226,7 @@ class BGPDeviceMetaMgr(Manager):
daemon, daemon,
directory, directory,
[], [],
swsscommon.CONFIG_DB, "CONFIG_DB",
swsscommon.CFG_DEVICE_METADATA_TABLE_NAME swsscommon.CFG_DEVICE_METADATA_TABLE_NAME
) )
@ -250,7 +251,7 @@ class BGPNeighborMetaMgr(Manager):
daemon, daemon,
directory, directory,
[], [],
swsscommon.CONFIG_DB, "CONFIG_DB",
swsscommon.CFG_DEVICE_NEIGHBOR_METADATA_TABLE_NAME swsscommon.CFG_DEVICE_NEIGHBOR_METADATA_TABLE_NAME
) )
@ -272,7 +273,7 @@ class BGPPeerMgr(Manager):
("meta", "localhost/bgp_asn"), ("meta", "localhost/bgp_asn"),
("neigmeta", ""), ("neigmeta", ""),
], ],
swsscommon.CONFIG_DB, "CONFIG_DB",
swsscommon.CFG_BGP_NEIGHBOR_TABLE_NAME swsscommon.CFG_BGP_NEIGHBOR_TABLE_NAME
) )
self.peers = self.load_peers() self.peers = self.load_peers()

View File

@ -84,22 +84,18 @@ class LldpManager(object):
pending_cmds: Dictionary where key is port name, value is pending pending_cmds: Dictionary where key is port name, value is pending
LLDP configuration command to run LLDP configuration command to run
""" """
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_MS = 0 REDIS_TIMEOUT_MS = 0
def __init__(self): def __init__(self):
# Open a handle to the Config database # Open a handle to the Config database
self.config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, self.config_db = swsscommon.DBConnector("CONFIG_DB",
self.REDIS_HOSTNAME, self.REDIS_TIMEOUT_MS,
self.REDIS_PORT, True)
self.REDIS_TIMEOUT_MS)
# Open a handle to the Application database # Open a handle to the Application database
self.appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, self.appl_db = swsscommon.DBConnector("APPL_DB",
self.REDIS_HOSTNAME, self.REDIS_TIMEOUT_MS,
self.REDIS_PORT, True)
self.REDIS_TIMEOUT_MS)
self.pending_cmds = {} self.pending_cmds = {}

View File

@ -43,11 +43,11 @@ HWSKU=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['hwsku']"`
# Don't load json config if system warm start or # Don't load json config if system warm start or
# swss docker warm start is enabled, the data already exists in appDB. # swss docker warm start is enabled, the data already exists in appDB.
SYSTEM_WARM_START=`redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable` SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
SWSS_WARM_START=`redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|swss" enable` SWSS_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|swss" enable`
if [[ "$SYSTEM_WARM_START" == "true" ]] || [[ "$SWSS_WARM_START" == "true" ]]; then if [[ "$SYSTEM_WARM_START" == "true" ]] || [[ "$SWSS_WARM_START" == "true" ]]; then
# We have to make sure db data has not been flushed. # We have to make sure db data has not been flushed.
RESTORE_COUNT=`redis-cli -n 6 hget "WARM_RESTART_TABLE|orchagent" restore_count` RESTORE_COUNT=`sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count`
if [[ -n "$RESTORE_COUNT" ]] && [[ "$RESTORE_COUNT" != "0" ]]; then if [[ -n "$RESTORE_COUNT" ]] && [[ "$RESTORE_COUNT" != "0" ]]; then
exit 0 exit 0
fi fi

View File

@ -1,7 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
STATE_DB_IDX="6"
VLAN_TABLE_PREFIX="VLAN_TABLE" VLAN_TABLE_PREFIX="VLAN_TABLE"
function wait_until_iface_ready function wait_until_iface_ready
@ -14,7 +12,7 @@ function wait_until_iface_ready
# Wait for the interface to come up # Wait for the interface to come up
# (i.e., interface is present in STATE_DB and state is "ok") # (i.e., interface is present in STATE_DB and state is "ok")
while true; do while true; do
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null) RESULT=$(sonic-db-cli STATE_DB HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null)
if [ x"$RESULT" == x"ok" ]; then if [ x"$RESULT" == x"ok" ]; then
break break
fi fi

View File

@ -29,7 +29,7 @@ fi
# If no configuration entry exists for TELEMETRY, create one default port # If no configuration entry exists for TELEMETRY, create one default port
if [ -z $TELEMETRY ]; then if [ -z $TELEMETRY ]; then
redis-cli -n 4 hset "TELEMETRY|gnmi" port 8080 sonic-db-cli CONFIG_DB hset "TELEMETRY|gnmi" port 8080
fi fi
PORT=`sonic-cfggen -d -v "TELEMETRY['gnmi']['port']"` PORT=`sonic-cfggen -d -v "TELEMETRY['gnmi']['port']"`

View File

@ -1,7 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
STATE_DB_IDX="6"
function wait_until_iface_ready function wait_until_iface_ready
{ {
IFACE_NAME=$1 IFACE_NAME=$1
@ -12,7 +10,7 @@ function wait_until_iface_ready
# Wait for the interface to come up # Wait for the interface to come up
# (i.e., interface is present in STATE_DB and state is "ok") # (i.e., interface is present in STATE_DB and state is "ok")
while true; do while true; do
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null) RESULT=$(sonic-db-cli STATE_DB HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
if [ x"$RESULT" == x"ok" ]; then if [ x"$RESULT" == x"ok" ]; then
break break
fi fi