Error handling for sw-patch host-install

This commit enables re-run of host-install if the first
attempt failed.

Test:
Pass: Error during ostree pull
Pass: Error during ostree deployment
Pass: Error during mount

Story: 2009969
Task: 46579
Signed-off-by: Jessica Castelino <jessica.castelino@windriver.com>
Change-Id: I9e0a565145ecbf34236cfe50cb5c5ee17afea8a8
This commit is contained in:
Jessica Castelino 2022-10-12 16:08:48 +00:00
parent b347b7660c
commit d289c721d3
1 changed files with 15 additions and 2 deletions

View File

@ -38,7 +38,9 @@ node_is_patched_rr_file = "/var/run/node_is_patched_rr"
patch_installing_file = "/var/run/patch_installing"
patch_failed_file = "/var/run/patch_install_failed"
node_is_locked_file = "/var/run/.node_locked"
ostree_pull_completed_deployment_pending_file = \
"/var/run/ostree_pull_completed_deployment_pending"
mount_pending_file = "/var/run/mount_pending"
insvc_patch_scripts = "/run/patching/patch-scripts"
insvc_patch_flags = "/run/patching/patch-flags"
insvc_patch_restart_agent = "/run/patching/.restart.patch-agent"
@ -440,17 +442,26 @@ class PatchAgent(PatchService):
changed = False
success = True
if self.changes:
if self.changes or \
os.path.exists(ostree_pull_completed_deployment_pending_file) or \
os.path.exists(mount_pending_file):
try:
# Pull changes from remote to the sysroot ostree
# The remote value is configured inside
# "/sysroot/ostree/repo/config" file
ostree_utils.pull_ostree_from_remote()
setflag(ostree_pull_completed_deployment_pending_file)
except OSTreeCommandFail:
LOG.exception("Failed to pull changes and create deployment"
"during host-install.")
success = False
try:
# Create a new deployment once the changes are pulled
ostree_utils.create_deployment()
changed = True
clearflag(ostree_pull_completed_deployment_pending_file)
except OSTreeCommandFail:
LOG.exception("Failed to pull changes and create deployment"
@ -475,7 +486,9 @@ class PatchAgent(PatchService):
try:
pending_deployment = ostree_utils.fetch_pending_deployment()
deployment_dir = constants.OSTREE_BASE_DEPLOYMENT_DIR + pending_deployment
setflag(mount_pending_file)
ostree_utils.mount_new_deployment(deployment_dir)
clearflag(mount_pending_file)
LOG.info("Running in-service patch-scripts")
subprocess.check_output(run_insvc_patch_scripts_cmd, stderr=subprocess.STDOUT)