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 `__