Fix API version inferred w/ un-versioned URLs

With [1], we fixed the issue with v1 API URLs when
configuring manila with a reverse proxy, like uwsgi.
However, the version discovery can be made against a
"unversioned" URL, i.e, the "/" endpoint.

Example version discovery target when there's no reverse
proxy:

   curl -i -X GET www.openstack-overcloud.com:8786/

Example version discovery target when manila is configured
with a web proxy:

   curl -i -X GET www.openstack-overcloud.com/shared-file-system/

Currently, the API assumes that a v2 endpoint is requested
and hence sets a default API version in the request, which
results in the wrong headers communicated to the client.

Fix this issue. The release note added with [1] should
suffice for this fix.

[1] I0363d7174f3d7ddefa8ced59b182faed665e9c36
Change-Id: I50d1024ee8485b8290c24fa850e60755b518fff3
Closes-Bug: #1818081
(Cherry-picked from commit 4b0c953f7f)
This commit is contained in:
Goutham Pacha Ravi 2019-03-13 16:50:27 -07:00 committed by Tom Barron
parent 2de3256439
commit 5a3be01535
3 changed files with 6 additions and 3 deletions

View File

@ -54,6 +54,7 @@ API_VERSION_REQUEST_HEADER = 'X-OpenStack-Manila-API-Version'
EXPERIMENTAL_API_REQUEST_HEADER = 'X-OpenStack-Manila-API-Experimental'
V1_SCRIPT_NAME = '/v1'
V2_SCRIPT_NAME = '/v2'
class Request(webob.Request):
@ -219,7 +220,9 @@ class Request(webob.Request):
Microversions starts with /v2, so if a client sends a /v1 URL, then
ignore the headers and request 1.0 APIs.
"""
if not self.script_name:
if not self.script_name or not (V1_SCRIPT_NAME in self.script_name or
V2_SCRIPT_NAME in self.script_name):
# The request is on the base URL without a major version specified
self.api_version_request = api_version.APIVersionRequest()
elif V1_SCRIPT_NAME in self.script_name:
self.api_version_request = api_version.APIVersionRequest('1.0')

View File

@ -177,7 +177,7 @@ class RequestTest(test.TestCase):
self.assertIsNone(request.set_api_version_request())
if not resource:
if not resource or not ('/v1' in resource or '/v2' in resource):
self.assertEqual(api_version.APIVersionRequest(),
request.api_version_request)
elif 'v1' in resource:

View File

@ -3,5 +3,5 @@ fixes:
- |
When manila API is run behind a proxy webserver, the API service was
parsing the major API version requested incorrectly, leading to incorrect
responses. This behavior has now been fixed. See `launchpad bug 1815038
responses. This behavior has now been fixed. See `launchpad bug 1818081
<https://bugs.launchpad.net/manila/+bug/1818081>`_ for more details.