[elbe-devel] [PATCH] elbepack: initvmaction: make destroy subcommand more robust

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Jul 17 12:36:03 CEST 2024


In case of an already partially destroyed initvm an error would prevent
the complete cleanup.
Therefor ignore errors during each substep of the destruction.

Also pass VIR_DOMAIN_UNDEFINE_MANAGED_SAVE to automatically clean
managed saves and avoid errors in case those exist.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/initvmaction.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index 51a618cee431..a2ad7e112e8c 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -3,6 +3,7 @@
 # SPDX-FileCopyrightText: 2015-2018 Linutronix GmbH
 # SPDX-FileCopyrightText: 2015 Silvio Fricke <silvio.fricke at gmail.com>
 
+import contextlib
 import datetime
 import io
 import os
@@ -384,10 +385,14 @@ class DestroyAction(InitVMAction):
 
     def execute(self, initvmdir, opt, _args):
         if not opt.qemu_mode:
-            self.initvm.destroy()
-            self.initvm.undefine()
+            import libvirt
 
-        shutil.rmtree(initvmdir)
+            with contextlib.suppress(libvirt.libvirtError):
+                self.initvm.destroy()
+            with contextlib.suppress(libvirt.libvirtError):
+                self.initvm.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)
+
+        shutil.rmtree(initvmdir, ignore_errors=True)
 
 
 @InitVMAction.register('attach')

---
base-commit: 9efaeca07c8801ef8d4d88faf2b9031389ad4865
change-id: 20240717-destroy-6550c3d9ae03

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh at linutronix.de>



More information about the elbe-devel mailing list