Merge "Add lvm snapshot removal to the deploy delete request"

This commit is contained in:
Zuul 2025-04-16 19:16:23 +00:00 committed by Gerrit Code Review
commit 1ce3602b4e
2 changed files with 38 additions and 32 deletions

View File

@ -286,25 +286,25 @@ def pull_ostree_from_remote(remote=None):
ref_cmd = "ostree refs --force --create=%s %s" % (ref, constants.OSTREE_REF)
try:
output = subprocess.run(cmd % ref, shell=True, check=True, capture_output=True)
process = subprocess.run(cmd % ref, shell=True, check=True, text=True, capture_output=True)
except subprocess.CalledProcessError as e:
msg = "Failed to pull from %s remote into sysroot ostree" % ref
err_msg = "OSTree Pull Error: return code: %s, Output: %s" \
% (e.returncode, e.stderr.decode("utf-8"))
% (e.returncode, e.stderr.strip())
LOG.exception(err_msg)
raise OSTreeCommandFail(msg)
# Log to help identify errors
msg = "Remote pull output: %s" % output
msg = "Remote pull output: %s" % process.stdout.strip()
LOG.info(msg)
if ref_cmd:
try:
subprocess.run(ref_cmd, shell=True, check=True, capture_output=True)
subprocess.run(ref_cmd, shell=True, check=True, text=True, capture_output=True)
except subprocess.CalledProcessError as e:
msg = "Failed to create ref %s for remote %s" % (ref, remote)
err_msg = "OSTree Ref Error: return code: %s, Output: %s" \
% (e.returncode, e.stderr.decode("utf-8"))
% (e.returncode, e.stderr.strip())
LOG.exception(err_msg)
raise OSTreeCommandFail(msg)

View File

@ -16,10 +16,11 @@ import sys
import time
import software.ostree_utils as ostree_utils
from software.lvm_snapshot import LVMSnapshotManager
from software.software_functions import configure_logging
from software.software_functions import execute_agent_hooks
from software.software_functions import remove_major_release_deployment_flags
from software.software_functions import LOG
from software.software_functions import remove_major_release_deployment_flags
import software.config as cfg
from software.base import PatchService
from software.exceptions import OSTreeCommandFail
@ -362,38 +363,43 @@ class SoftwareMessageDeployDeleteCleanupReq(messages.PatchMessage):
def handle(self, sock, addr):
LOG.info("Handling deploy delete cleanup request, major_release=%s" % self.major_release)
success_cleanup = ostree_utils.delete_temporary_refs_and_remotes()
# remove temporary remote and ref created during the upgrade process
success_ostree_remote_cleanup = ostree_utils.delete_temporary_refs_and_remotes()
# update the default remote 'debian' to point to the to-release feed
nodetype = utils.get_platform_conf("nodetype")
success_update = ostree_utils.add_ostree_remote(self.major_release, nodetype,
replace_default_remote=True)
success_flags = remove_major_release_deployment_flags()
success_undeploy = ostree_utils.undeploy_inactive_deployments()
success_ostree_remote_update = ostree_utils.add_ostree_remote(
self.major_release, nodetype, replace_default_remote=True)
if success_cleanup:
LOG.info("Success cleaning temporary refs/remotes.")
else:
LOG.error("Failure cleaning temporary refs/remotes. "
"Please do the cleanup manually.")
# remove the local upgrade flags created for the upgrade process
success_remove_upgrade_flags = remove_major_release_deployment_flags()
if success_update:
LOG.info("Success updating default remote.")
else:
LOG.error("Failure updating default remote. "
"Please update '%s' remote manually." % constants.OSTREE_REMOTE)
# undeploy the from-release ostree deployment to free sysroot disk space
success_ostree_undeploy_from_release = ostree_utils.undeploy_inactive_deployments()
if success_flags:
LOG.info("Success removing local major release deployment flags.")
else:
LOG.error("Failure removing major release deployment flags. "
"Please remove them manually.")
# remove the lvm snapshots created during the upgrade process
success_remove_lvm_snapshots = True
try:
lsm = LVMSnapshotManager()
lsm.delete_snapshots()
except Exception:
success_remove_lvm_snapshots = False
if success_undeploy:
LOG.info("Success undeploying from-release deployment.")
else:
LOG.error("Failure undeploying from-release deployment. "
"Please remove it manually using 'ostree admin undeploy' command.")
cleanup_results = [
(success_ostree_remote_cleanup, "cleaning temporary refs/remotes"),
(success_ostree_remote_update, "updating default remote"),
(success_remove_upgrade_flags, "removing local upgrade flags"),
(success_ostree_undeploy_from_release, "undeploying from-release ostree deployment"),
(success_remove_lvm_snapshots, "removing LVM snapshots"),
]
for result, log_msg in cleanup_results:
if result not in [None, False]:
LOG.info("Success %s" % log_msg)
else:
LOG.error("Failure %s, manual cleanup is required" % log_msg)
success = all(x not in [None, False] for x, _ in cleanup_results)
success = success_cleanup and success_update
resp = SoftwareMessageDeployDeleteCleanupResp()
resp.success = success
resp.send(sock, addr)