From 1e4350ca6fe54aa7227f37ef06d99d6524ab5e16 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 2 Mar 2020 10:41:00 -0500 Subject: [PATCH] Properly handle takeover state in VXNetworks Most of these actions/conditionals were looking for primary state, but were failing during node takeover. Update the conditionals to look for both router states instead. Also add a wait to lock flushing until a takeover is completed. --- node-daemon/pvcnoded/VMInstance.py | 3 +++ node-daemon/pvcnoded/VXNetworkInstance.py | 24 +++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/node-daemon/pvcnoded/VMInstance.py b/node-daemon/pvcnoded/VMInstance.py index 56f2c97a..b9a48462 100644 --- a/node-daemon/pvcnoded/VMInstance.py +++ b/node-daemon/pvcnoded/VMInstance.py @@ -74,6 +74,9 @@ def run_command(zk_conn, logger, this_node, data): # Flushing VM RBD locks if command == 'flush_locks': dom_uuid = args + # If this node is taking over primary state, wait until it's done + while this_node.router_state == 'takeover': + time.sleep(1) if this_node.router_state == 'primary': # Lock the command queue zk_lock = zkhandler.writelock(zk_conn, '/cmd/domains') diff --git a/node-daemon/pvcnoded/VXNetworkInstance.py b/node-daemon/pvcnoded/VXNetworkInstance.py index a666ca3b..62a5e29f 100644 --- a/node-daemon/pvcnoded/VXNetworkInstance.py +++ b/node-daemon/pvcnoded/VXNetworkInstance.py @@ -235,11 +235,11 @@ add rule inet filter forward ip6 saddr {netaddr6} counter jump {vxlannic}-out if data and self.ip6_gateway != data.decode('ascii'): orig_gateway = self.ip6_gateway - if self.this_node.router_state == 'primary': + if self.this_node.router_state in ['primary', 'takeover']: if orig_gateway: self.removeGateway6Address() self.ip6_gateway = data.decode('ascii') - if self.this_node.router_state == 'primary': + if self.this_node.router_state in ['primary', 'takeover']: self.createGateway6Address() if self.dhcp_server_daemon: self.stopDHCPServer() @@ -257,9 +257,9 @@ add rule inet filter forward ip6 saddr {netaddr6} counter jump {vxlannic}-out if data and self.dhcp6_flag != ( data.decode('ascii') == 'True' ): self.dhcp6_flag = ( data.decode('ascii') == 'True' ) - if self.dhcp6_flag and not self.dhcp_server_daemon and self.this_node.router_state == 'primary': + if self.dhcp6_flag and not self.dhcp_server_daemon and self.this_node.router_state in ['primary', 'takeover']: self.startDHCPServer() - elif self.dhcp_server_daemon and not self.dhcp4_flag and self.this_node.router_state == 'primary': + elif self.dhcp_server_daemon and not self.dhcp4_flag and self.this_node.router_state in ['primary', 'takeover']: self.stopDHCPServer() @self.zk_conn.DataWatch('/networks/{}/ip4_network'.format(self.vni)) @@ -286,11 +286,11 @@ add rule inet filter forward ip6 saddr {netaddr6} counter jump {vxlannic}-out if data and self.ip4_gateway != data.decode('ascii'): orig_gateway = self.ip4_gateway - if self.this_node.router_state == 'primary': + if self.this_node.router_state in ['primary', 'takeover']: if orig_gateway: self.removeGateway4Address() self.ip4_gateway = data.decode('ascii') - if self.this_node.router_state == 'primary': + if self.this_node.router_state in ['primary', 'takeover']: self.createGateway4Address() if self.dhcp_server_daemon: self.stopDHCPServer() @@ -308,9 +308,9 @@ add rule inet filter forward ip6 saddr {netaddr6} counter jump {vxlannic}-out if data and self.dhcp4_flag != ( data.decode('ascii') == 'True' ): self.dhcp4_flag = ( data.decode('ascii') == 'True' ) - if self.dhcp4_flag and not self.dhcp_server_daemon and self.this_node.router_state == 'primary': + if self.dhcp4_flag and not self.dhcp_server_daemon and self.this_node.router_state in ['primary', 'takeover']: self.startDHCPServer() - elif self.dhcp_server_daemon and not self.dhcp6_flag and self.this_node.router_state == 'primary': + elif self.dhcp_server_daemon and not self.dhcp6_flag and self.this_node.router_state in ['primary', 'takeover']: self.stopDHCPServer() @self.zk_conn.DataWatch('/networks/{}/dhcp4_start'.format(self.vni)) @@ -349,7 +349,7 @@ add rule inet filter forward ip6 saddr {netaddr6} counter jump {vxlannic}-out if self.dhcp_reservations != new_reservations: old_reservations = self.dhcp_reservations self.dhcp_reservations = new_reservations - if self.this_node.router_state == 'primary': + if self.this_node.router_state in ['primary', 'takeover']: self.updateDHCPReservations(old_reservations, new_reservations) if self.dhcp_server_daemon: self.stopDHCPServer() @@ -601,7 +601,7 @@ add rule inet filter forward ip6 saddr {netaddr6} counter jump {vxlannic}-out self.createGateway4Address() def createGateway6Address(self): - if self.this_node.router_state == 'primary': + if self.this_node.router_state in ['primary', 'takeover']: self.logger.out( 'Creating gateway {}/{} on interface {}'.format( self.ip6_gateway, @@ -614,7 +614,7 @@ add rule inet filter forward ip6 saddr {netaddr6} counter jump {vxlannic}-out common.createIPAddress(self.ip6_gateway, self.ip6_cidrnetmask, self.bridge_nic) def createGateway4Address(self): - if self.this_node.router_state == 'primary': + if self.this_node.router_state in ['primary', 'takeover']: self.logger.out( 'Creating gateway {}/{} on interface {}'.format( self.ip4_gateway, @@ -627,7 +627,7 @@ add rule inet filter forward ip6 saddr {netaddr6} counter jump {vxlannic}-out common.createIPAddress(self.ip4_gateway, self.ip4_cidrnetmask, self.bridge_nic) def startDHCPServer(self): - if self.this_node.router_state == 'primary' and self.nettype == 'managed': + if self.this_node.router_state in ['primary', 'takeover'] and self.nettype == 'managed': self.logger.out( 'Starting dnsmasq DHCP server on interface {}'.format( self.bridge_nic