Skip to content

Commit

Permalink
Merge pull request #34 from mssonicbld/sonicbld/202305-merge
Browse files Browse the repository at this point in the history
[code sync] Merge code from sonic-net/sonic-utilities:202305 to 202305
  • Loading branch information
mssonicbld authored Nov 24, 2023
2 parents 5ed08f5 + 2b6b658 commit 6f6c704
Show file tree
Hide file tree
Showing 11 changed files with 1,318 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"helper_data": {
"rdma_config_update_validator": {
"mellanox_asics": {
"spc1": [ "ACS-MSN2700", "ACS-MSN2740", "ACS-MSN2100", "ACS-MSN2410", "ACS-MSN2010", "Mellanox-SN2700", "Mellanox-SN2700-D48C8" ],
"spc1": [ "ACS-MSN2700", "ACS-MSN2740", "ACS-MSN2100", "ACS-MSN2410", "ACS-MSN2010", "Mellanox-SN2700", "Mellanox-SN2700-D48C8",
"ACS-MSN2700-A1", "Mellanox-SN2700-A1", "Mellanox-SN2700-A1-C28D8", "Mellanox-SN2700-A1-D40C8S8", "Mellanox-SN2700-A1-D44C10", "Mellanox-SN2700-A1-D48C8" ],
"spc2": [ "ACS-MSN3800", "Mellanox-SN3800-D112C8" ],
"spc3": [ "ACS-MSN4700", "ACS-MSN4600", "ACS-MSN4600C", "ACS-MSN4410", "Mellanox-SN4600C-D112C8", "Mellanox-SN4600C-C64", "Mellanox-SN4700-O8C48" ],
"spc4": [ "ACS-SN5600"]
Expand Down
14 changes: 9 additions & 5 deletions generic_config_updater/services_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ def _service_restart(svc_name):


def rsyslog_validator(old_config, upd_config, keys):
rc = os.system("/usr/bin/rsyslog-config.sh")
if rc != 0:
return _service_restart("rsyslog")
else:
return True
old_syslog = old_config.get("SYSLOG_SERVER", {})
upd_syslog = upd_config.get("SYSLOG_SERVER", {})

if old_syslog != upd_syslog:
os.system("systemctl reset-failed rsyslog-config rsyslog")
rc = os.system("systemctl restart rsyslog-config")
if rc != 0:
return False
return True


def dhcp_validator(old_config, upd_config, keys):
Expand Down
23 changes: 9 additions & 14 deletions scripts/fast-reboot-filter-routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@
import utilities_common.cli as clicommon
import syslog
import traceback
import click
from swsscommon.swsscommon import ConfigDBConnector

ROUTE_IDX = 1

def get_connected_routes():
cmd = ['sudo', 'vtysh', '-c', "show ip route connected json"]
connected_routes = []
try:
output, ret = clicommon.run_command(cmd, return_cmd=True)
if ret != 0:
click.echo(output.rstrip('\n'))
sys.exit(ret)
if output is not None:
route_info = json.loads(output)
for route in route_info.keys():
connected_routes.append(route)
except Exception:
ctx = click.get_current_context()
ctx.fail("Unable to get connected routes from bgp")

output, ret = clicommon.run_command(cmd, return_cmd=True)
if ret != 0:
raise Exception("Failed to execute {}: {}".format(" ".join(cmd), output.rstrip('\n')))
if output is not None:
route_info = json.loads(output)
for route in route_info.keys():
connected_routes.append(route)

return connected_routes

def get_route(db, route):
Expand Down Expand Up @@ -81,6 +75,7 @@ def main():
syslog.syslog(syslog.LOG_NOTICE, "SIGINT received. Quitting")
res = 1
except Exception as e:
print(e)
syslog.syslog(syslog.LOG_ERR, "Got an exception %s: Traceback: %s" % (str(e), traceback.format_exc()))
res = 2
finally:
Expand Down
133 changes: 120 additions & 13 deletions scripts/generate_dump
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ SKIP_BCMCMD=0
SAVE_STDERR=true
RETURN_CODE=$EXT_SUCCESS
DEBUG_DUMP=false
ROUTE_TAB_LIMIT_DIRECT_ITERATION=24000

# lock dirs/files
LOCKDIR="/tmp/techsupport-lock"
Expand Down Expand Up @@ -863,24 +864,114 @@ save_redis() {
}

###############################################################################
# SAI DUMP from syncd
# GET ROUTE table size by ASIC id and ip version
# Globals:
# TIMEOUT_MIN
# TIMEOUT_EXIT_CODE
# Arguments:
# asic id
# IP version
# Returns:
# Status: 0 success, otherwise failure
###############################################################################
get_route_table_size_by_asic_id_and_ipver() {
local asic_id="$1"
local ip_ver="$2"
local filepath="/tmp/route_summary.txt"
local ns=""
RC=0

if [[ $NUM_ASICS -gt 1 ]] ; then
ns="-n ${asic_id}"
fi

if [ $ip_ver = "ipv4" ]; then
cmd="vtysh ${ns} -c 'show ip route summary json'"
elif [ $ip_ver = "ipv6" ]; then
cmd="vtysh ${ns} -c 'show ipv6 route summary json'"
else
echo "Wrong argument $ip_ver."
return 255
fi

local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local cmds="$cmd > '$filepath'"

eval "${timeout_cmd} bash -c \"${cmds}\"" || RC=$?

if [ $RC -eq $TIMEOUT_EXIT_CODE ]; then
echo "Command: $cmds timedout after ${TIMEOUT_MIN} minutes."
return $RC
elif [ $RC -ne 0 ]; then
echo "Command: $cmds failed with RC $RC"
return $RC
fi

local route_tab_size=$(python3 -c "\
import json
with open('$filepath') as json_file:
data = json.load(json_file)
print(data['routesTotal'])")
rm $filepath
echo "$route_tab_size"
}

###############################################################################
# SAI DUMP based on the route table size
# if the route table has more than ROUTE_TAB_LIMIT_DIRECT_ITERATION
# then dump by Redis Save command,
# otherwize, dump it by directly iteration the Redis
#
# Globals:
# NUM_ASICS
# ROUTE_TAB_LIMIT_DIRECT_ITERATION
# Arguments:
# None
# Returns:
# None
###############################################################################
save_saidump() {
save_saidump_by_route_size() {
trap 'handle_error $? $LINENO' ERR
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
save_cmd "docker exec syncd saidump" "saidump"
else
for (( i=0; i<$NUM_ASICS; i++ ))
do
save_cmd "docker exec syncd$i saidump" "saidump$i"
done
fi

for (( i=0; i<$NUM_ASICS; i++ ))
do
route_size_ipv4=`get_route_table_size_by_asic_id_and_ipver $i ipv4`
ret=$?

if [ $ret -ne 0 ]; then
echo "Get route table's size by asicid $i and ipv4 failed."
return $ret
fi

route_size_ipv6=`get_route_table_size_by_asic_id_and_ipver $i ipv6`
ret=$?

if [ $ret -ne 0 ]; then
echo "Get route table's size by asicid $i and ipv6 failed."
return $ret
fi

route_size=`expr $route_size_ipv4 + $route_size_ipv6`
echo "The route table's size is $route_size(ipv4 $route_size_ipv4, ipv6 $route_size_ipv6)"

if [[ $route_size -gt $ROUTE_TAB_LIMIT_DIRECT_ITERATION ]]; then
echo "Dump by using Redis SAVE."

if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
save_cmd "docker exec syncd saidump.sh" "saidump"
else
save_cmd "docker exec syncd$i saidump.sh" "saidump$i"
fi
else
echo "Dump by using direct iteration of Redis DB."

if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
save_cmd "docker exec syncd saidump" "saidump"
else
save_cmd "docker exec syncd$i saidump" "saidump$i"
fi
fi
done
}

###############################################################################
Expand Down Expand Up @@ -1579,6 +1670,22 @@ save_dump_state_all_ns() {
done
}

###############################################################################
# Save important files that are present in container storage for better debugging
# Files will be saved under dump/<container_name>/
# Types of Files Saved:
# 1) rsyslogd.conf
###############################################################################
save_container_files() {
trap 'handle_error $? $LINENO' ERR
local CONTAINER_FDUMP="container_dumps"
# Get the running container names
container_names=$(docker ps --format '{{.Names}}' --filter status=running)
for name in $container_names; do
$MKDIR $V -p $LOGDIR/$CONTAINER_FDUMP/$name
copy_from_docker $name "/etc/rsyslog.conf" $LOGDIR/$CONTAINER_FDUMP/$name/rsyslog.conf
done
}

###############################################################################
# Main generate_dump routine
Expand Down Expand Up @@ -1706,6 +1813,8 @@ main() {
wait
save_redis_info &

save_container_files &

if $DEBUG_DUMP
then
save_dump_state_all_ns &
Expand All @@ -1732,9 +1841,7 @@ main() {
save_cmd "ps -AwwL -o user,pid,lwp,ppid,nlwp,pcpu,pri,nice,vsize,rss,tty,stat,wchan:12,start,bsdtime,command" "ps.extended" &
wait

if [[ "$device_type" != "SpineRouter" ]]; then
save_saidump
fi
save_saidump_by_route_size

if [ "$asic" = "barefoot" ]; then
collect_barefoot
Expand Down
Loading

0 comments on commit 6f6c704

Please sign in to comment.