Check if it's leader before calling leader_set()

There may be situations where leader-elected hook is executed without
being the leader and making leader_set() calls fail, this patch verifies
if it's the leader before attempting to use leader_set()

Change-Id: Ia435069f5df80bfdf0236d14664317990bd06407
Closes-Bug: 1784584
This commit is contained in:
Felipe Reyes 2018-08-01 12:42:05 -04:00
parent e49f780083
commit 1219f7b2a2
1 changed files with 5 additions and 1 deletions

View File

@ -807,7 +807,11 @@ def leader_settings_changed():
@hooks.hook('leader-elected')
def leader_elected():
'''Set the leader nodes IP'''
leader_set(**{'leader-ip': get_relation_ip('cluster')})
if is_leader():
leader_set(**{'leader-ip': get_relation_ip('cluster')})
else:
log('leader-elected hook executed, but this unit is not the leader',
level=INFO)
@hooks.hook('nrpe-external-master-relation-joined',