Add lvm snapshot removal to the deploy delete request

On deploy delete for a major release deployment, a message is
sent from the software-controller to all hosts, requesting them
to perform cleanup tasks related to the upgrade process.

This commit includes the step to clean up lvm snapshots, in case
the feature was used on the deploy start. There are no need for
special treatment to check if the system is AIO-SX or snapshots
were created since:
- If system is not AIO-SX, the feature will not be activated,
  so there won't be any snapshots
- If there aren't any snapshots, the snapshot delete function
  will just ignore it and return success

Test Plan (AIO-SX only):
PASS: run deploy delete with no lvm snapshots created, verify
      the process finishes successfully
PASS: run deploy delete with existing lvm snapshots, verify
      the process deletes them and finishes successfully

Story: 2011357
Task:

Change-Id: I7e71d33eed5be166afbf6658f6392608b9ffe8fe
Signed-off-by: Heitor Matsui <heitorvieira.matsui@windriver.com>
This commit is contained in:
Heitor Matsui
2025-04-09 17:09:10 -03:00
parent 51ad6c7cd2
commit f1ea56351f

View File

@@ -19,6 +19,7 @@ import software.ostree_utils as ostree_utils
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 LvmSnapshotManager
from software.software_functions import LOG
import software.config as cfg
from software.base import PatchService
@@ -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:
LOG.info("Success %s" % log_msg)
else:
LOG.error("Failure %s, manual cleanup is required" % log_msg)
success = all(x is True for x, _ in cleanup_results)
success = success_cleanup and success_update
resp = SoftwareMessageDeployDeleteCleanupResp()
resp.success = success
resp.send(sock, addr)