~matsubara/charms/trusty/keystone/bug-1417211

« back to all changes in this revision

Viewing changes to hooks/keystone_hooks.py

  • Committer: Liam Young
  • Date: 2015-01-23 09:20:29 UTC
  • mfrom: (109.1.1 keystone.fix-db-race)
  • Revision ID: liam.young@canonical.com-20150123092029-9catqct0ouxmaxcg
[hopem, r=gnuoy] Wait until DB ready before performing Keystone api ops.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import hashlib
3
3
import json
4
4
import os
5
 
import re
6
5
import stat
7
6
import sys
8
7
import time
67
66
    get_ssl_sync_request_units,
68
67
    is_str_true,
69
68
    is_ssl_cert_master,
 
69
    is_db_ready,
70
70
)
71
71
 
72
72
from charmhelpers.contrib.hahelpers.cluster import (
219
219
            # Bugs 1353135 & 1187508. Dbs can appear to be ready before the
220
220
            # units acl entry has been added. So, if the db supports passing
221
221
            # a list of permitted units then check if we're in the list.
222
 
            allowed_units = relation_get('allowed_units')
223
 
            if allowed_units and local_unit() not in allowed_units.split():
 
222
            if not is_db_ready(use_current_context=True):
224
223
                log('Allowed_units list provided and this unit not present')
225
224
                return
226
225
            # Ensure any existing service entries are updated in the
249
248
 
250
249
    notifications = {}
251
250
    if is_elected_leader(CLUSTER_RES):
252
 
        # Catch database not configured error and defer until db ready
253
 
        from keystoneclient.apiclient.exceptions import InternalServerError
254
 
        try:
255
 
            add_service_to_keystone(relation_id, remote_unit)
256
 
        except InternalServerError as exc:
257
 
            key = re.compile("'keystone\..+' doesn't exist")
258
 
            if re.search(key, exc.message):
259
 
                log("Keystone database not yet ready (InternalServerError "
260
 
                    "raised) - deferring until *-db relation completes.",
261
 
                    level=WARNING)
262
 
                return
263
 
 
264
 
            log("Unexpected exception occurred", level=ERROR)
265
 
            raise
266
 
 
 
251
 
 
252
        if not is_db_ready():
 
253
            log("identity-service-relation-changed hook fired before db "
 
254
                "ready - deferring until db ready", level=WARNING)
 
255
            return
 
256
 
 
257
        add_service_to_keystone(relation_id, remote_unit)
267
258
        settings = relation_get(rid=relation_id, unit=remote_unit)
268
259
        service = settings.get('service', None)
269
260
        if service: