Merge "Migrate to oslo request_id middleware - mv 2.46"

This commit is contained in:
Jenkins 2017-05-27 16:04:16 +00:00 committed by Gerrit Code Review
commit d9d300d5c8
8 changed files with 40 additions and 25 deletions

View File

@ -19,7 +19,7 @@
}
],
"status": "CURRENT",
"version": "2.45",
"version": "2.46",
"min_version": "2.1",
"updated": "2013-07-23T11:33:21Z"
}

View File

@ -22,7 +22,7 @@
}
],
"status": "CURRENT",
"version": "2.45",
"version": "2.46",
"min_version": "2.1",
"updated": "2013-07-23T11:33:21Z"
}

View File

@ -15,30 +15,22 @@
"""Middleware that ensures x-compute-request-id
Using this middleware provides a convenient way to attach the
x-compute-request-id to only v2 responses. Previously, this header was set in
api/openstack/wsgi.py
Nova's notion of request-id tracking predates any common idea, so the
original version of this header in OpenStack was
x-compute-request-id. Eventually we got oslo, and all other projects
implemented this with x-openstack-request-id.
However, x-compute-request-id was always part of our contract. The
following migrates us to use x-openstack-request-id as well, by using
the common middleware.
Responses for v2.1 API are taken care of by the request_id middleware provided
in oslo.
"""
from oslo_context import context
from oslo_middleware import base
import webob.dec
from oslo_middleware import request_id
ENV_REQUEST_ID = 'openstack.request_id'
HTTP_RESP_HEADER_REQUEST_ID = 'x-compute-request-id'
class ComputeReqIdMiddleware(base.Middleware):
@webob.dec.wsgify
def __call__(self, req):
req_id = context.generate_request_id()
req.environ[ENV_REQUEST_ID] = req_id
response = req.get_response(self.application)
if HTTP_RESP_HEADER_REQUEST_ID not in response.headers:
response.headers.add(HTTP_RESP_HEADER_REQUEST_ID, req_id)
return response
class ComputeReqIdMiddleware(request_id.RequestId):
compat_headers = [HTTP_RESP_HEADER_REQUEST_ID]

View File

@ -109,6 +109,7 @@ REST_API_VERSION_HISTORY = """REST API Version History:
header in the response for the snapshot image, they now return a
json dict in the response body with an image_id key and uuid
value.
* 2.46 - Return ``X-OpenStack-Request-ID`` header on requests.
"""
# The minimum and maximum versions of the API supported
@ -117,7 +118,7 @@ REST_API_VERSION_HISTORY = """REST API Version History:
# Note(cyeoh): This only applies for the v2.1 API once microversions
# support is fully merged. It does not affect the V2 API.
_MIN_API_VERSION = "2.1"
_MAX_API_VERSION = "2.45"
_MAX_API_VERSION = "2.46"
DEFAULT_API_VERSION = _MIN_API_VERSION
# Almost all proxy APIs which related to network, images and baremetal

View File

@ -536,3 +536,12 @@ user documentation.
The ``createImage`` and ``createBackup`` server action APIs no longer return
a ``Location`` header in the response for the snapshot image, they now return
a json dict in the response body with an ``image_id`` key and uuid value.
2.46
----
The request_id created for every inbound request is now returned in
``X-OpenStack-Request-ID`` in addition to ``X-Compute-Request-ID``
to be consistent with the rest of OpenStack. This is a signaling
only microversion, as these header settings happen well before
microversion processing.

View File

@ -23,16 +23,19 @@ from nova.api import compute_req_id
from nova import test
ENV_REQUEST_ID = 'openstack.request_id'
class RequestIdTest(test.NoDBTestCase):
def test_generate_request_id(self):
@webob.dec.wsgify
def application(req):
return req.environ[compute_req_id.ENV_REQUEST_ID]
return req.environ[ENV_REQUEST_ID]
app = compute_req_id.ComputeReqIdMiddleware(application)
req = webob.Request.blank('/test')
req_id = context.generate_request_id()
req.environ[compute_req_id.ENV_REQUEST_ID] = req_id
req.environ[ENV_REQUEST_ID] = req_id
res = req.get_response(app)
res_id = res.headers.get(compute_req_id.HTTP_RESP_HEADER_REQUEST_ID)

View File

@ -0,0 +1,10 @@
---
features:
- |
Nova now uses oslo.middleware for request_id processing. This
means that there is now a new ``X-OpenStack-Request-ID`` header
returned on every request which mirrors the content of the
existing ``X-Compute-Request-ID``. The expected existence of this
header is signaled by Microversion 2.46. If server version >= 2.46, you
can expect to see this header in your results (regardless of
microversion requested).

View File

@ -49,7 +49,7 @@ oslo.privsep!=1.17.0,>=1.9.0 # Apache-2.0
oslo.i18n!=3.15.2,>=2.1.0 # Apache-2.0
oslo.service>=1.10.0 # Apache-2.0
rfc3986>=0.3.1 # Apache-2.0
oslo.middleware>=3.10.0 # Apache-2.0
oslo.middleware>=3.27.0 # Apache-2.0
psutil>=3.2.2 # BSD
oslo.versionedobjects>=1.17.0 # Apache-2.0
os-brick>=1.13.0 # Apache-2.0