Merge ~martin-hilton/charm-mongodb:001-fix-replica-set-relation-broken-hook into ~mongodb-charmers/charm-mongodb:master

Proposed by Martin Hilton
Status: Merged
Merged at revision: 9e0b579ca37befbcae8195be146f12c46dd74af9
Proposed branch: ~martin-hilton/charm-mongodb:001-fix-replica-set-relation-broken-hook
Merge into: ~mongodb-charmers/charm-mongodb:master
Diff against target: 29 lines (+11/-0)
1 file modified
hooks/hooks.py (+11/-0)
Reviewer Review Type Date Requested Status
Mario Splivalo (community) Disapprove
Tim Kuhlman (community) Approve
Review via email: mp+324259@code.launchpad.net

Description of the change

The stops the replica-set-relation-broken hook from erroring if the unit isn't in a replica set.

To post a comment you must log in.
Revision history for this message
Tim Kuhlman (timkuhlman) :
review: Approve
Revision history for this message
Mario Splivalo (mariosplivalo) wrote :

Hi, Martin.

Sorry to be late for the party, but this will still fail when removing multi-unit service/application.

I am creating a separate MP that will fix this.

review: Disapprove

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/hooks.py b/hooks/hooks.py
2index aa09ff5..eafce5a 100755
3--- a/hooks/hooks.py
4+++ b/hooks/hooks.py
5@@ -1166,6 +1166,12 @@ def replica_set_relation_joined():
6 juju_log("replica_set_relation_joined-finish")
7
8
9+def in_replica_set():
10+ c = Connection('localhost')
11+ r = run_admin_command(c, 'isMaster')
12+ return 'setName' in r
13+
14+
15 def am_i_primary():
16 c = Connection('localhost')
17 for i in xrange(10):
18@@ -1260,6 +1266,11 @@ def replica_set_relation_departed():
19 def replica_set_relation_broken():
20 juju_log('replica_set_relation_broken-start')
21
22+ if not in_replica_set():
23+ juju_log('not in replica set', level=DEBUG)
24+ juju_log('replica_set_relation_broken-finish')
25+ return
26+
27 if am_i_primary():
28 juju_log('I was primary - removing myself via new primary.', 'DEBUG')
29 mongo_client('localhost', 'rs.stepDown()')

Subscribers

People subscribed via source and target branches

to status/vote changes: