~billy-olsen/charms/trusty/heat/lp1500635

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/hahelpers/cluster.py

  • Committer: Corey Bryant
  • Date: 2015-06-12 13:50:03 UTC
  • mfrom: (41.2.9 heat)
  • Revision ID: corey.bryant@canonical.com-20150612135003-0arrap0x5jmumb60
[beisner,r=corey.bryant] Add basic amulet tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    pass
65
65
 
66
66
 
 
67
class CRMDCNotFound(Exception):
 
68
    pass
 
69
 
 
70
 
67
71
def is_elected_leader(resource):
68
72
    """
69
73
    Returns True if the charm executing this is the elected cluster leader.
116
120
        status = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
117
121
        if not isinstance(status, six.text_type):
118
122
            status = six.text_type(status, "utf-8")
119
 
    except subprocess.CalledProcessError:
120
 
        return False
 
123
    except subprocess.CalledProcessError as ex:
 
124
        raise CRMDCNotFound(str(ex))
 
125
 
121
126
    current_dc = ''
122
127
    for line in status.split('\n'):
123
128
        if line.startswith('Current DC'):
125
130
            current_dc = line.split(':')[1].split()[0]
126
131
    if current_dc == get_unit_hostname():
127
132
        return True
 
133
    elif current_dc == 'NONE':
 
134
        raise CRMDCNotFound('Current DC: NONE')
 
135
 
128
136
    return False
129
137
 
130
138
 
131
 
@retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound)
 
139
@retry_on_exception(5, base_delay=2,
 
140
                    exc_type=(CRMResourceNotFound, CRMDCNotFound))
132
141
def is_crm_leader(resource, retry=False):
133
142
    """
134
143
    Returns True if the charm calling this is the elected corosync leader,