Skip to content

Commit

Permalink
Wait till CHASIS_APP_DB PING is successful, host_name and asic_name a…
Browse files Browse the repository at this point in the history
…re valid in CONIFG_DB before starting chassis-db-cleanup (#17962)

This PR fixes the issue reported in Issu #17945
We noticed that chassis db clean up is skipped sometimes when the CHASSIS_APP_DB PING fails. Also if host_name and asic_name are not written to CONIG_DB, it could pass the empty strings to CHASSIS_APP_DB EVAL commands.
The service hostname-config.service is restarted whenever the config-reload or load-minigraph is done and this services renames the file /etc/hosts to updates it with the new file. This interferes with swss@.service and when swss.sh script CHASSIS_APP_DPP when the /etc/hosts file is renamed, the error "Unable to connect to redis: Cannot assign requested address" is seen and the CHASSIS_APP_DB EVAL command fails. This causes the chassis db entries not getting cleaned up and causes orchagent crash in remote LC's.

---------

Signed-off-by: saksarav <sakthivadivu.saravanaraj@nokia.com>
  • Loading branch information
saksarav-nokia authored and gechiang committed Apr 20, 2024
1 parent 88301b3 commit 4a48f20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 7 additions & 1 deletion files/image_config/hostname/hostname-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ fi
echo $HOSTNAME > /etc/hostname
hostname -F /etc/hostname

#Don't update the /etc/hosts if hostname is not changed
#This is to prevent intermittent redis_chassis.server reachability issue
if [ $CURRENT_HOSTNAME == $HOSTNAME ] ; then
exit 0
fi

# Remove the old hostname entry from hosts file.
# But, 'localhost' entry is used by multiple applications. Don't remove it altogether.
# Edit contents of /etc/hosts and put in /etc/hosts.new
if [ $CURRENT_HOSTNAME != "localhost" ] || [ $CURRENT_HOSTNAME == $HOSTNAME ] ; then
if [ $CURRENT_HOSTNAME != "localhost" ] ; then
sed "/\s$CURRENT_HOSTNAME$/d" /etc/hosts > /etc/hosts.new
else
cp -f /etc/hosts /etc/hosts.new
Expand Down
17 changes: 14 additions & 3 deletions files/scripts/swss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,23 @@ function clean_up_chassis_db_tables()
return
fi

if [[ !($($SONIC_DB_CLI CHASSIS_APP_DB PING | grep -c True) -gt 0) ]]; then
return
fi
until [[ $($SONIC_DB_CLI CHASSIS_APP_DB PING | grep -c True) -gt 0 ]]; do
sleep 1
done

lc=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'hostname'`
until [[ -n "${lc}" ]]; do
lc=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'hostname'`
sleep 1
done
debug "Chassis db clean up for ${SERVICE}$DEV. hostname=$lc"

asic=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'asic_name'`
until [[ -n "${asic}" ]]; do
asic=`$SONIC_DB_CLI CONFIG_DB hget 'DEVICE_METADATA|localhost' 'asic_name'`
sleep 1
done
debug "Chassis db clean up for ${SERVICE}$DEV. asic=$asic"

# First, delete SYSTEM_NEIGH entries
num_neigh=`$SONIC_DB_CLI CHASSIS_APP_DB EVAL "
Expand Down

0 comments on commit 4a48f20

Please sign in to comment.