Merge lp:~hloeung/ubuntu-repository-cache/i-really-am-the-leader into lp:~tribaal/ubuntu-repository-cache/trunk

Proposed by Haw Loeung
Status: Merged
Merged at revision: 245
Proposed branch: lp:~hloeung/ubuntu-repository-cache/i-really-am-the-leader
Merge into: lp:~tribaal/ubuntu-repository-cache/trunk
Diff against target: 14 lines (+4/-0)
1 file modified
hooks/hooks.py (+4/-0)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/i-really-am-the-leader
Reviewer Review Type Date Requested Status
Chris Glass Approve
Review via email: mp+334717@code.launchpad.net

Description of the change

Ensure unit is the leader

Per LP#1723184, if the unit was elected (thus causing leader-elected
hook to fire) but then another elected, leader-set fails and we end up
in a leader-elected hook loop. Let's ensure this unit is the leader.

To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

Looks good!

Will merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2017-04-04 12:12:06 +0000
+++ hooks/hooks.py 2017-12-04 23:42:37 +0000
@@ -233,6 +233,10 @@
233 We need to tell other units what the unit name for the leader is (the unit233 We need to tell other units what the unit name for the leader is (the unit
234 name of the currently-running hook).234 name of the currently-running hook).
235 """235 """
236 # Per LP#1723184, double check that we're the leader.
237 if not hookenv.is_leader():
238 LOG('leader-elected fired. This is not the leader')
239 return
236 LOG('leader-elected fired. This unit is the new leader: {}'.format(240 LOG('leader-elected fired. This unit is the new leader: {}'.format(
237 hookenv.local_unit()))241 hookenv.local_unit()))
238 hookenv.leader_set(leader_id=hookenv.local_unit())242 hookenv.leader_set(leader_id=hookenv.local_unit())

Subscribers

People subscribed via source and target branches

to all changes: