Avoid duplicating maintenance state change

This makes no functional difference, but is technically more correct.
This commit is contained in:
Joshua Boniface 2021-06-05 01:36:40 -04:00
parent 5d88e92acc
commit f0dc0fc782
1 changed files with 16 additions and 15 deletions

View File

@ -29,7 +29,13 @@ import daemon_lib.ceph as pvc_ceph
def set_maintenance(zkhandler, maint_state): def set_maintenance(zkhandler, maint_state):
try: current_maint_state = zkhandler.read('/config/maintenance')
if maint_state == current_maint_state:
if maint_state == 'true':
return True, 'Cluster is already in maintenance mode'
else:
return True, 'Cluster is already in normal mode'
if maint_state == 'true': if maint_state == 'true':
zkhandler.write([ zkhandler.write([
('/config/maintenance', 'true') ('/config/maintenance', 'true')
@ -40,16 +46,11 @@ def set_maintenance(zkhandler, maint_state):
('/config/maintenance', 'false') ('/config/maintenance', 'false')
]) ])
return True, 'Successfully set cluster in normal mode' return True, 'Successfully set cluster in normal mode'
except Exception:
return False, 'Failed to set cluster maintenance state'
def getClusterInformation(zkhandler): def getClusterInformation(zkhandler):
# Get cluster maintenance state # Get cluster maintenance state
try:
maint_state = zkhandler.read('/config/maintenance') maint_state = zkhandler.read('/config/maintenance')
except Exception:
maint_state = 'false'
# List of messages to display to the clients # List of messages to display to the clients
cluster_health_msg = [] cluster_health_msg = []