~openstack-charmers-next/charms/xenial/cinder-ceph/trunk

« back to all changes in this revision

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

  • Committer: James Page
  • Date: 2016-06-17 10:42:48 UTC
  • Revision ID: james.page@ubuntu.com-20160617104248-8jocp3zyedl7h5gu
Switch to using charm-store for amulet tests

All OpenStack charms are now directly published to the charm store
on landing; switch Amulet helper to resolve charms using the
charm store rather than bzr branches, removing the lag between
charm changes landing and being available for other charms to
use for testing.

This is also important for new layered charms where the charm must
be build and published prior to being consumable.

Change-Id: I05d8199238727ebca25666196cf9060a94d3e7b8

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    relation_get,
42
42
    config as config_get,
43
43
    INFO,
44
 
    ERROR,
 
44
    DEBUG,
45
45
    WARNING,
46
46
    unit_get,
47
 
    is_leader as juju_is_leader
 
47
    is_leader as juju_is_leader,
 
48
    status_set,
48
49
)
49
50
from charmhelpers.core.decorators import (
50
51
    retry_on_exception,
60
61
    pass
61
62
 
62
63
 
 
64
class HAIncorrectConfig(Exception):
 
65
    pass
 
66
 
 
67
 
63
68
class CRMResourceNotFound(Exception):
64
69
    pass
65
70
 
274
279
    Obtains all relevant configuration from charm configuration required
275
280
    for initiating a relation to hacluster:
276
281
 
277
 
        ha-bindiface, ha-mcastport, vip
 
282
        ha-bindiface, ha-mcastport, vip, os-internal-hostname,
 
283
        os-admin-hostname, os-public-hostname
278
284
 
279
285
    param: exclude_keys: list of setting key(s) to be excluded.
280
286
    returns: dict: A dict containing settings keyed by setting name.
281
 
    raises: HAIncompleteConfig if settings are missing.
 
287
    raises: HAIncompleteConfig if settings are missing or incorrect.
282
288
    '''
283
 
    settings = ['ha-bindiface', 'ha-mcastport', 'vip']
 
289
    settings = ['ha-bindiface', 'ha-mcastport', 'vip', 'os-internal-hostname',
 
290
                'os-admin-hostname', 'os-public-hostname']
284
291
    conf = {}
285
292
    for setting in settings:
286
293
        if exclude_keys and setting in exclude_keys:
287
294
            continue
288
295
 
289
296
        conf[setting] = config_get(setting)
290
 
    missing = []
291
 
    [missing.append(s) for s, v in six.iteritems(conf) if v is None]
292
 
    if missing:
293
 
        log('Insufficient config data to configure hacluster.', level=ERROR)
294
 
        raise HAIncompleteConfig
 
297
 
 
298
    if not valid_hacluster_config():
 
299
        raise HAIncorrectConfig('Insufficient or incorrect config data to '
 
300
                                'configure hacluster.')
295
301
    return conf
296
302
 
297
303
 
 
304
def valid_hacluster_config():
 
305
    '''
 
306
    Check that either vip or dns-ha is set. If dns-ha then one of os-*-hostname
 
307
    must be set.
 
308
 
 
309
    Note: ha-bindiface and ha-macastport both have defaults and will always
 
310
    be set. We only care that either vip or dns-ha is set.
 
311
 
 
312
    :returns: boolean: valid config returns true.
 
313
    raises: HAIncompatibileConfig if settings conflict.
 
314
    raises: HAIncompleteConfig if settings are missing.
 
315
    '''
 
316
    vip = config_get('vip')
 
317
    dns = config_get('dns-ha')
 
318
    if not(bool(vip) ^ bool(dns)):
 
319
        msg = ('HA: Either vip or dns-ha must be set but not both in order to '
 
320
               'use high availability')
 
321
        status_set('blocked', msg)
 
322
        raise HAIncorrectConfig(msg)
 
323
 
 
324
    # If dns-ha then one of os-*-hostname must be set
 
325
    if dns:
 
326
        dns_settings = ['os-internal-hostname', 'os-admin-hostname',
 
327
                        'os-public-hostname']
 
328
        # At this point it is unknown if one or all of the possible
 
329
        # network spaces are in HA. Validate at least one is set which is
 
330
        # the minimum required.
 
331
        for setting in dns_settings:
 
332
            if config_get(setting):
 
333
                log('DNS HA: At least one hostname is set {}: {}'
 
334
                    ''.format(setting, config_get(setting)),
 
335
                    level=DEBUG)
 
336
                return True
 
337
 
 
338
        msg = ('DNS HA: At least one os-*-hostname(s) must be set to use '
 
339
               'DNS HA')
 
340
        status_set('blocked', msg)
 
341
        raise HAIncompleteConfig(msg)
 
342
 
 
343
    log('VIP HA: VIP is set {}'.format(vip), level=DEBUG)
 
344
    return True
 
345
 
 
346
 
298
347
def canonical_url(configs, vip_setting='vip'):
299
348
    '''
300
349
    Returns the correct HTTP URL to this host given the state of HTTPS