From e1233fb2b7de15a566cf9c26818b641722c5db15 Mon Sep 17 00:00:00 2001 From: Anael Beutot <anael.beutot@smartjog.com> Date: Tue, 22 May 2012 17:59:25 +0200 Subject: [PATCH] Fixed libvirt bad exception when destroying a VM. Libvirt raises an exception saying "domain not runnning" when trying to destroy a VM that is in fact running. So we try to figure out if this is this kind of exception and we ignore it in this case. --- ccnode/hypervisor/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ccnode/hypervisor/__init__.py b/ccnode/hypervisor/__init__.py index da79406..52ad80c 100644 --- a/ccnode/hypervisor/__init__.py +++ b/ccnode/hypervisor/__init__.py @@ -200,9 +200,13 @@ class Handler(HostHandler): logger.debug('VM destroy %s', name) try: self.hypervisor.domains[name].destroy() - except libvirt.libvirtError: - logger.exception('Error while destroying VM %s', name) - raise + except libvirt.libvirtError as exc: + # Libvirt raises exception 'domain is not running' event is domain + # is running, might be a bug in libvirt + if 'domain is not running' not in str(exc) or ( + self.hypervisor.domains[name].state != 'running'): + logger.exception('Error while destroying VM %s', name) + raise except KeyError: msg = 'Cannot destroy VM %s because it is not defined' % name logger.error(msg) -- GitLab