Skip to content

Commit 5057ac3

Browse files
dzhangalibabaqiluo-msft
authored andcommitted
[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
1 parent 7aa0baf commit 5057ac3

7 files changed

Lines changed: 19 additions & 28 deletions

File tree

dockers/docker-dhcp-relay/wait_for_intf.sh.j2

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
STATE_DB_IDX="6"
4-
53
function wait_until_iface_ready
64
{
75
IFACE_NAME=$1
@@ -12,7 +10,7 @@ function wait_until_iface_ready
1210
# Wait for the interface to come up
1311
# (i.e., interface is present in STATE_DB and state is "ok")
1412
while true; do
15-
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
13+
RESULT=$(sonic-db-cli STATE_DB HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
1614
if [ x"$RESULT" == x"ok" ]; then
1715
break
1816
fi

dockers/docker-fpm-frr/bgpcfgd

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ class Daemon(object):
8686
self.callbacks = defaultdict(lambda : defaultdict(list)) # db -> table -> []
8787
self.subscribers = set()
8888

89-
def add_manager(self, db, table_name, callback):
89+
def add_manager(self, db_name, table_name, callback):
90+
db = swsscommon.SonicDBConfig.getDbId(db_name)
9091
if db not in self.db_connectors:
91-
self.db_connectors[db] = swsscommon.DBConnector(db, swsscommon.DBConnector.DEFAULT_UNIXSOCKET, 0)
92+
self.db_connectors[db] = swsscommon.DBConnector(db_name, 0)
9293

9394
if table_name not in self.callbacks[db]:
9495
conn = self.db_connectors[db]
@@ -225,7 +226,7 @@ class BGPDeviceMetaMgr(Manager):
225226
daemon,
226227
directory,
227228
[],
228-
swsscommon.CONFIG_DB,
229+
"CONFIG_DB",
229230
swsscommon.CFG_DEVICE_METADATA_TABLE_NAME
230231
)
231232

@@ -250,7 +251,7 @@ class BGPNeighborMetaMgr(Manager):
250251
daemon,
251252
directory,
252253
[],
253-
swsscommon.CONFIG_DB,
254+
"CONFIG_DB",
254255
swsscommon.CFG_DEVICE_NEIGHBOR_METADATA_TABLE_NAME
255256
)
256257

@@ -272,7 +273,7 @@ class BGPPeerMgr(Manager):
272273
("meta", "localhost/bgp_asn"),
273274
("neigmeta", ""),
274275
],
275-
swsscommon.CONFIG_DB,
276+
"CONFIG_DB",
276277
swsscommon.CFG_BGP_NEIGHBOR_TABLE_NAME
277278
)
278279
self.peers = self.load_peers()

dockers/docker-lldp-sv2/lldpmgrd

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,18 @@ class LldpManager(object):
8484
pending_cmds: Dictionary where key is port name, value is pending
8585
LLDP configuration command to run
8686
"""
87-
REDIS_HOSTNAME = "localhost"
88-
REDIS_PORT = 6379
8987
REDIS_TIMEOUT_MS = 0
9088

9189
def __init__(self):
9290
# Open a handle to the Config database
93-
self.config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB,
94-
self.REDIS_HOSTNAME,
95-
self.REDIS_PORT,
96-
self.REDIS_TIMEOUT_MS)
91+
self.config_db = swsscommon.DBConnector("CONFIG_DB",
92+
self.REDIS_TIMEOUT_MS,
93+
True)
9794

9895
# Open a handle to the Application database
99-
self.appl_db = swsscommon.DBConnector(swsscommon.APPL_DB,
100-
self.REDIS_HOSTNAME,
101-
self.REDIS_PORT,
102-
self.REDIS_TIMEOUT_MS)
96+
self.appl_db = swsscommon.DBConnector("APPL_DB",
97+
self.REDIS_TIMEOUT_MS,
98+
True)
10399

104100
self.pending_cmds = {}
105101

dockers/docker-orchagent/swssconfig.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ HWSKU=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['hwsku']"`
4343

4444
# Don't load json config if system warm start or
4545
# swss docker warm start is enabled, the data already exists in appDB.
46-
SYSTEM_WARM_START=`redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable`
47-
SWSS_WARM_START=`redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|swss" enable`
46+
SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
47+
SWSS_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|swss" enable`
4848
if [[ "$SYSTEM_WARM_START" == "true" ]] || [[ "$SWSS_WARM_START" == "true" ]]; then
4949
# We have to make sure db data has not been flushed.
50-
RESTORE_COUNT=`redis-cli -n 6 hget "WARM_RESTART_TABLE|orchagent" restore_count`
50+
RESTORE_COUNT=`sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count`
5151
if [[ -n "$RESTORE_COUNT" ]] && [[ "$RESTORE_COUNT" != "0" ]]; then
5252
exit 0
5353
fi

dockers/docker-router-advertiser/wait_for_intf.sh.j2

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
STATE_DB_IDX="6"
4-
53
VLAN_TABLE_PREFIX="VLAN_TABLE"
64

75
function wait_until_iface_ready
@@ -14,7 +12,7 @@ function wait_until_iface_ready
1412
# Wait for the interface to come up
1513
# (i.e., interface is present in STATE_DB and state is "ok")
1614
while true; do
17-
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null)
15+
RESULT=$(sonic-db-cli STATE_DB HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null)
1816
if [ x"$RESULT" == x"ok" ]; then
1917
break
2018
fi

dockers/docker-sonic-telemetry/telemetry.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fi
2929

3030
# If no configuration entry exists for TELEMETRY, create one default port
3131
if [ -z $TELEMETRY ]; then
32-
redis-cli -n 4 hset "TELEMETRY|gnmi" port 8080
32+
sonic-db-cli CONFIG_DB hset "TELEMETRY|gnmi" port 8080
3333
fi
3434

3535
PORT=`sonic-cfggen -d -v "TELEMETRY['gnmi']['port']"`

src/sonic-config-engine/tests/sample_output/wait_for_intf.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
STATE_DB_IDX="6"
4-
53
function wait_until_iface_ready
64
{
75
IFACE_NAME=$1
@@ -12,7 +10,7 @@ function wait_until_iface_ready
1210
# Wait for the interface to come up
1311
# (i.e., interface is present in STATE_DB and state is "ok")
1412
while true; do
15-
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
13+
RESULT=$(sonic-db-cli STATE_DB HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
1614
if [ x"$RESULT" == x"ok" ]; then
1715
break
1816
fi

0 commit comments

Comments
 (0)