diff --git a/tests/functional/wsgi/test_version.py b/tests/functional/wsgi/test_version.py new file mode 100644 index 000000000..10ad76ead --- /dev/null +++ b/tests/functional/wsgi/test_version.py @@ -0,0 +1,69 @@ +# Copyright (c) 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import falcon +from oslo.serialization import jsonutils + +from zaqar.tests.unit.transport.wsgi import base + +EXPECTED_VERSIONS = [ + { + 'id': '1', + 'status': 'SUPPORTED', + 'updated': '2014-9-11T17:47:05Z', + 'media-types': [ + { + 'base': 'application/json', + 'type': 'application/vnd.openstack.messaging-v1+json' + } + ], + 'links': [ + { + 'href': '/v1/', + 'rel': 'self' + } + ] + }, + { + 'id': '1.1', + 'status': 'CURRENT', + 'updated': '2014-9-24T04:06:47Z', + 'media-types': [ + { + 'base': 'application/json', + 'type': 'application/vnd.openstack.messaging-v1_1+json' + } + ], + 'links': [ + { + 'href': '/v1.1/', + 'rel': 'self' + } + ] + } +] + + +class TestVersion(base.TestBase): + + config_file = 'wsgi_sqlalchemy.conf' + + def test_get(self): + response = self.simulate_get('/') + versions = jsonutils.loads(response[0])['versions'] + + self.assertEqual(self.srmock.status, falcon.HTTP_300) + self.assertEqual(len(versions), 2) + self.assertEqual(EXPECTED_VERSIONS, versions) diff --git a/zaqar/transport/wsgi/driver.py b/zaqar/transport/wsgi/driver.py index f4161b6bd..586d586b5 100644 --- a/zaqar/transport/wsgi/driver.py +++ b/zaqar/transport/wsgi/driver.py @@ -28,6 +28,7 @@ from zaqar.transport import auth from zaqar.transport import validation from zaqar.transport.wsgi import v1_0 from zaqar.transport.wsgi import v1_1 +from zaqar.transport.wsgi import version _WSGI_OPTIONS = ( cfg.StrOpt('bind', default='127.0.0.1', @@ -82,6 +83,7 @@ class Driver(transport.DriverBase): catalog = [ ('/v1', v1_0.public_endpoints(self, self._conf)), ('/v1.1', v1_1.public_endpoints(self, self._conf)), + ('/', [('', version.Resource())]) ] if self._conf.admin_mode: diff --git a/zaqar/transport/wsgi/v1_0/__init__.py b/zaqar/transport/wsgi/v1_0/__init__.py index bda7ed2c0..c3093ef79 100644 --- a/zaqar/transport/wsgi/v1_0/__init__.py +++ b/zaqar/transport/wsgi/v1_0/__init__.py @@ -21,6 +21,24 @@ from zaqar.transport.wsgi.v1_0 import pools from zaqar.transport.wsgi.v1_0 import queues from zaqar.transport.wsgi.v1_0 import stats +VERSION = { + 'id': '1', + 'status': 'SUPPORTED', + 'updated': '2014-9-11T17:47:05Z', + 'media-types': [ + { + 'base': 'application/json', + 'type': 'application/vnd.openstack.messaging-v1+json' + } + ], + 'links': [ + { + 'href': '/v1/', + 'rel': 'self' + } + ] +} + def public_endpoints(driver, conf): queue_controller = driver._storage.queue_controller diff --git a/zaqar/transport/wsgi/v1_1/__init__.py b/zaqar/transport/wsgi/v1_1/__init__.py index 8815094be..89c317820 100644 --- a/zaqar/transport/wsgi/v1_1/__init__.py +++ b/zaqar/transport/wsgi/v1_1/__init__.py @@ -22,6 +22,24 @@ from zaqar.transport.wsgi.v1_1 import pools from zaqar.transport.wsgi.v1_1 import queues from zaqar.transport.wsgi.v1_1 import stats +VERSION = { + 'id': '1.1', + 'status': 'CURRENT', + 'updated': '2014-9-24T04:06:47Z', + 'media-types': [ + { + 'base': 'application/json', + 'type': 'application/vnd.openstack.messaging-v1_1+json' + } + ], + 'links': [ + { + 'href': '/v1.1/', + 'rel': 'self' + } + ] +} + def public_endpoints(driver, conf): queue_controller = driver._storage.queue_controller diff --git a/zaqar/transport/wsgi/version.py b/zaqar/transport/wsgi/version.py new file mode 100644 index 000000000..b31bf13dc --- /dev/null +++ b/zaqar/transport/wsgi/version.py @@ -0,0 +1,37 @@ +# Copyright (c) 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +import falcon + +from zaqar.transport import utils +from zaqar.transport.wsgi import v1_0 +from zaqar.transport.wsgi import v1_1 + +VERSIONS = { + 'versions': [ + v1_0.VERSION, + v1_1.VERSION + ] +} + + +class Resource(object): + + def __init__(self): + self.versions = utils.to_json(VERSIONS) + + def on_get(self, req, resp, project_id): + resp.data = self.versions + + resp.status = falcon.HTTP_300