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
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2017-04-04 12:12:06 +0000
3+++ hooks/hooks.py 2017-12-04 23:42:37 +0000
4@@ -233,6 +233,10 @@
5 We need to tell other units what the unit name for the leader is (the unit
6 name of the currently-running hook).
7 """
8+ # Per LP#1723184, double check that we're the leader.
9+ if not hookenv.is_leader():
10+ LOG('leader-elected fired. This is not the leader')
11+ return
12 LOG('leader-elected fired. This unit is the new leader: {}'.format(
13 hookenv.local_unit()))
14 hookenv.leader_set(leader_id=hookenv.local_unit())

Subscribers

People subscribed via source and target branches

to all changes: