From bc38af774e8cbd1c4033777c349a5fb832956473 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 19 Jun 2019 12:49:34 -0400 Subject: [PATCH] Check that node is in run state before primary Fixes #37 --- client-common/node.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/client-common/node.py b/client-common/node.py index f37fb1e8..1f3a7a5c 100644 --- a/client-common/node.py +++ b/client-common/node.py @@ -100,6 +100,11 @@ def secondary_node(zk_conn, node): if daemon_mode == 'hypervisor': return False, 'ERROR: Cannot change router mode on non-coordinator node "{}"'.format(node) + # Ensure node is in run daemonstate + daemon_state = zkhandler.readdata(zk_conn, '/nodes/{}/daemonstate'.format(node)) + if daemon_mode != 'run': + return False, 'ERROR: Node "{}" is not active'.format(node) + # Get current state current_state = zkhandler.readdata(zk_conn, '/nodes/{}/routerstate'.format(node)) if current_state == 'primary': @@ -122,6 +127,11 @@ def primary_node(zk_conn, node): if daemon_mode == 'hypervisor': return False, 'ERROR: Cannot change router mode on non-coordinator node "{}"'.format(node) + # Ensure node is in run daemonstate + daemon_state = zkhandler.readdata(zk_conn, '/nodes/{}/daemonstate'.format(node)) + if daemon_mode != 'run': + return False, 'ERROR: Node "{}" is not active'.format(node) + # Get current state current_state = zkhandler.readdata(zk_conn, '/nodes/{}/routerstate'.format(node)) if current_state == 'secondary':