~hopem/charms/trusty/keystone/fix-ssl-disable

« back to all changes in this revision

Viewing changes to hooks/keystone_hooks.py

[hopem, r=gnuoy] add more is_db_ready() protection

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
    log,
19
19
    local_unit,
20
20
    DEBUG,
 
21
    INFO,
21
22
    WARNING,
22
23
    ERROR,
23
24
    relation_get,
187
188
    relation_set(database=config('database'))
188
189
 
189
190
 
190
 
def update_all_identity_relation_units():
 
191
def update_all_identity_relation_units(check_db_ready=True):
191
192
    CONFIGS.write_all()
 
193
    if check_db_ready and not is_db_ready():
 
194
        log('Allowed_units list provided and this unit not present',
 
195
            level=INFO)
 
196
        return
 
197
 
192
198
    try:
193
199
        migrate_database()
194
200
    except Exception as exc:
220
226
            # units acl entry has been added. So, if the db supports passing
221
227
            # a list of permitted units then check if we're in the list.
222
228
            if not is_db_ready(use_current_context=True):
223
 
                log('Allowed_units list provided and this unit not present')
 
229
                log('Allowed_units list provided and this unit not present',
 
230
                    level=INFO)
224
231
                return
 
232
 
225
233
            # Ensure any existing service entries are updated in the
226
234
            # new database backend
227
 
            update_all_identity_relation_units()
 
235
            update_all_identity_relation_units(check_db_ready=False)
228
236
 
229
237
 
230
238
@hooks.hook('pgsql-db-relation-changed')
242
250
 
243
251
 
244
252
@hooks.hook('identity-service-relation-changed')
 
253
@restart_on_change(restart_map())
245
254
@synchronize_ca_if_changed()
246
255
def identity_changed(relation_id=None, remote_unit=None):
247
256
    CONFIGS.write_all()
248
257
 
249
258
    notifications = {}
250
259
    if is_elected_leader(CLUSTER_RES):
251
 
 
252
260
        if not is_db_ready():
253
261
            log("identity-service-relation-changed hook fired before db "
254
262
                "ready - deferring until db ready", level=WARNING)
476
484
 
477
485
    clustered = relation_get('clustered')
478
486
    if clustered and is_elected_leader(CLUSTER_RES):
 
487
        if not is_db_ready():
 
488
                log('Allowed_units list provided and this unit not present',
 
489
                    level=INFO)
 
490
                return
 
491
 
479
492
        ensure_initial_admin(config)
480
493
        log('Cluster configured, notifying other services and updating '
481
494
            'keystone endpoint configuration')