Skip to content

Commit 68a5dcf

Browse files
committed
ipu: Check if insert fails and retry
Signed-off-by: Salvatore Daniele <[email protected]>
1 parent c882766 commit 68a5dcf

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ipu.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def boot_iso_with_redfish(self, iso_path: str) -> None:
354354
logger.info("Checking if iso needs to be cleaned up")
355355
self.cleanup_iso_if_needed(iso_path)
356356
logger.info("inserting iso")
357-
self._insert_media(iso_path)
357+
self._insert_media_retry(iso_path)
358358
logger.info("setting boot source override")
359359
self._bootsource_override_cd()
360360
logger.info("triggering reboot")
@@ -376,6 +376,8 @@ def _wait_iso_downloaded(self, iso_path: str) -> None:
376376
rh.ssh_connect("root", password="", discover_auth=False)
377377
loop_count = 0
378378
while True:
379+
if not rh.is_connected():
380+
logger.error_and_exit(f"Connection to {rh.hostname} has been dropped, is download failed")
379381
result = rh.run("du -b /mnt/imc/acc-os.iso").out.split()
380382
if len(result) == 0:
381383
continue
@@ -402,6 +404,19 @@ def _insert_media(self, iso_path: str) -> None:
402404
logger.info("Waiting for the size of iso_path to be the same the IMC")
403405
self._wait_iso_downloaded(iso_path)
404406

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+
405420
def _bootsource_override_cd(self) -> None:
406421
url = f"https://{self.url}:8443/redfish/v1/Systems/1"
407422
data = {"Boot": {"BootSourceOverrideEnabled": "Once", "BootSourceOverrideTarget": "Cd"}}

0 commit comments

Comments
 (0)