Merge "Make versions aware of enabled pipelines."

This commit is contained in:
Jenkins 2013-03-21 21:29:23 +00:00 committed by Gerrit Code Review
commit 747b457bb0
4 changed files with 143 additions and 58 deletions

View File

@ -19,13 +19,14 @@ from keystone.common import logging
from keystone import config from keystone import config
from keystone import exception from keystone import exception
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
CONF = config.CONF CONF = config.CONF
MEDIA_TYPE_JSON = 'application/vnd.openstack.identity-%s+json' MEDIA_TYPE_JSON = 'application/vnd.openstack.identity-%s+json'
MEDIA_TYPE_XML = 'application/vnd.openstack.identity-%s+xml' MEDIA_TYPE_XML = 'application/vnd.openstack.identity-%s+xml'
_VERSIONS = []
class Extensions(wsgi.Application): class Extensions(wsgi.Application):
"""Base extensions controller to be extended by public and admin API's.""" """Base extensions controller to be extended by public and admin API's."""
@ -76,7 +77,12 @@ class PublicExtensions(Extensions):
pass pass
def register_version(version):
_VERSIONS.append(version)
class Version(wsgi.Application): class Version(wsgi.Application):
def __init__(self, version_type): def __init__(self, version_type):
self.endpoint_url_type = version_type self.endpoint_url_type = version_type
@ -92,57 +98,60 @@ class Version(wsgi.Application):
def _get_versions_list(self, context): def _get_versions_list(self, context):
"""The list of versions is dependent on the context.""" """The list of versions is dependent on the context."""
versions = {} versions = {}
versions['v2.0'] = { if 'v2.0' in _VERSIONS:
'id': 'v2.0', versions['v2.0'] = {
'status': 'stable', 'id': 'v2.0',
'updated': '2013-03-06T00:00:00Z', 'status': 'stable',
'links': [ 'updated': '2013-03-06T00:00:00Z',
{ 'links': [
'rel': 'self', {
'href': self._get_identity_url(version='v2.0'), 'rel': 'self',
}, { 'href': self._get_identity_url(version='v2.0'),
'rel': 'describedby', }, {
'type': 'text/html', 'rel': 'describedby',
'href': 'http://docs.openstack.org/api/openstack-' 'type': 'text/html',
'identity-service/2.0/content/' 'href': 'http://docs.openstack.org/api/openstack-'
}, { 'identity-service/2.0/content/'
'rel': 'describedby', }, {
'type': 'application/pdf', 'rel': 'describedby',
'href': 'http://docs.openstack.org/api/openstack-' 'type': 'application/pdf',
'identity-service/2.0/identity-dev-guide-' 'href': 'http://docs.openstack.org/api/openstack-'
'2.0.pdf' 'identity-service/2.0/identity-dev-guide-'
} '2.0.pdf'
], }
'media-types': [ ],
{ 'media-types': [
'base': 'application/json', {
'type': MEDIA_TYPE_JSON % 'v2.0' 'base': 'application/json',
}, { 'type': MEDIA_TYPE_JSON % 'v2.0'
'base': 'application/xml', }, {
'type': MEDIA_TYPE_XML % 'v2.0' 'base': 'application/xml',
} 'type': MEDIA_TYPE_XML % 'v2.0'
] }
} ]
versions['v3'] = { }
'id': 'v3.0',
'status': 'stable', if 'v3' in _VERSIONS:
'updated': '2013-03-06T00:00:00Z', versions['v3'] = {
'links': [ 'id': 'v3.0',
{ 'status': 'stable',
'rel': 'self', 'updated': '2013-03-06T00:00:00Z',
'href': self._get_identity_url(version='v3'), 'links': [
} {
], 'rel': 'self',
'media-types': [ 'href': self._get_identity_url(version='v3'),
{ }
'base': 'application/json', ],
'type': MEDIA_TYPE_JSON % 'v3' 'media-types': [
}, { {
'base': 'application/xml', 'base': 'application/json',
'type': MEDIA_TYPE_XML % 'v3' 'type': MEDIA_TYPE_JSON % 'v3'
} }, {
] 'base': 'application/xml',
} 'type': MEDIA_TYPE_XML % 'v3'
}
]
}
return versions return versions
@ -156,12 +165,18 @@ class Version(wsgi.Application):
def get_version_v2(self, context): def get_version_v2(self, context):
versions = self._get_versions_list(context) versions = self._get_versions_list(context)
return wsgi.render_response(body={ if 'v2.0' in _VERSIONS:
'version': versions['v2.0'] return wsgi.render_response(body={
}) 'version': versions['v2.0']
})
else:
raise exception.VersionNotFound(version='v2.0')
def get_version_v3(self, context): def get_version_v3(self, context):
versions = self._get_versions_list(context) versions = self._get_versions_list(context)
return wsgi.render_response(body={ if 'v3' in _VERSIONS:
'version': versions['v3'] return wsgi.render_response(body={
}) 'version': versions['v3']
})
else:
raise exception.VersionNotFound(version='v3')

View File

@ -204,6 +204,10 @@ class CredentialNotFound(NotFound):
"""Could not find credential: %(credential_id)s""" """Could not find credential: %(credential_id)s"""
class VersionNotFound(NotFound):
"""Could not find version: %(version)s"""
class Conflict(Error): class Conflict(Error):
"""Conflict occurred attempting to store %(type)s. """Conflict occurred attempting to store %(type)s.

View File

@ -19,6 +19,7 @@ import routes
from keystone import auth from keystone import auth
from keystone import catalog from keystone import catalog
from keystone import config from keystone import config
from keystone import controllers
from keystone.common import logging from keystone.common import logging
from keystone.common import wsgi from keystone.common import wsgi
from keystone.contrib import ec2 from keystone.contrib import ec2
@ -43,6 +44,7 @@ DRIVERS = dict(
@logging.fail_gracefully @logging.fail_gracefully
def public_app_factory(global_conf, **local_conf): def public_app_factory(global_conf, **local_conf):
controllers.register_version('v2.0')
conf = global_conf.copy() conf = global_conf.copy()
conf.update(local_conf) conf.update(local_conf)
return wsgi.ComposingRouter(routes.Mapper(), return wsgi.ComposingRouter(routes.Mapper(),
@ -81,6 +83,7 @@ def admin_version_app_factory(global_conf, **local_conf):
@logging.fail_gracefully @logging.fail_gracefully
def v3_app_factory(global_conf, **local_conf): def v3_app_factory(global_conf, **local_conf):
controllers.register_version('v3')
conf = global_conf.copy() conf = global_conf.copy()
conf.update(local_conf) conf.update(local_conf)
mapper = routes.Mapper() mapper = routes.Mapper()

View File

@ -16,6 +16,7 @@
# limitations under the License. # limitations under the License.
from keystone import config from keystone import config
from keystone import controllers
from keystone.openstack.common import jsonutils from keystone.openstack.common import jsonutils
from keystone import test from keystone import test
@ -193,3 +194,65 @@ class VersionTestCase(test.TestCase):
self._paste_in_port(expected['version'], self._paste_in_port(expected['version'],
'http://localhost:%s/v3/' % CONF.admin_port) 'http://localhost:%s/v3/' % CONF.admin_port)
self.assertEqual(data, expected) self.assertEqual(data, expected)
def test_v2_disabled(self):
self.stubs.Set(controllers, '_VERSIONS', ['v3'])
client = self.client(self.public_app)
# request to /v2.0 should fail
resp = client.get('/v2.0/')
self.assertEqual(resp.status_int, 404)
# request to /v3 should pass
resp = client.get('/v3/')
self.assertEqual(resp.status_int, 200)
data = jsonutils.loads(resp.body)
expected = v3_VERSION_RESPONSE
self._paste_in_port(expected['version'],
'http://localhost:%s/v3/' % CONF.public_port)
self.assertEqual(data, expected)
# only v3 information should be displayed by requests to /
v3_only_response = {
"versions": {
"values": [
v3_EXPECTED_RESPONSE
]
}
}
self._paste_in_port(v3_only_response['versions']['values'][0],
'http://localhost:%s/v3/' % CONF.public_port)
resp = client.get('/')
self.assertEqual(resp.status_int, 300)
data = jsonutils.loads(resp.body)
self.assertEqual(data, v3_only_response)
def test_v3_disabled(self):
self.stubs.Set(controllers, '_VERSIONS', ['v2.0'])
client = self.client(self.public_app)
# request to /v3 should fail
resp = client.get('/v3/')
self.assertEqual(resp.status_int, 404)
# request to /v2.0 should pass
resp = client.get('/v2.0/')
self.assertEqual(resp.status_int, 200)
data = jsonutils.loads(resp.body)
expected = v2_VERSION_RESPONSE
self._paste_in_port(expected['version'],
'http://localhost:%s/v2.0/' % CONF.public_port)
self.assertEqual(data, expected)
# only v2 information should be displayed by requests to /
v2_only_response = {
"versions": {
"values": [
v2_EXPECTED_RESPONSE
]
}
}
self._paste_in_port(v2_only_response['versions']['values'][0],
'http://localhost:%s/v2.0/' % CONF.public_port)
resp = client.get('/')
self.assertEqual(resp.status_int, 300)
data = jsonutils.loads(resp.body)
self.assertEqual(data, v2_only_response)