@@ -223,15 +223,13 @@ def test_smartswitch_moduleupdater_status_transitions():
223223 module_updater = SmartSwitchModuleUpdater (SYSLOG_IDENTIFIER , chassis )
224224
225225 # Mock dependent methods
226- with patch .object (module_updater , 'retrieve_dpu_reboot_time' , return_value = "2024-11-19T00:00:00" ) \
227- as mock_retrieve_reboot_time , \
228- patch .object (module_updater , '_is_first_boot' , return_value = False ) as mock_is_first_boot , \
229- patch .object (module_updater , 'persist_dpu_reboot_cause' ) as mock_persist_reboot_cause , \
230- patch .object (module_updater , 'update_dpu_reboot_cause_to_db' ) as mock_update_reboot_db , \
231- patch ("os.makedirs" ) as mock_makedirs , \
232- patch ("builtins.open" , mock_open ()) as mock_file , \
233- patch .object (module_updater , '_get_history_path' ,
234- return_value = "/tmp/prev_reboot_time.txt" ) as mock_get_history_path :
226+ with patch .object (module_updater , 'retrieve_dpu_reboot_info' , return_value = ("Switch rebooted DPU" , "2023_01_01_00_00_00" )) as mock_reboot_info , \
227+ patch .object (module_updater , '_is_first_boot' , return_value = False ) as mock_is_first_boot , \
228+ patch .object (module_updater , 'persist_dpu_reboot_cause' ) as mock_persist_reboot_cause , \
229+ patch .object (module_updater , 'update_dpu_reboot_cause_to_db' ) as mock_update_reboot_db , \
230+ patch ("os.makedirs" ) as mock_makedirs , \
231+ patch ("builtins.open" , mock_open ()) as mock_file , \
232+ patch .object (module_updater , '_get_history_path' , return_value = "/tmp/prev_reboot_time.txt" ) as mock_get_history_path :
235233
236234 # Transition from ONLINE to OFFLINE
237235 offline_status = ModuleBase .MODULE_STATUS_OFFLINE
@@ -255,6 +253,59 @@ def test_smartswitch_moduleupdater_status_transitions():
255253 mock_persist_reboot_cause .assert_called_once ()
256254 mock_update_reboot_db .assert_called_once ()
257255
256+ def test_online_transition_skips_reboot_update ():
257+ chassis = MockSmartSwitchChassis ()
258+ index = 0
259+ name = "DPU0"
260+ module = MockModule (index , name , "DPU" , ModuleBase .MODULE_TYPE_DPU , 0 , "SN123" )
261+ module .set_oper_status (ModuleBase .MODULE_STATUS_OFFLINE )
262+ chassis .module_list .append (module )
263+
264+ updater = SmartSwitchModuleUpdater (SYSLOG_IDENTIFIER , chassis )
265+
266+ # Mock the module going ONLINE
267+ module .set_oper_status (ModuleBase .MODULE_STATUS_ONLINE )
268+
269+ with patch .object (updater , 'retrieve_dpu_reboot_info' ,
270+ return_value = ("Switch rebooted DPU" , datetime .now (timezone .utc ).strftime ("%Y_%m_%d_%H_%M_%S" ))), \
271+ patch .object (module , 'get_reboot_cause' , return_value = "Switch rebooted DPU" ), \
272+ patch .object (updater , '_is_first_boot' , return_value = False ), \
273+ patch .object (updater , 'persist_dpu_reboot_cause' ) as mock_persist , \
274+ patch .object (updater , 'update_dpu_reboot_cause_to_db' ) as mock_update , \
275+ patch ("builtins.open" , mock_open ()), \
276+ patch ("os.makedirs" ), \
277+ patch .object (updater , '_get_history_path' , return_value = "/tmp/fake.json" ):
278+
279+ updater .module_db_update ()
280+
281+ # Ensure no reboot update due to is_reboot = True
282+ mock_persist .assert_not_called ()
283+ mock_update .assert_not_called ()
284+
285+ def test_retrieve_dpu_reboot_info_success ():
286+ class DummyChassis :
287+ def get_num_modules (self ): return 0
288+ def init_midplane_switch (self ): return False
289+
290+ updater = SmartSwitchModuleUpdater (SYSLOG_IDENTIFIER , DummyChassis ())
291+ sample_json = {"cause" : "Switch rebooted DPU" , "name" : "2025_06_25_17_18_52" }
292+ with patch ("os.path.exists" , return_value = True ), \
293+ patch ("builtins.open" , mock_open (read_data = json .dumps (sample_json ))):
294+ cause , time_str = updater .retrieve_dpu_reboot_info ("dpu0" )
295+ assert cause == "Switch rebooted DPU"
296+ assert time_str == "2025_06_25_17_18_52"
297+
298+ def test_retrieve_dpu_reboot_info_file_missing ():
299+ class DummyChassis :
300+ def get_num_modules (self ): return 0
301+ def init_midplane_switch (self ): return False # required for SmartSwitchModuleUpdater
302+
303+ updater = SmartSwitchModuleUpdater (SYSLOG_IDENTIFIER , DummyChassis ())
304+ with patch ("os.path.exists" , return_value = False ):
305+ cause , time_str = updater .retrieve_dpu_reboot_info ("dpu0" )
306+ assert cause is None
307+ assert time_str is None
308+
258309def test_smartswitch_moduleupdater_check_invalid_name ():
259310 chassis = MockSmartSwitchChassis ()
260311 index = 0
0 commit comments