From 109000c17c54fccdd4126bcc11253d306e4b7eb6 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 15 Nov 2024 12:00:31 -0500 Subject: [PATCH] Ensure snapshots are removed if none succeed Avoids having lingering automirror snapshots that will never be cleaned up. --- daemon-common/automirror.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/daemon-common/automirror.py b/daemon-common/automirror.py index 36533fdd..ad72343e 100644 --- a/daemon-common/automirror.py +++ b/daemon-common/automirror.py @@ -389,6 +389,7 @@ def worker_cluster_automirror( continue remote_marked_for_deletion = dict() + all_results = list() for destination in vm_destinations: mirror_start = datetime.now() result, ret = run_vm_mirror( @@ -401,6 +402,7 @@ def worker_cluster_automirror( ) mirror_end = datetime.now() runtime_secs = (mirror_end - mirror_start).seconds + all_results.append(result) if result: remote_marked_for_deletion[destination] = ret @@ -421,6 +423,15 @@ def worker_cluster_automirror( "result_message": ret, } + # If all sends failed, remove the snapshot we created as it will never be needed or automatically cleaned up later + if all(not b for b in all_results): + vm.vm_worker_remove_snapshot( + zkhandler, + None, + vm_detail["name"], + snapshot_name, + ) + # Find all local snapshots that were present in all remote snapshot deletions, # then remove them # If one of the sends fails, this should result in nothing being removed