@@ -199,7 +199,8 @@ function get_dpu_ip()
199199
200200# Function to retrieve GNMI port from CONFIG_DB
201201function get_gnmi_port() {
202- port=$( sonic-db-cli CONFIG_DB HGET " DPU_PORT|<TODO: PORT_NAME>" " gnmi" )
202+ local DPU_NAME=$1
203+ port=$( sonic-db-cli CONFIG_DB HGET " DPU_PORT|$DPU_NAME " " gnmi" )
203204 if [ $? -ne 0 ] || [ -z " $port " ]; then
204205 echo " Error: Failed to retrieve GNMI port"
205206 exit ${EXIT_ERROR}
@@ -250,7 +251,12 @@ function reboot_dpu_module()
250251
251252 # Retrieve DPU IP and GNMI port
252253 dpu_ip=$( get_dpu_ip " ${DPU_NAME} " )
253- port=$( get_gnmi_port)
254+ port=$( get_gnmi_port " ${DPU_NAME} " )
255+
256+ if [ -z " $dpu_ip " ] || [ -z " $port " ]; then
257+ echo " Error: Failed to retrieve DPU IP or GNMI port for ${DPU_NAME} "
258+ exit ${EXIT_ERROR}
259+ fi
254260
255261 # Issue GNOI client command to reboot the DPU
256262 gnoi_client -target ${dpu_ip} :${port} -logtostderr -insecure -rpc Reboot -jsonin ' {"method":3}'
@@ -261,6 +267,10 @@ function reboot_dpu_module()
261267
262268 # Retrieve dpu_halt_services_timeout value using jq
263269 dpu_halt_services_timeout=$( jq -r ' .dpu_halt_services_timeout' " $PLATFORM_JSON_PATH " 2> /dev/null)
270+ if [ $? -ne 0 ]; then
271+ echo " Error: Failed to retrieve dpu_halt_services_timeout from ${PLATFORM_JSON_PATH} "
272+ exit ${EXIT_ERROR}
273+ fi
264274
265275 # Poll on reboot status response with a timeout mechanism
266276 poll_interval=5
@@ -286,9 +296,11 @@ function reboot_dpu_module()
286296
287297 # Update STATE_DB and handle PCIe removal and rescan
288298 sonic-db-cli state_db set " PCIE_DETACH_INFO|${DPU_NAME} " ' {"dpu_id": "' ${DPU_INDEX} ' ", "dpu_state": "detaching", "bus_info": "' ${DPU_BUS_INFO} ' "}'
299+
289300 echo 1 > /sys/bus/pci/devices/${DPU_BUS_INFO} /remove
290301 reboot_platform_module " ${DPU_NAME} "
291302 echo 1 > /sys/bus/pci/rescan
303+
292304 sonic-db-cli state_db del " PCIE_DETACH_INFO|${DPU_NAME} "
293305}
294306
@@ -351,15 +363,19 @@ function reboot_all_dpus() {
351363
352364# Function to handle scenarios on smart switch
353365function 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-
356366 if [ -f " $PLATFORM_JSON_PATH " ]; then
357367 NUM_DPU=$( jq -r ' .DPUS | length' " $PLATFORM_JSON_PATH " 2> /dev/null)
358368 if [ " $NUM_DPU " -gt 0 ]; then
359369 SMART_SWITCH=" yes"
360370 fi
361371 fi
362372
373+ is_dpu=$( python3 -c " import reboot_helper; reboot_helper.is_dpu()" )
374+ if [[ " $is_dpu " == " True" ] && [ " $PRE_SHUTDOWN " != " yes" ]]; then
375+ echo " Invalid, '-p' option not specified for a DPU"
376+ exit ${EXIT_ERROR}
377+ fi
378+
363379 if [[ " $REBOOT_DPU " == " yes" ]]; then
364380 if [[ " $SMART_SWITCH " == " yes" ]]; then
365381 echo " User requested to reboot the device ${DPU_MODULE_NAME} "
0 commit comments