~openstack-charmers-next/charms/xenial/rabbitmq-server/trunk

« back to all changes in this revision

Viewing changes to hooks/rabbit_utils.py

  • Committer: Alex Kavanagh
  • Date: 2016-06-17 13:53:47 UTC
  • Revision ID: alex@ajkavanagh.co.uk-20160617135347-uyga5lv9axpr9ei7
Fix for multiple status_set() in assess_status()

This fixes a multiple status_set() bug in the implementation of assess_status()
on the charm, when it is determining whether it is active AND clustered.
The change hooks into the _determine_os_workload_status() directly in
charmhelpers to ensure that status_set() is only called once when
assess_status() is called.

Change-Id: Idfd93126c3edb41f83897c82ee7f20fe5f366559
Related-Bug:#1588462

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from charmhelpers.core.templating import render
16
16
 
17
17
from charmhelpers.contrib.openstack.utils import (
18
 
    make_assess_status_func,
 
18
    _determine_os_workload_status,
19
19
    pause_unit,
20
20
    resume_unit,
21
21
    is_unit_paused_set,
27
27
    log, ERROR,
28
28
    INFO,
29
29
    service_name,
30
 
    status_get,
31
30
    status_set,
32
31
    cached,
33
32
    relation_set,
686
685
        # General status check
687
686
        ret = wait_app()
688
687
        if ret:
689
 
            if clustered():
690
 
                return 'active', 'Unit is ready and clustered'
691
 
            else:
692
 
                return 'active', 'Unit is ready'
 
688
            # we're active - so just return the 'active' state, but if 'active'
 
689
            # is returned, then it is ignored by the assess_status system.
 
690
            return 'active', "message is ignored"
693
691
    else:
694
692
        return 'waiting', 'RabbitMQ is not yet installed'
695
693
 
751
749
    @returns None - this function is executed for its side-effect
752
750
    """
753
751
    assess_status_func(configs)()
754
 
    # Charm has a bespoke status message when clustered
755
 
    if status_get() == ('active', 'Unit is ready') and clustered():
756
 
        if clustered():
757
 
            status_set('active', 'Unit is ready and clustered')
758
752
 
759
753
 
760
754
def assess_status_func(configs):
771
765
    @param configs: a templating.OSConfigRenderer() object
772
766
    @return f() -> None : a function that assesses the unit's workload status
773
767
    """
774
 
    return make_assess_status_func(
775
 
        configs, {},
776
 
        charm_func=assess_cluster_status,
777
 
        services=services(), ports=None)
 
768
    def _assess_status_func():
 
769
        state, message = _determine_os_workload_status(
 
770
            configs, {},
 
771
            charm_func=assess_cluster_status,
 
772
            services=services(), ports=None)
 
773
        if state == 'active' and clustered():
 
774
            message = 'Unit is ready and clustered'
 
775
        status_set(state, message)
 
776
 
 
777
    return _assess_status_func
778
778
 
779
779
 
780
780
def pause_unit_helper(configs):