Skip to content

Commit 138d5fb

Browse files
committed
More changes
1 parent 10ed4da commit 138d5fb

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
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

scripts/reboot_helper.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
chk_log_level = syslog.LOG_ERR
1212

13+
1314
def _log_msg(lvl, pfx, msg):
1415
if lvl <= chk_log_level:
1516
print("{}: {}".format(pfx, msg))
@@ -31,6 +32,7 @@ def log_debug(m):
3132
# Global variable for platform chassis
3233
platform_chassis = None
3334

35+
3436
def load_platform_chassis():
3537
global platform_chassis
3638

@@ -47,6 +49,7 @@ def load_platform_chassis():
4749

4850
return True
4951

52+
5053
def reboot_module(module_name):
5154
"""Reboot the specified module by invoking the platform API"""
5255

@@ -68,23 +71,24 @@ def reboot_module(module_name):
6871
log_info(f"Rebooting module {module_name}...")
6972
try:
7073
module.reboot()
71-
log_info(f"Reboot command sent for module {module_name}")
74+
log_info("Reboot command sent for module {module_name}")
7275
return True
7376
except NotImplementedError:
74-
log_error(f"Reboot not implemented for module {module_name}.")
77+
log_err("Reboot not implemented for module {module_name}.")
7578
return False
7679
except Exception as e:
77-
log_error(f"An error occurred while rebooting module {module_name}: {e}")
80+
log_err("An error occurred while rebooting module {module_name}: {e}")
7881
return False
7982

8083
# If the module with the given name is not found
81-
log_err(f"Module {module_name} not found")
84+
log_err("Module {module_name} not found")
8285
return False
8386

8487
except Exception as e:
85-
log_err(f"Error occurred while rebooting module {module_name}: {repr(e)}")
88+
log_err("Error occurred while rebooting module {module_name}: {repr(e)}")
8689
return False
8790

91+
8892
if __name__ == "__main__":
8993
if len(sys.argv) < 3:
9094
print("Usage: reboot_helper.py <command> <module_name>")
@@ -98,7 +102,7 @@ def reboot_module(module_name):
98102
if not success:
99103
sys.exit(1)
100104
else:
101-
print(f"Reboot command sent for module {module_name}")
105+
print("Reboot command sent for module {module_name}")
102106
else:
103-
print(f"Unknown command: {command}")
107+
print("Unknown command: {command}")
104108
sys.exit(1)

0 commit comments

Comments
 (0)