@@ -354,7 +354,7 @@ def boot_iso_with_redfish(self, iso_path: str) -> None:
354
354
logger .info ("Checking if iso needs to be cleaned up" )
355
355
self .cleanup_iso_if_needed (iso_path )
356
356
logger .info ("inserting iso" )
357
- self ._insert_media (iso_path )
357
+ self ._insert_media_retry (iso_path )
358
358
logger .info ("setting boot source override" )
359
359
self ._bootsource_override_cd ()
360
360
logger .info ("triggering reboot" )
@@ -376,6 +376,8 @@ def _wait_iso_downloaded(self, iso_path: str) -> None:
376
376
rh .ssh_connect ("root" , password = "" , discover_auth = False )
377
377
loop_count = 0
378
378
while True :
379
+ if not rh .is_connected ():
380
+ logger .error_and_exit (f"Connection to { rh .hostname } has been dropped, is download failed" )
379
381
result = rh .run ("du -b /mnt/imc/acc-os.iso" ).out .split ()
380
382
if len (result ) == 0 :
381
383
continue
@@ -402,6 +404,19 @@ def _insert_media(self, iso_path: str) -> None:
402
404
logger .info ("Waiting for the size of iso_path to be the same the IMC" )
403
405
self ._wait_iso_downloaded (iso_path )
404
406
407
+ def _insert_media_retry (self , iso_path :str , max_retries = 10 ) -> None :
408
+ retries = 0
409
+ while True :
410
+ try :
411
+ self ._insert_media (iso_path )
412
+ break
413
+ except Exception as e :
414
+ logger .info (f"Encountered exception { e } when inserting media, retrying... (attempt={ retries } )" )
415
+ retries += 1
416
+ if retries >= max_retries :
417
+ logger .error_and_exit ("Insert media failed" )
418
+ time .sleep (5 )
419
+
405
420
def _bootsource_override_cd (self ) -> None :
406
421
url = f"https://{ self .url } :8443/redfish/v1/Systems/1"
407
422
data = {"Boot" : {"BootSourceOverrideEnabled" : "Once" , "BootSourceOverrideTarget" : "Cd" }}
0 commit comments