Inherit RequestContext from oslo_context's RequestContext

Before murano used RequestContext, inherited from object.
oslo_context has graduated and includes a bunch of features, that is
used by oslo_log and other oslo modules.
In particular this commit enables logging of request_id, user_id and
tenant_id in all context-aware requests.
Alters tests tto make them pass regardless of the new context.

Targets blueprint: murano-x-openstack-request-id-support

Change-Id: Ic22f67ae89881581254de8787fa3632dfa1af08f
This commit is contained in:
Kirill Zaitsev 2015-08-12 16:24:26 +03:00
parent dd84aa1e06
commit b64b9d72ee
4 changed files with 16 additions and 26 deletions

View File

@ -13,38 +13,23 @@
# under the License.
from murano.common import policy
from oslo_context import context
class RequestContext(object):
"""Stores information about the security context under which the user
accesses the system, as well as additional request information.
class RequestContext(context.RequestContext):
"""Class that stores context info about an API request.
TODO: (sjmc7) - extend openstack.common.context
Stores creditentials of the user, that is accessing API
as well as additional request information.
"""
def __init__(self, auth_token=None, user=None,
tenant=None, session=None, is_admin=None,
roles=None):
self.auth_token = auth_token
self.user = user
self.tenant = tenant
def __init__(self, session=None,
roles=None, is_admin=None,
**kwargs):
super(RequestContext, self).__init__(**kwargs)
self.session = session
self.is_admin = is_admin
self.roles = roles or []
self.is_admin = is_admin
if self.is_admin is None:
self.is_admin = policy.check_is_admin(self)
def to_dict(self):
return {
'user': self.user,
'tenant': self.tenant,
'auth_token': self.auth_token,
'session': self.session,
'roles': self.roles,
'is_admin': self.is_admin
}
@classmethod
def from_dict(cls, values):
return cls(**values)

View File

@ -146,6 +146,7 @@ class ControllerTest(object):
'SCRIPT_NAME': '/v1',
'PATH_INFO': path,
'wsgi.url_scheme': 'http',
'QUERY_STRING': '',
}
def _simple_request(self, path, params=None, method='GET',

View File

@ -19,8 +19,11 @@ from murano.db import session
def dummy_context(user='test_username', tenant_id='test_tenant_id',
password='password', roles=[], user_id=None,
is_admin=False):
is_admin=False, request_id='dummy-request'):
# NOTE(kzaitsev) passing non-False value by default to request_id, to
# prevent generation during tests.
return context.RequestContext.from_dict({
'request_id': request_id,
'tenant': tenant_id,
'user': user,
# 'roles': roles, # Commented until policy check changes land

View File

@ -32,6 +32,7 @@ python-muranoclient>=0.5.6
python-congressclient>=1.0.0
oslo.db>=2.0 # Apache-2.0
oslo.config>=2.1.0 # Apache-2.0
oslo.context>=0.2.0 # Apache-2.0
oslo.policy>=0.5.0 # Apache-2.0
oslo.messaging!=1.17.0,!=1.17.1,>=1.16.0 # Apache-2.0
oslo.serialization>=1.4.0 # Apache-2.0