~gnuoy/charms/trusty/rabbitmq-server/ssl-only

« back to all changes in this revision

Viewing changes to hooks/rabbitmq_server_relations.py

  • Committer: billy.olsen at canonical
  • Date: 2015-09-01 00:54:12 UTC
  • mfrom: (105.3.6 rabbitmq-server)
  • Revision ID: billy.olsen@canonical.com-20150901005412-v4oorjgs1kyopdvx
[thedac,r=billy-olsen] Fix clustering race conditions.

For juju >= 1.24 run cluster_changed() when the leader-settings-changed hook executes.
For juju < 1.24 use remote_unit() in relation_get when in a native cluster relation hook

Partially-Closes Bug: 1486177

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
    UnregisteredHookError,
64
64
    is_leader,
65
65
    charm_dir,
 
66
    in_relation_hook,
66
67
)
67
68
from charmhelpers.core.host import (
68
69
    cmp_pkgrevno,
317
318
 
318
319
@hooks.hook('cluster-relation-changed')
319
320
def cluster_changed():
320
 
    cookie = peer_retrieve('cookie')
 
321
    if relation_ids('cluster'):
 
322
        cookie = peer_retrieve('cookie')
 
323
    else:
 
324
        cookie = None
321
325
    if not cookie:
322
326
        log('cluster_joined: cookie not yet set.', level=INFO)
323
327
        return
326
330
    hostname = rdata.get('hostname', None)
327
331
    private_address = rdata.get('private-address', None)
328
332
 
 
333
    # If called from leader-settings-changed we are not in a hook env
 
334
    if not in_relation_hook():
 
335
        rid = relation_ids('cluster')[0]
 
336
        for unit in related_units(rid):
 
337
            rdata = relation_get(rid=rid, unit=unit)
 
338
            if rdata:
 
339
                break;
 
340
    else:
 
341
        rdata = relation_get()
 
342
 
 
343
 
329
344
    if hostname and private_address:
330
345
        rabbit.update_hosts_file({private_address: hostname})
331
346
 
336
351
 
337
352
    if not is_sufficient_peers():
338
353
        # Stop rabbit until leader has finished configuring
 
354
        log('Not enough peers, stopping until leader is configured',
 
355
            level=INFO)
339
356
        service_stop('rabbitmq-server')
340
357
        return
341
358
 
772
789
def leader_settings_changed():
773
790
    # If leader has changed and access credentials, ripple these
774
791
    # out from all units
 
792
    cluster_changed()
775
793
    for rid in relation_ids('amqp'):
776
794
        for unit in related_units(rid):
777
795
            amqp_changed(relation_id=rid, remote_unit=unit)