Skip to content

Commit

Permalink
Delay using threading.local() to fix check job failure
Browse files Browse the repository at this point in the history
After I221232d50821fe2adb9881f237f06714003ce79d was merged,
the gate-tempest-dsvm-keystone-eventlet-full has been failing
consistently. We added a threading.local() call and use
that for the oslo.db engine facade. We need to ensure that
monkey patching for eventlet is done before we call local().

Closes-Bug: #1550017
Change-Id: I363ef507e78c1c601011861ebb589c10a2bc489e
  • Loading branch information
dims committed Feb 26, 2016
1 parent 8c4a193 commit 9535c09
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions keystone/common/sql/core.py
Expand Up @@ -19,7 +19,6 @@
"""
import functools
import threading

from oslo_config import cfg
from oslo_db import exception as db_exception
Expand Down Expand Up @@ -184,15 +183,25 @@ def cleanup():
_main_context_manager = None


_CONTEXT = threading.local()
_CONTEXT = None


def _get_context():
global _CONTEXT
if _CONTEXT is None:
# NOTE(dims): Delay the `threading.local` import to allow for
# eventlet/gevent monkeypatching to happen
import threading
_CONTEXT = threading.local()
return _CONTEXT


def session_for_read():
return _get_main_context_manager().reader.using(_CONTEXT)
return _get_main_context_manager().reader.using(_get_context())


def session_for_write():
return _get_main_context_manager().writer.using(_CONTEXT)
return _get_main_context_manager().writer.using(_get_context())


def truncated(f):
Expand Down

0 comments on commit 9535c09

Please sign in to comment.