Fix parsing api version with correct service_type

Masakari project service_type is `instance-ha` but it reads
the api_version from `OpenStack-API-Version` request header
using service_type `masakari`.

This patch fixes this issue by changing service_type from
`masakari` to `instance-ha`.

Closes-Bug: #1816941
Change-Id: Ife141f9eab438e21f02966f3d27a6f044d4aa4ac
This commit is contained in:
shilpa.devharakar 2019-02-21 07:15:35 +00:00
parent de2f4d637d
commit 324e1794f9
2 changed files with 9 additions and 3 deletions

View File

@ -183,7 +183,7 @@ class Request(wsgi.Request):
def set_api_version_request(self):
"""Set API version request based on the request header information."""
hdr_string = microversion_parse.get_version(
self.headers, service_type='masakari')
self.headers, service_type='instance-ha')
if hdr_string is None:
self.api_version_request = api_version.APIVersionRequest(
@ -1059,7 +1059,7 @@ class Fault(webob.exc.HTTPException):
if not req.api_version_request.is_null():
self.wrapped_exc.headers[API_VERSION_REQUEST_HEADER] = \
'masakari ' + req.api_version_request.get_string()
'instance-ha ' + req.api_version_request.get_string()
self.wrapped_exc.headers.add('Vary', API_VERSION_REQUEST_HEADER)
self.wrapped_exc.content_type = 'application/json'

View File

@ -37,7 +37,7 @@ class MicroversionedTest(testscenarios.WithScenarios, test.NoDBTestCase):
header_name = 'OpenStack-API-Version'
def _make_microversion_header(self, value):
return {self.header_name: value}
return {self.header_name: 'instance-ha %s' % value}
class RequestTest(MicroversionedTest):
@ -138,6 +138,12 @@ class RequestTest(MicroversionedTest):
self.assertEqual(api_version.APIVersionRequest("1.0"),
request.api_version_request)
def test_api_version_request_header_invalid(self):
request = wsgi.Request.blank('/')
request.headers = self._make_microversion_header('1.1.1')
self.assertRaises(exception.InvalidAPIVersionString,
request.set_api_version_request)
class ActionDispatcherTest(test.NoDBTestCase):
def test_dispatch(self):