Merge lp:~thedac/charms/trusty/rabbitmq-server/backport-cluster-race-fixes into lp:charms/trusty/rabbitmq-server

Proposed by David Ames
Status: Merged
Merged at revision: 102
Proposed branch: lp:~thedac/charms/trusty/rabbitmq-server/backport-cluster-race-fixes
Merge into: lp:charms/trusty/rabbitmq-server
Diff against target: 107 lines (+36/-11)
2 files modified
hooks/rabbit_utils.py (+6/-1)
hooks/rabbitmq_server_relations.py (+30/-10)
To merge this branch: bzr merge lp:~thedac/charms/trusty/rabbitmq-server/backport-cluster-race-fixes
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+270712@code.launchpad.net

Description of the change

Backport cluster race conditions fix from next to the stable charm fixing LP Bug#1486177

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #8949 rabbitmq-server for thedac mp270712
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/8949/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #9718 rabbitmq-server for thedac mp270712
    LINT FAIL: lint-test failed
    LINT FAIL: charm-proof failed

LINT Results (max last 2 lines):
make: *** [lint] Error 100
ERROR:root:Make target returned non-zero.

Full lint test output: http://paste.ubuntu.com/12329593/
Build: http://10.245.162.77:8080/job/charm_lint_check/9718/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6348 rabbitmq-server for thedac mp270712
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/12329701/
Build: http://10.245.162.77:8080/job/charm_amulet_test/6348/

Revision history for this message
Liam Young (gnuoy) wrote :

Approve, (amulet fixes to follow).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/rabbit_utils.py'
2--- hooks/rabbit_utils.py 2015-08-10 16:38:33 +0000
3+++ hooks/rabbit_utils.py 2015-09-10 16:44:56 +0000
4@@ -299,7 +299,12 @@
5 cmd = [RABBITMQ_CTL, 'stop_app']
6 subprocess.check_call(cmd)
7 cmd = [RABBITMQ_CTL, cluster_cmd, 'rabbit@%s' % node]
8- subprocess.check_call(cmd)
9+ try:
10+ subprocess.check_output(cmd, stderr=subprocess.STDOUT)
11+ except subprocess.CalledProcessError as e:
12+ if not e.returncode == 2 or \
13+ "{ok,already_member}" not in e.output:
14+ raise e
15 cmd = [RABBITMQ_CTL, 'start_app']
16 subprocess.check_call(cmd)
17 log('Host clustered with %s.' % node)
18
19=== modified file 'hooks/rabbitmq_server_relations.py'
20--- hooks/rabbitmq_server_relations.py 2015-08-10 16:38:33 +0000
21+++ hooks/rabbitmq_server_relations.py 2015-09-10 16:44:56 +0000
22@@ -81,6 +81,7 @@
23 peer_store,
24 peer_store_and_set,
25 peer_retrieve_by_prefix,
26+ leader_get,
27 )
28
29 from charmhelpers.contrib.network.ip import get_address_in_network
30@@ -304,31 +305,35 @@
31 return
32
33 if is_elected_leader('res_rabbitmq_vip'):
34+ log('Leader peer_storing cookie', level=INFO)
35 cookie = open(rabbit.COOKIE_PATH, 'r').read().strip()
36 peer_store('cookie', cookie)
37
38
39 @hooks.hook('cluster-relation-changed')
40 def cluster_changed():
41+ # Future travelers beware ordering is significant
42+ rdata = relation_get()
43+ # sync passwords
44+ blacklist = ['hostname', 'private-address', 'public-address']
45+ whitelist = [a for a in rdata.keys() if a not in blacklist]
46+ peer_echo(includes=whitelist)
47+
48 cookie = peer_retrieve('cookie')
49 if not cookie:
50 log('cluster_joined: cookie not yet set.', level=INFO)
51 return
52
53- rdata = relation_get()
54 if config('prefer-ipv6') and rdata.get('hostname'):
55- private_address = rdata['private-address']
56- hostname = rdata['hostname']
57+ private_address = rdata.get('private-address')
58+ hostname = rdata.get('hostname')
59 if hostname:
60 rabbit.update_hosts_file({private_address: hostname})
61
62- # sync passwords
63- blacklist = ['hostname', 'private-address', 'public-address']
64- whitelist = [a for a in rdata.keys() if a not in blacklist]
65- peer_echo(includes=whitelist)
66-
67 if not is_sufficient_peers():
68 # Stop rabbit until leader has finished configuring
69+ log('Not enough peers, stopping until leader is configured',
70+ level=INFO)
71 service_stop('rabbitmq-server')
72 return
73
74@@ -358,9 +363,12 @@
75 amqp_changed(relation_id=rid, remote_unit=unit)
76
77
78-def update_cookie():
79+def update_cookie(leaders_cookie=None):
80 # sync cookie
81- cookie = peer_retrieve('cookie')
82+ if leaders_cookie:
83+ cookie = leaders_cookie
84+ else:
85+ cookie = peer_retrieve('cookie')
86 cookie_local = None
87 with open(rabbit.COOKIE_PATH, 'r') as f:
88 cookie_local = f.read().strip()
89@@ -763,6 +771,18 @@
90
91 @hooks.hook('leader-settings-changed')
92 def leader_settings_changed():
93+ # Get cookie from leader, update cookie locally and
94+ # force cluster-relation-changed hooks to run on peers
95+ cookie = leader_get(attribute='cookie')
96+ if cookie:
97+ update_cookie(leaders_cookie=cookie)
98+ # Force cluster-relation-changed hooks to run on peers
99+ # This will precipitate peer clustering
100+ # Without this a chicken and egg scenario prevails when
101+ # using LE and peerstorage
102+ for rid in relation_ids('cluster'):
103+ relation_set(relation_id=rid, relation_settings={'cookie': cookie})
104+
105 # If leader has changed and access credentials, ripple these
106 # out from all units
107 for rid in relation_ids('amqp'):

Subscribers

People subscribed via source and target branches