From 3e937362cd457669b5585c4ab4c35a3d82ba843b Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 30 Sep 2018 13:34:31 -0400 Subject: [PATCH] Finagle how startup happens --- router-daemon/pvcrd/RouterInstance.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/router-daemon/pvcrd/RouterInstance.py b/router-daemon/pvcrd/RouterInstance.py index f1eedc74..83b00734 100644 --- a/router-daemon/pvcrd/RouterInstance.py +++ b/router-daemon/pvcrd/RouterInstance.py @@ -49,6 +49,7 @@ class RouterInstance(): self.s_network = s_network self.network_list = [] self.ipmi_hostname = self.config['ipmi_hostname'] + self.active = False # Zookeeper handlers for changed states @zk_conn.DataWatch('/routers/{}/daemonstate'.format(self.name)) @@ -65,14 +66,6 @@ class RouterInstance(): except AttributeError: self.network_state = 'secondary' - # toggle state management of this router - if s_network != {}: # If there's no network list, we're too early in startup - if self.name == self.this_router: - if self.network_state == 'secondary': - self.become_secondary() - if self.network_state == 'primary': - self.become_primary() - # Get value functions def getname(self): return self.name @@ -96,6 +89,7 @@ class RouterInstance(): self.network_list.append(s_network[network].getvni()) def become_secondary(self): + self.active = True ansiiprint.echo('Setting router {} to secondary state'.format(self.name), '', 'i') ansiiprint.echo('Network list: {}'.format(', '.join(self.network_list)), '', 'c') for router in self.t_router: @@ -115,6 +109,7 @@ class RouterInstance(): time.sleep(1) def become_primary(self): + self.active = True ansiiprint.echo('Setting router {} to primary state.'.format(self.name), '', 'i') ansiiprint.echo('Network list: {}'.format(', '.join(self.network_list)), '', 'c') for network in self.s_network: @@ -212,6 +207,14 @@ class RouterInstance(): except ValueError: pass + # toggle state management of this router + if s_network != {} and not self.active: # If there's no network list, we're too early in startup + if self.name == self.this_router: + if self.network_state == 'secondary': + self.become_secondary() + if self.network_state == 'primary': + self.become_primary() + # Try to set ourself primary if there is no primary in the cluster cluster_has_primary = False for router in self.t_router: