From 30842faeaa52d40f6a00765e797e3a173a15f441 Mon Sep 17 00:00:00 2001 From: dineshbhor Date: Thu, 20 Apr 2017 18:13:45 +0530 Subject: [PATCH] Fix response of microversions API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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://: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 Co-Authored-By: suzhengwei Co-Authored-By: Radosław Piliszek Change-Id: If3943060b5d09bd153b6401d34c7d10d3dc864fe --- masakari/api/openstack/ha/versions.py | 5 +- masakari/api/openstack/ha/versionsV1.py | 10 ++-- .../unit/api/openstack/ha/test_versions.py | 47 ++++++++++++++++--- .../notes/bug-1685145-3d93145bfc76c660.yaml | 6 +++ .../notes/bug-1882516-e8dc7fd2b55f065f.yaml | 6 +++ 5 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/bug-1685145-3d93145bfc76c660.yaml create mode 100644 releasenotes/notes/bug-1882516-e8dc7fd2b55f065f.yaml diff --git a/masakari/api/openstack/ha/versions.py b/masakari/api/openstack/ha/versions.py index b11bd4b3..755004db 100644 --- a/masakari/api/openstack/ha/versions.py +++ b/masakari/api/openstack/ha/versions.py @@ -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": [ { diff --git a/masakari/api/openstack/ha/versionsV1.py b/masakari/api/openstack/ha/versionsV1.py index d7b25369..5d2365bd 100644 --- a/masakari/api/openstack/ha/versionsV1.py +++ b/masakari/api/openstack/ha/versionsV1.py @@ -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("", "/") diff --git a/masakari/tests/unit/api/openstack/ha/test_versions.py b/masakari/tests/unit/api/openstack/ha/test_versions.py index 03586c95..418ffc73 100644 --- a/masakari/tests/unit/api/openstack/ha/test_versions.py +++ b/masakari/tests/unit/api/openstack/ha/test_versions.py @@ -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): diff --git a/releasenotes/notes/bug-1685145-3d93145bfc76c660.yaml b/releasenotes/notes/bug-1685145-3d93145bfc76c660.yaml new file mode 100644 index 00000000..ad9faf7d --- /dev/null +++ b/releasenotes/notes/bug-1685145-3d93145bfc76c660.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes ``/v1/`` API path which returned 404 ResourceNotFound preventing + microversion discovery. + `LP#1685145 `__ diff --git a/releasenotes/notes/bug-1882516-e8dc7fd2b55f065f.yaml b/releasenotes/notes/bug-1882516-e8dc7fd2b55f065f.yaml new file mode 100644 index 00000000..61253af8 --- /dev/null +++ b/releasenotes/notes/bug-1882516-e8dc7fd2b55f065f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes API microversion reporting to report the latest supported + microversion. + `LP#1882516 `__