Fix response of microversions API

If you request to show details of versions "v1/" API it returns 404
ResourceNotFound.

This patch fixes this issue by updating the v1 version correctly
as "v1.0" in versions controller which helps wsgi layer to find
the resource(controller) correctly. This way it returns the details
of version "v1" correctly instead of ResourceNotFound.

v1 show API response:

{"version": {"status": "CURRENT", "updated": "2016-07-01T11:33:21Z",
"links": [{"href": "http://<host-ip>:15868/v1/", "rel": "self"},
{"href": "http://docs.openstack.org/", "type": "text/html",
"rel": "describedby"}], "min_version": "1.0", "version": "1.0",
"media-types": [{"base": "application/json",
"type": "application/vnd.openstack.masakari+json;version=1"}],
"id": "v1.0"}}

This patch fixes the reported supported microversion as well
to avoid clients failing due to requesting too new version
(LP#1882516). It has to be fixed to pass tests.

APIImpact - versions "v1/" show API will return 200 OK now instead
of 404 ResourceNotFound.

Closes-Bug: #1685145
Closes-Bug: #1882516
Co-Authored-By: Jegor van Opdorp <jegor@leaf.cloud>
Co-Authored-By: suzhengwei <sugar-2008@163.com>
Co-Authored-By: Radosław Piliszek <radoslaw.piliszek@gmail.com>
Change-Id: If3943060b5d09bd153b6401d34c7d10d3dc864fe
This commit is contained in:
dineshbhor
2017-04-20 18:13:45 +05:30
committed by Radosław Piliszek
parent 9d3ffd7363
commit 30842faeaa
5 changed files with 63 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ from http import HTTPStatus
from oslo_config import cfg
from masakari.api import api_version_request
from masakari.api.openstack.ha.views import versions as views_versions
from masakari.api.openstack import wsgi
@@ -33,8 +34,8 @@ VERSIONS = {
"v1.0": {
"id": "v1.0",
"status": "CURRENT",
"version": "1.0",
"min_version": "1.0",
"version": api_version_request._MAX_API_VERSION,
"min_version": api_version_request._MIN_API_VERSION,
"updated": "2016-07-01T11:33:21Z",
"links": [
{

View File

@@ -28,7 +28,7 @@ ALIAS = "versions"
class VersionsController(wsgi.Controller):
@extensions.expected_errors(HTTPStatus.NOT_FOUND)
def show(self, req, id='v1'):
def show(self, req, id='v1.0'):
builder = views_versions.get_view_builder(req)
if id not in versions.VERSIONS:
raise webob.exc.HTTPNotFound()
@@ -53,7 +53,11 @@ class Versions(extensions.V1APIExtensionBase):
return []
def version_map(self, mapper, wsgi_resource):
mapper.connect("versions", "/",
self.map_path(mapper, wsgi_resource, '/')
self.map_path(mapper, wsgi_resource, '')
@staticmethod
def map_path(mapper, wsgi_resource, path):
mapper.connect("versions", path,
controller=wsgi_resource,
action='show', conditions={"method": ['GET']})
mapper.redirect("", "/")

View File

@@ -213,14 +213,49 @@ class VersionsTest(test.NoDBTestCase):
def wsgi_app(self):
return fakes.wsgi_app_v1(init_only=('versions',))
@mock.patch('masakari.rpc.get_client')
def test_get_version_list_302(self, mock_get_client):
req = webob.Request.blank('/v1')
def _test_v1(self, path):
req = webob.Request.blank(path)
req.accept = "application/json"
res = req.get_response(self.wsgi_app)
self.assertEqual(http.FOUND, res.status_int)
redirect_req = webob.Request.blank('/v1/')
self.assertEqual(redirect_req.url, res.location)
self.assertEqual(200, res.status_int)
self.assertEqual("application/json", res.content_type)
version = jsonutils.loads(res.body)
expected = {
"version": {
"id": "v1.0",
"status": "CURRENT",
"version": "1.2",
"min_version": "1.0",
"updated": "2016-07-01T11:33:21Z",
"links": [
{
"rel": "self",
"href": "http://localhost/v1/",
},
{
"rel": "describedby",
"type": "text/html",
"href": "https://docs.openstack.org/",
},
],
"media-types": [
{
"base": "application/json",
"type": "application/"
"vnd.openstack.masakari+json;version=1",
},
],
},
}
self.assertEqual(expected, version)
@mock.patch('masakari.rpc.get_client')
def test_get_version_1_detail(self, mock_get_client):
self._test_v1('/v1/')
@mock.patch('masakari.rpc.get_client')
def test_get_version_1_detail_no_slash(self, mock_get_client):
self._test_v1('/v1')
@mock.patch('masakari.rpc.get_client')
def test_get_version_1_versions_invalid(self, mock_get_client):

View File

@@ -0,0 +1,6 @@
---
fixes:
- |
Fixes ``/v1/`` API path which returned 404 ResourceNotFound preventing
microversion discovery.
`LP#1685145 <https://launchpad.net/bugs/1685145>`__

View File

@@ -0,0 +1,6 @@
---
fixes:
- |
Fixes API microversion reporting to report the latest supported
microversion.
`LP#1882516 <https://launchpad.net/bugs/1882516>`__