Skip to content

Commit

Permalink
Revert "[MultiDB]except src and dockers : replace redis-cli with soni…
Browse files Browse the repository at this point in the history
…c-db-cli and use new DBConnector (#3928)" (#4002)

This reverts commit 0dae59a.
  • Loading branch information
lguohan authored Jan 10, 2020
1 parent c475519 commit 483a594
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 60 deletions.
9 changes: 6 additions & 3 deletions device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
SFP_I2C_PAGE_SIZE = 256

# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0

# parameters for SFP presence
Expand Down Expand Up @@ -188,9 +190,10 @@ def get_transceiver_change_event(self, timeout=0):

if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector("STATE_DB",
REDIS_TIMEOUT_USECS,
True))
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)

# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
Expand Down
34 changes: 17 additions & 17 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ function preStartAction()
docker cp /tmp/dump.rdb database:/var/lib/redis/
fi
{%- elif docker_container_name == "snmp" %}
sonic-db-cli STATE_DB HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s)
vrfenabled=`sonic-db-cli CONFIG_DB hget "MGMT_VRF_CONFIG|vrf_global" mgmtVrfEnabled`
v1SnmpTrapIp=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v1TrapDest" DestIp`
v1SnmpTrapPort=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v1TrapDest" DestPort`
v1Vrf=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v1TrapDest" vrf`
v1Comm=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v1TrapDest" Community`
v2SnmpTrapIp=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v2TrapDest" DestIp`
v2SnmpTrapPort=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v2TrapDest" DestPort`
v2Vrf=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v2TrapDest" vrf`
v2Comm=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v2TrapDest" Community`
v3SnmpTrapIp=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v3TrapDest" DestIp`
v3SnmpTrapPort=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v3TrapDest" DestPort`
v3Vrf=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v3TrapDest" vrf`
v3Comm=`sonic-db-cli CONFIG_DB hget "SNMP_TRAP_CONFIG|v3TrapDest" Community`
docker exec -i database redis-cli -n 6 HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s)
vrfenabled=`/usr/bin/redis-cli -n 4 hget "MGMT_VRF_CONFIG|vrf_global" mgmtVrfEnabled`
v1SnmpTrapIp=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v1TrapDest" DestIp`
v1SnmpTrapPort=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v1TrapDest" DestPort`
v1Vrf=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v1TrapDest" vrf`
v1Comm=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v1TrapDest" Community`
v2SnmpTrapIp=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v2TrapDest" DestIp`
v2SnmpTrapPort=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v2TrapDest" DestPort`
v2Vrf=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v2TrapDest" vrf`
v2Comm=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v2TrapDest" Community`
v3SnmpTrapIp=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v3TrapDest" DestIp`
v3SnmpTrapPort=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v3TrapDest" DestPort`
v3Vrf=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v3TrapDest" vrf`
v3Comm=`/usr/bin/redis-cli -n 4 hget "SNMP_TRAP_CONFIG|v3TrapDest" Community`

if [ "${v1SnmpTrapIp}" != "" ]
then
Expand Down Expand Up @@ -113,7 +113,7 @@ function preStartAction()
fi

echo -n "" > /tmp/snmpagentaddr.yml
keys=`sonic-db-cli CONFIG_DB keys "SNMP_AGENT_ADDRESS_CONFIG|*"`
keys=`/usr/bin/redis-cli -n 4 keys "SNMP_AGENT_ADDRESS_CONFIG|*"`
count=1
for key in $keys;do
ip=`echo $key|cut -d "|" -f2`
Expand Down Expand Up @@ -151,10 +151,10 @@ function postStartAction()

if [[ "$BOOT_TYPE" == "fast" ]]; then
# set the key to expire in 3 minutes
sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180"
redis-cli -n 6 SET "FAST_REBOOT|system" "1" "EX" "180"
fi

sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
redis-cli -n 4 SET "CONFIG_DB_INITIALIZED" "1"
fi

if [[ -x /usr/bin/db_migrator.py ]]; then
Expand Down
11 changes: 6 additions & 5 deletions files/image_config/config-setup/config-setup
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
###########################################################################

# Initialize constants
CONFIG_DB_INDEX=4
UPDATEGRAPH_CONF=/etc/sonic/updategraph.conf
CONFIG_DB_JSON=/etc/sonic/config_db.json
MINGRAPH_FILE=/etc/sonic/minigraph.xml
Expand Down Expand Up @@ -106,9 +107,9 @@ reload_minigraph()
if [ ! -f /etc/sonic/init_cfg.json ]; then
echo "{}" > /etc/sonic/init_cfg.json
fi
sonic-db-cli CONFIG_DB FLUSHDB
redis-cli -n $CONFIG_DB_INDEX FLUSHDB
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --write-to-db
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
redis-cli -n $CONFIG_DB_INDEX SET "CONFIG_DB_INITIALIZED" "1"
if [ -f /etc/sonic/acl.json ]; then
acl-loader update full /etc/sonic/acl.json
fi
Expand Down Expand Up @@ -137,7 +138,7 @@ function copy_config_files_and_directories()
# Check if SONiC swich has booted after a warm reboot request
check_system_warm_boot()
{
SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
SYSTEM_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable`
# SYSTEM_WARM_START could be empty, always make WARM_BOOT meaningful.
if [[ x"$SYSTEM_WARM_START" == x"true" ]]; then
WARM_BOOT="true"
Expand Down Expand Up @@ -186,7 +187,7 @@ load_config()
return 1
fi

sonic-db-cli CONFIG_DB FLUSHDB
redis-cli -n $CONFIG_DB_INDEX FLUSHDB
sonic-cfggen -j ${CONFIG_FILE} --write-to-db
if [ $? -ne 0 ]; then
return $?
Expand All @@ -197,7 +198,7 @@ load_config()
/usr/bin/db_migrator.py -o migrate
fi

sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
redis-cli -n $CONFIG_DB_INDEX SET "CONFIG_DB_INITIALIZED" "1"
return 0
}

Expand Down
10 changes: 6 additions & 4 deletions files/image_config/updategraph/updategraph
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/bin/bash

CONFIG_DB_INDEX=4

reload_minigraph()
{
echo "Reloading minigraph..."
if [ ! -f /etc/sonic/init_cfg.json ]; then
echo "{}" > /etc/sonic/init_cfg.json
fi
sonic-db-cli CONFIG_DB FLUSHDB
redis-cli -n $CONFIG_DB_INDEX FLUSHDB
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --write-to-db
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
redis-cli -n $CONFIG_DB_INDEX SET "CONFIG_DB_INITIALIZED" "1"
if [ -f /etc/sonic/acl.json ]; then
acl-loader update full /etc/sonic/acl.json
fi
Expand Down Expand Up @@ -75,9 +77,9 @@ if [ "$src" = "dhcp" ]; then
else
cp -f /tmp/device_meta.json /etc/sonic/config_db.json
fi
sonic-db-cli CONFIG_DB FLUSHDB
redis-cli -n $CONFIG_DB_INDEX FLUSHDB
sonic-cfggen -j /etc/sonic/config_db.json --write-to-db
sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
redis-cli -n $CONFIG_DB_INDEX SET "CONFIG_DB_INITIALIZED" "1"
if [ "$dhcp_as_static" = "true" ]; then
sed -i "/enabled=/d" /etc/sonic/updategraph.conf
echo "enabled=false" >> /etc/sonic/updategraph.conf
Expand Down
10 changes: 6 additions & 4 deletions files/image_config/warmboot-finalizer/finalize-warmboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function debug()

function check_warm_boot()
{
WARM_BOOT=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
WARM_BOOT=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable`
}


Expand All @@ -29,10 +29,12 @@ function wait_for_database_service()
debug "Wait for database to become ready..."

# Wait for redis server start before database clean
/usr/bin/docker exec database ping_pong_db_insts
until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]];
do sleep 1;
done

# Wait for configDB initialization
until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];
until [[ $(/usr/bin/docker exec database redis-cli -n 4 GET "CONFIG_DB_INITIALIZED") ]];
do sleep 1;
done

Expand All @@ -42,7 +44,7 @@ function wait_for_database_service()

function get_component_state()
{
sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|$1" state
/usr/bin/redis-cli -n 6 hget "WARM_RESTART_TABLE|$1" state
}


Expand Down
2 changes: 1 addition & 1 deletion files/scripts/configdb-load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ if [ -r /etc/sonic/config_db.json ]; then
sonic-cfggen -j /etc/sonic/config_db.json --write-to-db
fi

sonic-db-cli CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1"
redis-cli -n 4 SET "CONFIG_DB_INITIALIZED" "1"
26 changes: 14 additions & 12 deletions files/scripts/swss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function unlock_service_state_change()

function check_warm_boot()
{
SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
SERVICE_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable`
SYSTEM_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable`
SERVICE_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable`
if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then
WARM_BOOT="true"
else
Expand All @@ -43,7 +43,7 @@ function check_warm_boot()
function validate_restore_count()
{
if [[ x"$WARM_BOOT" == x"true" ]]; then
RESTORE_COUNT=`sonic-db-cli STATE_DB hget "WARM_RESTART_TABLE|orchagent" restore_count`
RESTORE_COUNT=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_TABLE|orchagent" restore_count`
# We have to make sure db data has not been flushed.
if [[ -z "$RESTORE_COUNT" ]]; then
WARM_BOOT="false"
Expand All @@ -54,10 +54,12 @@ function validate_restore_count()
function wait_for_database_service()
{
# Wait for redis server start before database clean
/usr/bin/docker exec database ping_pong_db_insts
until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]];
do sleep 1;
done

# Wait for configDB initialization
until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];
until [[ $(/usr/bin/docker exec database redis-cli -n 4 GET "CONFIG_DB_INITIALIZED") ]];
do sleep 1;
done
}
Expand All @@ -67,7 +69,7 @@ function wait_for_database_service()
# $2 the string of a list of table prefixes
function clean_up_tables()
{
sonic-db-cli $1 EVAL "
redis-cli -n $1 EVAL "
local tables = {$2}
for i = 1, table.getn(tables) do
local matches = redis.call('KEYS', tables[i])
Expand Down Expand Up @@ -112,11 +114,11 @@ start() {
# Don't flush DB during warm boot
if [[ x"$WARM_BOOT" != x"true" ]]; then
debug "Flushing APP, ASIC, COUNTER, CONFIG, and partial STATE databases ..."
sonic-db-cli APPL_DB FLUSHDB
sonic-db-cli ASIC_DB FLUSHDB
sonic-db-cli COUNTERS_DB FLUSHDB
sonic-db-cli FLEX_COUNTER_DB FLUSHDB
clean_up_tables STATE_DB "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'LAG_TABLE*', 'LAG_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*', 'FDB_TABLE*'"
/usr/bin/docker exec database redis-cli -n 0 FLUSHDB
/usr/bin/docker exec database redis-cli -n 1 FLUSHDB
/usr/bin/docker exec database redis-cli -n 2 FLUSHDB
/usr/bin/docker exec database redis-cli -n 5 FLUSHDB
clean_up_tables 6 "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'LAG_TABLE*', 'LAG_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*', 'FDB_TABLE*'"
fi

# start service docker
Expand Down Expand Up @@ -164,7 +166,7 @@ stop() {
# encountered error, e.g. syncd crashed. And swss needs to
# be restarted.
debug "Clearing FAST_REBOOT flag..."
clean_up_tables STATE_DB "'FAST_REBOOT*'"
clean_up_tables 6 "'FAST_REBOOT*'"

# Unlock has to happen before reaching out to peer service
unlock_service_state_change
Expand Down
12 changes: 7 additions & 5 deletions files/scripts/syncd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function unlock_service_state_change()

function check_warm_boot()
{
SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable`
SERVICE_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable`
SYSTEM_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable`
SERVICE_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable`
# SYSTEM_WARM_START could be empty, always make WARM_BOOT meaningful.
if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then
WARM_BOOT="true"
Expand All @@ -43,10 +43,12 @@ function check_warm_boot()
function wait_for_database_service()
{
# Wait for redis server start before database clean
/usr/bin/docker exec database ping_pong_db_insts
until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]];
do sleep 1;
done

# Wait for configDB initialization
until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];
until [[ $(/usr/bin/docker exec database redis-cli -n 4 GET "CONFIG_DB_INITIALIZED") ]];
do sleep 1;
done
}
Expand All @@ -63,7 +65,7 @@ function getBootType()
;;
*SONIC_BOOT_TYPE=fast*|*fast-reboot*)
# check that the key exists
if [[ $(sonic-db-cli STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then
if [[ $(redis-cli -n 6 GET "FAST_REBOOT|system") == "1" ]]; then
TYPE='fast'
else
TYPE='cold'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function _docker_swss_check {
while true
do
# Check if syncd starts
result=`sonic-db-cli ASIC_DB HLEN HIDDEN`
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function _docker_swss_check {
while true
do
# Check if syncd starts
result=`sonic-db-cli ASIC_DB HLEN HIDDEN`
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function _docker_swss_check {
while true
do
# Check if syncd starts
result=`sonic-db-cli ASIC_DB HLEN HIDDEN`
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function _docker_swss_check {
while true
do
# Check if syncd starts
result=`sonic-db-cli ASIC_DB HLEN HIDDEN`
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function _docker_swss_check {
while true
do
# Check if syncd starts
result=`sonic-db-cli ASIC_DB HLEN HIDDEN`
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function _docker_swss_check {
while true
do
# Check if syncd starts
result=`sonic-db-cli ASIC_DB HLEN HIDDEN`
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function _docker_swss_check {
while true
do
# Check if syncd starts
result=`sonic-db-cli ASIC_DB HLEN HIDDEN`
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function _docker_swss_check {
while true
do
# Check if syncd starts
result=`sonic-db-cli ASIC_DB HLEN HIDDEN`
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function _docker_swss_check {
while true
do
# Check if syncd starts
result=`sonic-db-cli ASIC_DB HLEN HIDDEN`
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
Expand Down

0 comments on commit 483a594

Please sign in to comment.