Skip to content

Commit 8746356

Browse files
committed
More changes
1 parent 39ee02b commit 8746356

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

scripts/reboot

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
3535
SUBTYPE=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype)
3636
ASAN=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asan)
3737
VERBOSE=no
38-
EXIT_SUCCESS=0
3938
EXIT_NEXT_IMAGE_NOT_EXISTS=4
4039
EXIT_SONIC_INSTALLER_VERIFY_REBOOT=21
4140
EXIT_PLATFORM_FW_AU_FAILURE=22
@@ -136,6 +135,8 @@ function show_help_and_exit()
136135
echo " "
137136
echo " Available options:"
138137
echo " -h, -? : getting this help"
138+
echo " -d : DPU module name on a smart switch, option is invalid when on DPU"
139+
echo " -p : Pre-shutdown steps on DPU, invalid on NPU"
139140

140141
exit ${EXIT_SUCCESS}
141142
}
@@ -198,7 +199,7 @@ function get_dpu_ip()
198199

199200
# Function to retrieve GNMI port from CONFIG_DB
200201
function get_gnmi_port() {
201-
port=$(sonic-db-cli CONFIG_DB HGET "GNMI|gnmi" "port")
202+
port=$(sonic-db-cli CONFIG_DB HGET "DPU_PORT|<TODO: PORT_NAME>" "gnmi")
202203
if [ $? -ne 0 ] || [ -z "$port" ]; then
203204
echo "Error: Failed to retrieve GNMI port"
204205
exit ${EXIT_ERROR}
@@ -293,7 +294,7 @@ function reboot_dpu_module()
293294

294295
function parse_options()
295296
{
296-
while getopts "h?vf" opt; do
297+
while getopts "h?vfpd" opt; do
297298
case ${opt} in
298299
h|\? )
299300
show_help_and_exit
@@ -348,6 +349,32 @@ function reboot_all_dpus() {
348349
wait
349350
}
350351

352+
# Function to handle scenarios on smart switch
353+
function handle_smart_switch() {
354+
# TODO: Check if this is DPU or not, proceed only if PRE-SHUTDOWN is set on DPU, else throw error
355+
356+
if [ -f "$PLATFORM_JSON_PATH" ]; then
357+
NUM_DPU=$(jq -r '.DPUS | length' "$PLATFORM_JSON_PATH" 2>/dev/null)
358+
if [ "$NUM_DPU" -gt 0 ]; then
359+
SMART_SWITCH="yes"
360+
fi
361+
fi
362+
363+
if [[ "$REBOOT_DPU" == "yes" ]]; then
364+
if [[ "$SMART_SWITCH" == "yes" ]]; then
365+
echo "User requested to reboot the device ${DPU_MODULE_NAME}"
366+
reboot_dpu_module "$DPU_MODULE_NAME"
367+
else
368+
echo "Invalid '-d' option specified for a non-smart switch"
369+
exit ${EXIT_ERROR}
370+
fi
371+
fi
372+
373+
if [[ "$SMART_SWITCH" == "yes" ]]; then
374+
reboot_all_dpus "$NUM_DPU"
375+
fi
376+
}
377+
351378
parse_options $@
352379

353380
# Exit if not superuser
@@ -358,19 +385,7 @@ fi
358385

359386
debug "User requested rebooting device ..."
360387

361-
if [ -f "$PLATFORM_JSON_PATH" ]; then
362-
NUM_DPU=$(jq -r '.DPUS | length' "$PLATFORM_JSON_PATH" 2>/dev/null)
363-
if [ "$NUM_DPU" -gt 0 ]; then
364-
SMART_SWITCH="yes"
365-
fi
366-
fi
367-
368-
if [[ "$REBOOT_DPU" == "yes" && "$SMART_SWITCH" == "yes" ]]; then
369-
echo "User requested to reboot the device ${DPU_MODULE_NAME}"
370-
reboot_dpu_module "$DPU_MODULE_NAME"
371-
elif [ "$SMART_SWITCH" == "yes" ]; then
372-
reboot_all_dpus "$NUM_DPU"
373-
fi
388+
handle_smart_switch
374389

375390
check_conflict_boot_in_fw_update
376391

0 commit comments

Comments
 (0)