~landscape/charms/trusty/keystone-leadership-election/trunk

« back to all changes in this revision

Viewing changes to hooks/keystone_utils.py

[hopem,r=gnuoy]

Fixes db migration (keystone-manage db-sync) races but preventing
database access/usage until the database is ready and has been
initialised.

Show diffs side-by-side

added added

removed removed

Lines of Context:
314
314
    configs.write_all()
315
315
 
316
316
    if is_elected_leader(CLUSTER_RES):
317
 
        migrate_database()
 
317
        if is_db_ready():
 
318
            migrate_database()
 
319
        else:
 
320
            log("Database not ready - deferring to shared-db relation",
 
321
                level=INFO)
 
322
            return
 
323
 
 
324
 
 
325
def set_db_initialised():
 
326
    for rid in relation_ids('cluster'):
 
327
        relation_set(relation_settings={'db-initialised': 'True'},
 
328
                     relation_id=rid)
 
329
 
 
330
 
 
331
def is_db_initialised():
 
332
    for rid in relation_ids('cluster'):
 
333
        units = related_units(rid) + [local_unit()]
 
334
        for unit in units:
 
335
            db_initialised = relation_get(attribute='db-initialised',
 
336
                                          unit=unit, rid=rid)
 
337
            if db_initialised:
 
338
                log("Database is initialised", level=DEBUG)
 
339
                return True
 
340
 
 
341
    log("Database is NOT initialised", level=DEBUG)
 
342
    return False
318
343
 
319
344
 
320
345
def migrate_database():
328
353
    subprocess.check_output(cmd)
329
354
    service_start('keystone')
330
355
    time.sleep(10)
331
 
 
 
356
    set_db_initialised()
332
357
 
333
358
# OLD
334
359
 
 
360
 
335
361
def get_local_endpoint():
336
362
    """Returns the URL for the local end-point bypassing haproxy/ssl"""
337
363
    if config('prefer-ipv6'):