~chris-gondolin/charms/trusty/keystone/ldap-fixes

« back to all changes in this revision

Viewing changes to hooks/keystone_hooks.py

  • Committer: Edward Hope-Morley
  • Date: 2016-01-08 14:33:27 UTC
  • mfrom: (196 stable.remote)
  • mto: This revision was merged to the branch mainline in revision 197.
  • Revision ID: edward.hope-morley@canonical.com-20160108143327-czj7dusywrbuqz66
sync /next

Show diffs side-by-side

added added

removed removed

Lines of Context:
273
273
    update_all_identity_relation_units()
274
274
 
275
275
 
 
276
def leader_init_db_if_ready(use_current_context=False):
 
277
    """ Initialise the keystone db if it is ready and mark it as initialised.
 
278
 
 
279
    NOTE: this must be idempotent.
 
280
    """
 
281
    if not is_elected_leader(CLUSTER_RES):
 
282
        log("Not leader - skipping db init", level=DEBUG)
 
283
        return
 
284
 
 
285
    if is_db_initialised():
 
286
        log("Database already initialised - skipping db init", level=DEBUG)
 
287
        return
 
288
 
 
289
    # Bugs 1353135 & 1187508. Dbs can appear to be ready before the
 
290
    # units acl entry has been added. So, if the db supports passing
 
291
    # a list of permitted units then check if we're in the list.
 
292
    if not is_db_ready(use_current_context=use_current_context):
 
293
        log('Allowed_units list provided and this unit not present',
 
294
            level=INFO)
 
295
        return
 
296
 
 
297
    migrate_database()
 
298
    # Ensure any existing service entries are updated in the
 
299
    # new database backend. Also avoid duplicate db ready check.
 
300
    update_all_identity_relation_units(check_db_ready=False)
 
301
 
 
302
 
276
303
@hooks.hook('shared-db-relation-changed')
277
304
@restart_on_change(restart_map())
278
305
@synchronize_ca_if_changed()
281
308
        log('shared-db relation incomplete. Peer not ready?')
282
309
    else:
283
310
        CONFIGS.write(KEYSTONE_CONF)
284
 
        if is_elected_leader(CLUSTER_RES):
285
 
            # Bugs 1353135 & 1187508. Dbs can appear to be ready before the
286
 
            # units acl entry has been added. So, if the db supports passing
287
 
            # a list of permitted units then check if we're in the list.
288
 
            if not is_db_ready(use_current_context=True):
289
 
                log('Allowed_units list provided and this unit not present',
290
 
                    level=INFO)
291
 
                return
292
 
 
293
 
            migrate_database()
294
 
            # Ensure any existing service entries are updated in the
295
 
            # new database backend. Also avoid duplicate db ready check.
296
 
            update_all_identity_relation_units(check_db_ready=False)
 
311
        leader_init_db_if_ready(use_current_context=True)
297
312
 
298
313
 
299
314
@hooks.hook('pgsql-db-relation-changed')
304
319
        log('pgsql-db relation incomplete. Peer not ready?')
305
320
    else:
306
321
        CONFIGS.write(KEYSTONE_CONF)
307
 
        if is_elected_leader(CLUSTER_RES):
308
 
            if not is_db_ready(use_current_context=True):
309
 
                log('Allowed_units list provided and this unit not present',
310
 
                    level=INFO)
311
 
                return
312
 
 
313
 
            migrate_database()
314
 
            # Ensure any existing service entries are updated in the
315
 
            # new database backend. Also avoid duplicate db ready check.
316
 
            update_all_identity_relation_units(check_db_ready=False)
 
322
        leader_init_db_if_ready(use_current_context=True)
317
323
 
318
324
 
319
325
@hooks.hook('identity-service-relation-changed')
605
611
    ensure_ssl_dirs()
606
612
 
607
613
    CONFIGS.write_all()
 
614
 
 
615
    # See LP bug 1519035
 
616
    leader_init_db_if_ready()
 
617
 
608
618
    update_nrpe_config()
609
619
 
610
620
    if is_elected_leader(CLUSTER_RES):