Skip to content

Commit

Permalink
Fix for TSA error logging on multi-asic (#11519)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjchadaga authored and yxieca committed Aug 1, 2022
1 parent b1456ee commit f2d7481
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 39 deletions.
34 changes: 25 additions & 9 deletions dockers/docker-fpm-frr/base_image_files/TS
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`}

if [[ $1 == "TSA" ]]; then
if [[ $1 == "TSA" ]]; then
TSA_STATE_UPDATE='{"BGP_DEVICE_GLOBAL":{"STATE":{"tsa_enabled": "true"}}}'
log_msg='System Mode: Normal -> Maintenance'
err_msg='System is already in Maintenance'
desired_tsa_state=true
elif [[ $1 == "TSB" ]]; then
TSA_STATE_UPDATE='{"BGP_DEVICE_GLOBAL":{"STATE":{"tsa_enabled": "false"}}}'
log_msg='System Mode: Maintenance -> Normal'
err_msg='System is already in Normal mode'
desired_tsa_state=false
fi

# Parse the device specific asic conf file, if it exists
Expand All @@ -28,10 +32,16 @@ if [[ ($NUM_ASIC -gt 1) ]]; then
if [ $sub_role == 'FrontEnd' ]
then
echo -e "BGP"$asic" : \c"
if [[ -n "$TSA_STATE_UPDATE" ]]; then
sonic-cfggen -a "$TSA_STATE_UPDATE" -w -n $NAMESPACE_PREFIX$asic
logger -t $1 -p user.info "BGP$asic: $log_msg"
echo "$log_msg"
if [[ -n "$TSA_STATE_UPDATE" ]]; then
current_tsa_state="$(sonic-cfggen -d -v BGP_DEVICE_GLOBAL.STATE.tsa_enabled -n $NAMESPACE_PREFIX$asic)"
if [[ $current_tsa_state == $desired_tsa_state ]]; then
echo "$err_msg"
logger -t $1 -p user.info "$err_msg"
else
sonic-cfggen -a "$TSA_STATE_UPDATE" -w -n $NAMESPACE_PREFIX$asic
logger -t $1 -p user.info "$log_msg"
echo "$log_msg"
fi
else
# If TSC is executed, invoke FRR script to check installed route-maps
docker exec -i bgp$asic /usr/bin/$1
Expand All @@ -40,10 +50,16 @@ if [[ ($NUM_ASIC -gt 1) ]]; then
asic=$[$asic+1]
done
else
if [[ -n "$TSA_STATE_UPDATE" ]]; then
sonic-cfggen -a "$TSA_STATE_UPDATE" -w
logger -t $1 -p user.info "$log_msg"
echo "$log_msg"
if [[ -n "$TSA_STATE_UPDATE" ]]; then
current_tsa_state="$(sonic-cfggen -d -v BGP_DEVICE_GLOBAL.STATE.tsa_enabled)"
if [[ $current_tsa_state == $desired_tsa_state ]]; then
echo "$err_msg"
logger -t $1 -p user.info "$err_msg"
else
sonic-cfggen -a "$TSA_STATE_UPDATE" -w
logger -t $1 -p user.info "$log_msg"
echo "$log_msg"
fi
else
# If TSC is executed, invoke FRR script to check installed route-maps
docker exec -i bgp /usr/bin/$1
Expand Down
25 changes: 9 additions & 16 deletions dockers/docker-fpm-frr/base_image_files/TSA
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#!/bin/bash


if [[ "$(sonic-cfggen -d -v BGP_DEVICE_GLOBAL.STATE.tsa_enabled)" == "true" ]]; then
echo "System is already in Maintenance"
logger -t TSA -p user.info "System is already in Maintenance"
else
# toggle the mux to standby if dualtor and any mux active
if
[[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype | tr [:upper:] [:lower:])" == *"dualtor"* ]] &&
[[ $(show mux status | grep active | wc -l) > 0 ]];
then
logger -t TSA -p user.info "Toggle all mux mode to standby"
sudo config mux mode standby all
fi

/usr/bin/TS TSA
echo "Please execute 'config save' to preserve System mode in Maintenance after reboot or config reload"
# toggle the mux to standby if dualtor and any mux active
if
[[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype | tr [:upper:] [:lower:])" == *"dualtor"* ]] &&
[[ $(show mux status | grep active | wc -l) > 0 ]];
then
logger -t TSA -p user.info "Toggle all mux mode to standby"
sudo config mux mode standby all
fi

/usr/bin/TS TSA
echo "Please execute 'config save' to preserve System mode in Maintenance after reboot or config reload"
20 changes: 7 additions & 13 deletions dockers/docker-fpm-frr/base_image_files/TSB
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#!/bin/bash

if [[ "$(sonic-cfggen -d -v BGP_DEVICE_GLOBAL.STATE.tsa_enabled)" == "false" ]]; then
echo "System is already in Normal mode"
logger -t TSB -p user.info "System is already in Normal mode"
else
# toggle the mux to auto if dualtor
if [[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype | tr [:upper:] [:lower:])" == *"dualtor"* ]];
then
logger -t TSB -p user.info "Toggle all mux mode to auto"
sudo config mux mode auto all
fi

/usr/bin/TS TSB
echo "Please execute 'config save' to preserve System mode in Normal state after reboot or config reload"
# toggle the mux to auto if dualtor
if [[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype | tr [:upper:] [:lower:])" == *"dualtor"* ]];
then
logger -t TSB -p user.info "Toggle all mux mode to auto"
sudo config mux mode auto all
fi

/usr/bin/TS TSB
echo "Please execute 'config save' to preserve System mode in Normal state after reboot or config reload"
8 changes: 7 additions & 1 deletion src/sonic-bgpcfgd/tests/test_device_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
from .util import load_constants
import bgpcfgd.managers_device_global
from swsscommon import swsscommon
from copy import deepcopy

TEMPLATE_PATH = os.path.abspath('../../dockers/docker-fpm-frr/frr')
BASE_PATH = os.path.abspath('../sonic-bgpcfgd/tests/data/general/peer-group.conf/')
global_constants = {
"bgp": {
"traffic_shift_community" :"12345:12345"
}
}

def constructor():
cfg_mgr = MagicMock()
Expand All @@ -32,7 +38,7 @@ def get_config():
cfg_mgr.push = push
cfg_mgr.get_config = get_config

constants = load_constants()['constants']
constants = deepcopy(global_constants)
common_objs = {
'directory': Directory(),
'cfg_mgr': cfg_mgr,
Expand Down

0 comments on commit f2d7481

Please sign in to comment.