From 19f2f2833adb484d30d120de3dc154fad4fe9f3d Mon Sep 17 00:00:00 2001 From: John Griffith Date: Tue, 24 Mar 2015 03:08:15 +0000 Subject: [PATCH] Enable request-id in cinder API logs Using common.local:store.context doesn't work correctly with the new oslo_log module. This change removes the calls to common.local and removes the file altogether which allows the proper settings to be passed in to the logging module and give us back our request-id in the API logs. Change-Id: If312f419fb465c9128bcfa0a280d6c35a46cb29b Closes-Bug: #1435588 --- cinder/context.py | 9 ++----- cinder/openstack/common/local.py | 45 -------------------------------- openstack-common.conf | 1 - 3 files changed, 2 insertions(+), 53 deletions(-) delete mode 100644 cinder/openstack/common/local.py diff --git a/cinder/context.py b/cinder/context.py index e5a1eb79f..88139ad61 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -24,7 +24,6 @@ from oslo_log import log as logging from oslo_utils import timeutils from cinder.i18n import _ -from cinder.openstack.common import local from cinder import policy @@ -74,8 +73,6 @@ class RequestContext(context.RequestContext): timestamp = timeutils.parse_strtime(timestamp) self.timestamp = timestamp self.quota_class = quota_class - if overwrite or not hasattr(local.store, 'context'): - self.update_store() if service_catalog: # Only include required parts of service_catalog @@ -109,9 +106,6 @@ class RequestContext(context.RequestContext): read_deleted = property(_get_read_deleted, _set_read_deleted, _del_read_deleted) - def update_store(self): - local.store.context = self - def to_dict(self): default = super(RequestContext, self).to_dict() extra = {'user_id': self.user_id, @@ -123,7 +117,8 @@ class RequestContext(context.RequestContext): 'remote_address': self.remote_address, 'timestamp': timeutils.strtime(self.timestamp), 'quota_class': self.quota_class, - 'service_catalog': self.service_catalog} + 'service_catalog': self.service_catalog, + 'request_id': self.request_id} return dict(default.items() + extra.items()) @classmethod diff --git a/cinder/openstack/common/local.py b/cinder/openstack/common/local.py deleted file mode 100644 index 0819d5b97..000000000 --- a/cinder/openstack/common/local.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2011 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -"""Local storage of variables using weak references""" - -import threading -import weakref - - -class WeakLocal(threading.local): - def __getattribute__(self, attr): - rval = super(WeakLocal, self).__getattribute__(attr) - if rval: - # NOTE(mikal): this bit is confusing. What is stored is a weak - # reference, not the value itself. We therefore need to lookup - # the weak reference and return the inner value here. - rval = rval() - return rval - - def __setattr__(self, attr, value): - value = weakref.ref(value) - return super(WeakLocal, self).__setattr__(attr, value) - - -# NOTE(mikal): the name "store" should be deprecated in the future -store = WeakLocal() - -# A "weak" store uses weak references and allows an object to fall out of scope -# when it falls out of scope in the code that uses the thread local storage. A -# "strong" store will hold a reference to the object so that it never falls out -# of scope. -weak_store = WeakLocal() -strong_store = threading.local() diff --git a/openstack-common.conf b/openstack-common.conf index 72f963391..00f22d387 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -7,7 +7,6 @@ module=fileutils module=gettextutils module=imageutils module=install_venv_common -module=local module=loopingcall module=middleware module=periodic_task -- 2.45.2