From 12e3a050b7dadcd526ac02e10ed093a7f5b4b88a Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Thu, 31 Aug 2017 17:28:04 -0400 Subject: [PATCH] Get the domain again before cleaning it up, catch errors Whoops, that last commit just wasn't very good. We need to re-open the libvirt connection and re-get the domain object, and also we should catch errors while destroying and undefining the domain... Signed-off-by: Adam Williamson --- createhdds.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/createhdds.py b/createhdds.py index 15603cd..91ba0f3 100755 --- a/createhdds.py +++ b/createhdds.py @@ -305,8 +305,18 @@ class VirtInstallImage(object): ret = subprocess.call(args, timeout=3600) except subprocess.TimeoutExpired: logger.warning("Image creation timed out!") - dom.destroy() - dom.undefine() + # clean up the domain again + conn = libvirt.open() + dom = conn.lookupByName('createhdds') + try: + dom.destroy() + except libvirt.libvirtError: + # maybe it died already + pass + try: + dom.undefine() + except libvirt.libvirtError: + pass conn.close() if os.path.isfile(tmpfile): os.remove(tmpfile)