Ensure o.c.local is populated with the current Context

Since oslo.messaging was introduced, our logs at the server side of an RPC
call have not been receiving a context in order to inject user/tenant info
into the log format.

This is due to o.m implementing their own replacement for o.c.local, we
now need to manually populate o.c.local.

Additionally, remove some redundant code from the Context to_dict method

Change-Id: Id755c62681d425ae20473a57cf227a501b65b399
Closes-Bug: 1344040
This commit is contained in:
Kiall Mac Innes 2014-07-18 14:38:26 +01:00
parent ed59a6689a
commit 5df0429871
2 changed files with 11 additions and 15 deletions

View File

@ -23,7 +23,6 @@ from designate import notifications
from designate import wsgi
from designate import context
from designate.openstack.common import jsonutils as json
from designate.openstack.common import local
from designate.openstack.common import log as logging
from designate.openstack.common import strutils
from designate.openstack.common.middleware import request_id
@ -66,8 +65,6 @@ class ContextMiddleware(wsgi.Middleware):
kwargs.setdefault('request_id', req_id)
ctxt = context.DesignateContext(*args, **kwargs)
local.store.context = ctxt
request.environ['context'] = ctxt
return ctxt

View File

@ -17,8 +17,8 @@ import itertools
import copy
from designate.openstack.common import context
from designate.openstack.common import local
from designate.openstack.common import log as logging
from designate.openstack.common.gettextutils import _LW
LOG = logging.getLogger(__name__)
@ -29,10 +29,10 @@ class DesignateContext(context.RequestContext):
user_domain=None, project_domain=None, is_admin=False,
read_only=False, show_deleted=False, request_id=None,
instance_uuid=None, roles=None, service_catalog=None,
all_tenants=False, **kwargs):
if kwargs:
LOG.warn(_LW('Arguments dropped when creating context: %s') %
str(kwargs))
all_tenants=False, user_identity=None):
# NOTE: user_identity may be passed in, but will be silently dropped as
# it is a generated field based on several others.
roles = roles or []
super(DesignateContext, self).__init__(
auth_token=auth_token,
@ -51,6 +51,12 @@ class DesignateContext(context.RequestContext):
self.service_catalog = service_catalog
self.all_tenants = all_tenants
if not hasattr(local.store, 'context'):
self.update_store()
def update_store(self):
local.store.context = self
def deepcopy(self):
d = self.to_dict()
@ -59,17 +65,10 @@ class DesignateContext(context.RequestContext):
def to_dict(self):
d = super(DesignateContext, self).to_dict()
user_idt = (
self.user_idt_format.format(user=self.user or '-',
tenant=self.tenant or '-',
domain=self.domain or '-',
user_domain=self.user_domain or '-',
p_domain=self.project_domain or '-'))
d.update({
'roles': self.roles,
'service_catalog': self.service_catalog,
'all_tenants': self.all_tenants,
'user_identity': user_idt
})
return copy.deepcopy(d)