From f0fd3d3f0ee336522cec9a1cc91dc2a698d71446 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 2 Jul 2021 11:34:19 -0400 Subject: [PATCH] Make extra sure VMs terminate when told When doing a stop_vm or terminate_vm, check again after 0.2 seconds and try re-terminating if it's still running. Covers cases where a VM doesn't stop if given the 'stop' state. --- node-daemon/pvcnoded/VMInstance.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/node-daemon/pvcnoded/VMInstance.py b/node-daemon/pvcnoded/VMInstance.py index e9758e5c..11b8e907 100644 --- a/node-daemon/pvcnoded/VMInstance.py +++ b/node-daemon/pvcnoded/VMInstance.py @@ -335,6 +335,13 @@ class VMInstance(object): self.instop = True try: self.dom.destroy() + time.sleep(0.2) + try: + if self.getdom().state()[0] == libvirt.VIR_DOMAIN_RUNNING: + # It didn't terminate, try again + self.dom.destroy() + except libvirt.libvirtError: + pass except AttributeError: self.logger.out('Failed to terminate VM', state='e', prefix='Domain {}'.format(self.domuuid)) self.removeDomainFromList() @@ -351,6 +358,13 @@ class VMInstance(object): self.instop = True try: self.dom.destroy() + time.sleep(0.2) + try: + if self.getdom().state()[0] == libvirt.VIR_DOMAIN_RUNNING: + # It didn't terminate, try again + self.dom.destroy() + except libvirt.libvirtError: + pass except AttributeError: self.logger.out('Failed to stop VM', state='e', prefix='Domain {}'.format(self.domuuid)) self.removeDomainFromList()