Skip to content
Snippets Groups Projects
Commit e1233fb2 authored by Anael Beutot's avatar Anael Beutot
Browse files

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.
parent f9408b11
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment