Add retry logic for mount

This commit adds a retry logic for mount when it fails on the
first try on subclouds.

Test Plan:
[PASS] Installed in-service patch in DC env

Story: 2010676
Task: 49169
Change-Id: I5b1c959f966b7ac2622f315c1aac35d85d4b463c
Signed-off-by: Jessica Castelino <jessica.castelino@windriver.com>
This commit is contained in:
Jessica Castelino 2023-11-03 21:10:06 +00:00
parent 525416f9dd
commit 2702fbf565
2 changed files with 26 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import os
import sh
import shutil
import subprocess
import time
import gi
gi.require_version('OSTree', '1.0')
@ -257,12 +258,18 @@ def mount_new_deployment(deployment_dir):
new_etc_mount_dir = "%s/etc" % (deployment_dir)
sh.mount("--bind", "-o", "ro,noatime", new_usr_mount_dir, "/usr")
sh.mount("--bind", "-o", "rw,noatime", new_etc_mount_dir, "/etc")
except sh.ErrorReturnCode as e:
msg = "Failed to re-mount /usr and /etc."
info_msg = "OSTree Deployment Mount Error: Output: %s" \
% (e.stderr.decode("utf-8"))
LOG.info(info_msg)
raise OSTreeCommandFail(msg)
except sh.ErrorReturnCode:
LOG.warning("Mount failed. Retrying to mount /usr and /etc again after 5 secs.")
time.sleep(5)
try:
sh.mount("--bind", "-o", "ro,noatime", new_usr_mount_dir, "/usr")
sh.mount("--bind", "-o", "rw,noatime", new_etc_mount_dir, "/etc")
except sh.ErrorReturnCode as e:
msg = "Failed to re-mount /usr and /etc."
info_msg = "OSTree Deployment Mount Error: Output: %s" \
% (e.stderr.decode("utf-8"))
LOG.warning(info_msg)
raise OSTreeCommandFail(msg)
finally:
try:
sh.mount("/usr/local/kubernetes/current/stage1")

View File

@ -11,6 +11,7 @@ import os
import sh
import shutil
import subprocess
import time
from cgcs_patch import constants
from cgcs_patch.exceptions import OSTreeCommandFail
@ -299,12 +300,18 @@ def mount_new_deployment(deployment_dir):
new_etc_mount_dir = "%s/etc" % (deployment_dir)
sh.mount("--bind", "-o", "ro,noatime", new_usr_mount_dir, "/usr")
sh.mount("--bind", "-o", "rw,noatime", new_etc_mount_dir, "/etc")
except sh.ErrorReturnCode as e:
msg = "Failed to re-mount /usr and /etc."
info_msg = "OSTree Deployment Mount Error: Output: %s" \
% (e.stderr.decode("utf-8"))
LOG.info(info_msg)
raise OSTreeCommandFail(msg)
except sh.ErrorReturnCode:
LOG.warning("Mount failed. Retrying to mount /usr and /etc again after 5 secs.")
time.sleep(5)
try:
sh.mount("--bind", "-o", "ro,noatime", new_usr_mount_dir, "/usr")
sh.mount("--bind", "-o", "rw,noatime", new_etc_mount_dir, "/etc")
except sh.ErrorReturnCode as e:
msg = "Failed to re-mount /usr and /etc."
info_msg = "OSTree Deployment Mount Error: Output: %s" \
% (e.stderr.decode("utf-8"))
LOG.warning(info_msg)
raise OSTreeCommandFail(msg)
finally:
try:
sh.mount("/usr/local/kubernetes/current/stage1")