Enable Glare API 1.1

This commit marks 1.0 API as stable and 1.1 as experimental

Change-Id: Idd5644a6f338656d4b4ca59ce62f26860e9d20a3
This commit is contained in:
Mike Fedosin 2017-08-27 20:17:07 +03:00
parent 1281a8b4db
commit 2a71c7888a
5 changed files with 77 additions and 67 deletions

View File

@ -67,9 +67,7 @@ class GlareVersionNegotiationFilter(base_middleware.ConfigurableMiddleware):
# determine if this is request for versions # determine if this is request for versions
if req.path_info in ('/versions', '/'): if req.path_info in ('/versions', '/'):
is_multi = req.path_info == '/' return artifacts_versions.Controller.index(req)
return artifacts_versions.Controller.index(
req, is_multi=is_multi)
# determine api version from request # determine api version from request
req_version = GlareVersionNegotiationFilter.get_version_from_accept( req_version = GlareVersionNegotiationFilter.get_version_from_accept(

View File

@ -20,6 +20,10 @@ from glare.i18n import _
REST_API_VERSION_HISTORY = """REST API Version History: REST_API_VERSION_HISTORY = """REST API Version History:
* 1.1 Added dynamic quotas API request. Added a possibility to delete blobs
with external locations. Added a possibility to define system locations to
blobs.
* 1.0 - First stable API version that supports microversion. If API version * 1.0 - First stable API version that supports microversion. If API version
is not specified in the request then API v1.0 is used as default API is not specified in the request then API v1.0 is used as default API
version. version.
@ -33,7 +37,7 @@ class APIVersionRequest(object):
""" """
_MIN_API_VERSION = "1.0" _MIN_API_VERSION = "1.0"
_MAX_API_VERSION = "1.0" _MAX_API_VERSION = "1.1"
_DEFAULT_API_VERSION = "1.0" _DEFAULT_API_VERSION = "1.0"
def __init__(self, version_string): def __init__(self, version_string):

View File

@ -18,7 +18,6 @@ from oslo_serialization import jsonutils
from six.moves import http_client from six.moves import http_client
import webob.dec import webob.dec
from glare.api.v1 import api_version_request
from glare.i18n import _ from glare.i18n import _
@ -52,45 +51,39 @@ Related options:
CONF = cfg.CONF CONF = cfg.CONF
CONF.register_opts(versions_opts) CONF.register_opts(versions_opts)
_LINKS = [{
"rel": "describedby",
"type": "text/html",
"href": "http://docs.openstack.org/",
}]
class Controller(object): class Controller(object):
"""A controller that reports which API versions are supported.""" """A controller that reports which API versions are there."""
@staticmethod @staticmethod
def index(req, is_multi): def index(req):
"""Respond to a request for all OpenStack API versions. """Respond to a request for all OpenStack Glare API versions.
:param is_multi: defines if multiple choices should be response status
or not
:param req: user request object :param req: user request object
:return: list of supported API versions :return: list of supported API versions
""" """
def build_version_object(max_version, min_version, status, path=None): version_objs = [
url = CONF.public_endpoint or req.host_url {
return { 'version': '1.0',
'id': 'v%s' % max_version, 'status': 'STABLE',
'links': [ 'links': _LINKS,
{ 'media-type': 'application/vnd.openstack.artifacts-1.0',
'rel': 'self', },
'href': '%s/%s/' % (url, path) if path else {
'%s/' % url, 'version': '1.1',
}, 'status': 'EXPERIMENTAL',
], 'links': _LINKS,
'status': status, 'media-type': 'application/vnd.openstack.artifacts-1.1',
'min_version': min_version, }]
'version': max_version
}
microv_max = api_version_request.APIVersionRequest.max_version()
microv_min = api_version_request.APIVersionRequest.min_version()
version_objs = [build_version_object(microv_max.get_string(),
microv_min.get_string(),
'EXPERIMENTAL')]
return_status = (http_client.MULTIPLE_CHOICES if is_multi else
http_client.OK)
response = webob.Response(request=req, response = webob.Response(request=req,
status=return_status, status=http_client.MULTIPLE_CHOICES,
content_type='application/json') content_type='application/json')
response.body = jsonutils.dump_as_bytes(dict(versions=version_objs)) response.body = jsonutils.dump_as_bytes(dict(versions=version_objs))
return response return response

View File

@ -31,14 +31,24 @@ class TestContextMiddleware(base.BaseTestCase):
return version_negotiation.GlareVersionNegotiationFilter(None) return version_negotiation.GlareVersionNegotiationFilter(None)
def test_version_request(self): def test_version_request(self):
_LINKS = [{
"rel": "describedby",
"type": "text/html",
"href": "http://docs.openstack.org/",
}]
for path_info in ('/', '/versions'): for path_info in ('/', '/versions'):
expected = { expected = {'versions': [
"versions": [{ {
"status": "EXPERIMENTAL", 'version': '1.0',
"min_version": "1.0", 'status': 'STABLE',
"version": "1.0", 'links': _LINKS,
"id": "v1.0", 'media-type': 'application/vnd.openstack.artifacts-1.0',
"links": [{"href": "http://localhost/", "rel": "self"}] },
{
'version': '1.1',
'status': 'EXPERIMENTAL',
'links': _LINKS,
'media-type': 'application/vnd.openstack.artifacts-1.1',
}] }]
} }
req = self._build_request(self.MIME_TYPE + '1.0', path_info) req = self._build_request(self.MIME_TYPE + '1.0', path_info)
@ -58,7 +68,7 @@ class TestContextMiddleware(base.BaseTestCase):
def test_latest_version(self): def test_latest_version(self):
req = self._build_request(self.MIME_TYPE + 'latest', '/artifacts') req = self._build_request(self.MIME_TYPE + 'latest', '/artifacts')
self._build_middleware().process_request(req) self._build_middleware().process_request(req)
self.assertEqual('1.0', req.api_version_request.get_string()) self.assertEqual('1.1', req.api_version_request.get_string())
def test_version_unknown(self): def test_version_unknown(self):
req = self._build_request('UNKNOWN', '/artifacts') req = self._build_request('UNKNOWN', '/artifacts')

View File

@ -24,42 +24,47 @@ class VersionsTest(base.BaseTestCase):
"""Test the version information returned from the API service.""" """Test the version information returned from the API service."""
def test_get_version_list(self): def test_root_endpoint(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:9494/') req = webob.Request.blank('/', base_url='http://127.0.0.1:9494/')
req.accept = 'application/json' req.accept = 'application/json'
res = versions.Controller().index(req, is_multi=True) res = versions.Controller().index(req)
self.assertEqual(300, res.status_int) self.assertEqual(300, res.status_int)
self.assertEqual('application/json', res.content_type) self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions'] results = jsonutils.loads(res.body)['versions']
expected = [ expected = [
{ {'links': [{'href': 'http://docs.openstack.org/',
'id': 'v1.0', 'rel': 'describedby',
'status': 'EXPERIMENTAL', 'type': 'text/html'}],
'links': [{'rel': 'self', 'media-type': 'application/vnd.openstack.artifacts-1.0',
'href': 'http://127.0.0.1:9494/'}], 'status': 'STABLE',
'min_version': '1.0', 'version': '1.0'},
'version': '1.0' {'links': [{'href': 'http://docs.openstack.org/',
} 'rel': 'describedby',
] 'type': 'text/html'}],
'media-type': 'application/vnd.openstack.artifacts-1.1',
'status': 'EXPERIMENTAL',
'version': '1.1'}]
self.assertEqual(expected, results) self.assertEqual(expected, results)
def test_get_version_list_public_endpoint(self): def test_versions_endpoint(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:9494/') req = webob.Request.blank('/versions',
base_url='http://127.0.0.1:9494/')
req.accept = 'application/json' req.accept = 'application/json'
self.config(bind_host='127.0.0.1', bind_port=9494, res = versions.Controller().index(req)
public_endpoint='https://example.com:9494')
res = versions.Controller().index(req, is_multi=True)
self.assertEqual(300, res.status_int) self.assertEqual(300, res.status_int)
self.assertEqual('application/json', res.content_type) self.assertEqual('application/json', res.content_type)
results = jsonutils.loads(res.body)['versions'] results = jsonutils.loads(res.body)['versions']
expected = [ expected = [
{ {'links': [{'href': 'http://docs.openstack.org/',
'id': 'v1.0', 'rel': 'describedby',
'status': 'EXPERIMENTAL', 'type': 'text/html'}],
'links': [{'rel': 'self', 'media-type': 'application/vnd.openstack.artifacts-1.0',
'href': 'https://example.com:9494/'}], 'status': 'STABLE',
'min_version': '1.0', 'version': '1.0'},
'version': '1.0' {'links': [{'href': 'http://docs.openstack.org/',
} 'rel': 'describedby',
] 'type': 'text/html'}],
'media-type': 'application/vnd.openstack.artifacts-1.1',
'status': 'EXPERIMENTAL',
'version': '1.1'}]
self.assertEqual(expected, results) self.assertEqual(expected, results)