Fixed request_id data type error under py3

In python3.4 request_id becomes a bytesarrary which is not JSON
serializable. This patch addes a conversion (safe_decode) wrapper.

Change-Id: Icf8dbf100ed2cb844e4922ea05e606588cb6e5e4
This commit is contained in:
tengqm 2015-03-18 21:12:31 +08:00
parent 4309d15e8d
commit 11f90c41e8

View File

@ -12,6 +12,7 @@
from oslo_context import context from oslo_context import context
from oslo_middleware import request_id as oslo_request_id from oslo_middleware import request_id as oslo_request_id
from oslo_utils import encodeutils
from oslo_utils import importutils from oslo_utils import importutils
from senlin.common import exception from senlin.common import exception
@ -48,6 +49,8 @@ class RequestContext(context.RequestContext):
read_only=read_only, read_only=read_only,
show_deleted=show_deleted, show_deleted=show_deleted,
request_id=request_id) request_id=request_id)
self.request_id = encodeutils.safe_decode(self.request_id)
# Session for DB access # Session for DB access
self._session = None self._session = None
@ -162,7 +165,11 @@ class ContextMiddleware(wsgi.Middleware):
roles = headers.get('X-Roles') roles = headers.get('X-Roles')
if roles is not None: if roles is not None:
roles = roles.split(',') roles = roles.split(',')
request_id = environ.get(oslo_request_id.ENV_REQUEST_ID) env_req_id = environ.get(oslo_request_id.ENV_REQUEST_ID)
if env_req_id is None:
request_id = None
else:
request_id = encodeutils.safe_decode(env_req_id)
except Exception: except Exception:
raise exception.NotAuthenticated() raise exception.NotAuthenticated()