From 5ad49d239ef9e20ad47b2c1ad4b95dd3c2a3f63e Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Mon, 11 Jun 2018 20:12:11 -0400 Subject: [PATCH] Add some tweaks to prevent clobbering state changes happening at startup and during each keepalive cycle --- NodeInstance.py | 8 ++++++-- VMInstance.py | 24 +++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index d2a5dc6b..5c7e621e 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -198,10 +198,12 @@ class NodeInstance(): else: self.daemon_state = 'start' - # Toggle state management of all VMs and remove any non-running VMs + # Toggle state management of dead VMs for domain, instance in self.s_domain.items(): if instance.inshutdown == False and domain in self.domain_list: - instance.manage_vm_state() + if instance.getstate() == 'start' and instance.gethypervisor() == self.name and instance.dom == None: + instance.manage_vm_state() + if instance.dom == None: try: self.domain_list.remove(domain) @@ -218,6 +220,8 @@ class NodeInstance(): self.domain_list.remove(domain) except: pass + else: + instance.setnoclobber() # toggle state management of this node if self.domain_state == 'flush': diff --git a/VMInstance.py b/VMInstance.py index 744067b5..9bc55d2a 100644 --- a/VMInstance.py +++ b/VMInstance.py @@ -40,17 +40,24 @@ class VMInstance: self.inmigrate = False self.inreceive = False - self.dom = self.lookupByUUID(self.domuuid) + # These stop a weird clobber at startup + self.noclobber = False - # Watch for changes to the hypervisor field in Zookeeper - @zk.DataWatch('/domains/{}/hypervisor'.format(self.domuuid)) - def watch_hypervisor(data, stat, event=""): - self.manage_vm_state() + self.dom = self.lookupByUUID(self.domuuid) # Watch for changes to the state field in Zookeeper @zk.DataWatch('/domains/{}/state'.format(self.domuuid)) def watch_state(data, stat, event=""): - self.manage_vm_state() + if self.noclobber == False: + self.noclobber = True + self.manage_vm_state() + + # Watch for changes to the hypervisor field in Zookeeper + @zk.DataWatch('/domains/{}/hypervisor'.format(self.domuuid)) + def watch_hypervisor(data, stat, event=""): + if self.noclobber == False: + self.noclobber = True + self.manage_vm_state() # Get data functions def getstate(self): @@ -59,6 +66,10 @@ class VMInstance: def gethypervisor(self): return self.hypervisor + # Allow the node to set the noclobber status once it performs its first keepalive + def setnoclobber(self): + self.noclobber = False + # Start up the VM def start_vm(self, xmlconfig): ansiiprint.echo('Starting VM', '{}:'.format(self.domuuid), 'i') @@ -286,7 +297,6 @@ class VMInstance: domxml = str(domxml.decode('ascii')) self.start_vm(domxml) - # This function is a wrapper for libvirt.lookupByUUID which fixes some problems # 1. Takes a text UUID and handles converting it to bytes # 2. Try's it and returns a sensible value if not