Check that node is in run state before primary

Fixes #37
This commit is contained in:
Joshua Boniface 2019-06-19 12:49:34 -04:00
parent 9a0554fdbe
commit bc38af774e
1 changed files with 10 additions and 0 deletions

View File

@ -100,6 +100,11 @@ def secondary_node(zk_conn, node):
if daemon_mode == 'hypervisor': if daemon_mode == 'hypervisor':
return False, 'ERROR: Cannot change router mode on non-coordinator node "{}"'.format(node) 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 # Get current state
current_state = zkhandler.readdata(zk_conn, '/nodes/{}/routerstate'.format(node)) current_state = zkhandler.readdata(zk_conn, '/nodes/{}/routerstate'.format(node))
if current_state == 'primary': if current_state == 'primary':
@ -122,6 +127,11 @@ def primary_node(zk_conn, node):
if daemon_mode == 'hypervisor': if daemon_mode == 'hypervisor':
return False, 'ERROR: Cannot change router mode on non-coordinator node "{}"'.format(node) 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 # Get current state
current_state = zkhandler.readdata(zk_conn, '/nodes/{}/routerstate'.format(node)) current_state = zkhandler.readdata(zk_conn, '/nodes/{}/routerstate'.format(node))
if current_state == 'secondary': if current_state == 'secondary':