Merge "Fix Image API 'versions' response"
This commit is contained in:
commit
362d187eaa
|
@ -84,7 +84,8 @@ class VersionNegotiationFilter(wsgi.Middleware):
|
|||
allowed_versions['v2.3'] = 2
|
||||
allowed_versions['v2.4'] = 2
|
||||
allowed_versions['v2.5'] = 2
|
||||
allowed_versions['v2.6'] = 2
|
||||
if CONF.enable_image_import:
|
||||
allowed_versions['v2.6'] = 2
|
||||
return allowed_versions
|
||||
|
||||
def _match_version_string(self, subject):
|
||||
|
|
|
@ -73,8 +73,10 @@ class Controller(object):
|
|||
|
||||
version_objs = []
|
||||
if CONF.enable_v2_api:
|
||||
if CONF.enable_image_import:
|
||||
version_objs.append(
|
||||
build_version_object(2.6, 'v2', 'EXPERIMENTAL'))
|
||||
version_objs.extend([
|
||||
build_version_object(2.6, 'v2', 'EXPERIMENTAL'),
|
||||
build_version_object(2.5, 'v2', 'CURRENT'),
|
||||
build_version_object(2.4, 'v2', 'SUPPORTED'),
|
||||
build_version_object(2.3, 'v2', 'SUPPORTED'),
|
||||
|
|
|
@ -77,6 +77,9 @@ class Server(object):
|
|||
self.property_protection_file = ''
|
||||
self.enable_v1_api = True
|
||||
self.enable_v2_api = True
|
||||
# TODO(rosmaita): remove in Queens when the option is removed
|
||||
# also, don't forget to remove it from ApiServer.conf_base
|
||||
self.enable_image_import = False
|
||||
self.enable_v1_registry = True
|
||||
self.enable_v2_registry = True
|
||||
self.needs_database = False
|
||||
|
@ -348,6 +351,7 @@ show_multiple_locations = %(show_multiple_locations)s
|
|||
user_storage_quota = %(user_storage_quota)s
|
||||
enable_v1_api = %(enable_v1_api)s
|
||||
enable_v2_api = %(enable_v2_api)s
|
||||
enable_image_import = %(enable_image_import)s
|
||||
lock_path = %(lock_path)s
|
||||
property_protection_file = %(property_protection_file)s
|
||||
property_protection_rule_format = %(property_protection_rule_format)s
|
||||
|
|
|
@ -22,6 +22,77 @@ from six.moves import http_client
|
|||
|
||||
from glance.tests import functional
|
||||
|
||||
# TODO(rosmaita): all the EXPERIMENTAL stuff in this file can be ripped out
|
||||
# when v2.6 becomes CURRENT in Queens
|
||||
|
||||
|
||||
def _generate_v1_versions(url):
|
||||
v1_versions = {'versions': [
|
||||
{
|
||||
'id': 'v1.1',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self', 'href': url % '1'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.0',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self', 'href': url % '1'}],
|
||||
},
|
||||
]}
|
||||
return v1_versions
|
||||
|
||||
|
||||
def _generate_v2_versions(url, include_experimental=False):
|
||||
version_list = []
|
||||
if include_experimental:
|
||||
version_list.append(
|
||||
{
|
||||
'id': 'v2.6',
|
||||
'status': 'EXPERIMENTAL',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
})
|
||||
version_list.extend([
|
||||
{
|
||||
'id': 'v2.5',
|
||||
'status': 'CURRENT',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.4',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.3',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.2',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.1',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.0',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
}
|
||||
])
|
||||
v2_versions = {'versions': version_list}
|
||||
return v2_versions
|
||||
|
||||
|
||||
def _generate_all_versions(url, include_experimental=False):
|
||||
v1 = _generate_v1_versions(url)
|
||||
v2 = _generate_v2_versions(url, include_experimental)
|
||||
all_versions = {'versions': v2['versions'] + v1['versions']}
|
||||
return all_versions
|
||||
|
||||
|
||||
class TestApiVersions(functional.FunctionalTest):
|
||||
|
||||
|
@ -31,53 +102,25 @@ class TestApiVersions(functional.FunctionalTest):
|
|||
self.start_servers(**self.__dict__.copy())
|
||||
|
||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||
versions = {'versions': [
|
||||
{
|
||||
'id': 'v2.6',
|
||||
'status': 'EXPERIMENTAL',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.5',
|
||||
'status': 'CURRENT',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.4',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.3',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.2',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.1',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.0',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.1',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self', 'href': url % '1'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.0',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self', 'href': url % '1'}],
|
||||
},
|
||||
]}
|
||||
versions = _generate_all_versions(url)
|
||||
|
||||
# Verify version choices returned.
|
||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content_json = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(versions, content)
|
||||
|
||||
def test_version_configurations_EXPERIMENTAL(self):
|
||||
"""Test that versioning is handled properly through all channels"""
|
||||
self.api_server.enable_v1_api = True
|
||||
self.api_server.enable_v2_api = True
|
||||
self.api_server.enable_image_import = True
|
||||
self.start_servers(**self.__dict__.copy())
|
||||
|
||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||
versions = _generate_all_versions(url, include_experimental=True)
|
||||
|
||||
# Verify version choices returned.
|
||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||
|
@ -93,43 +136,24 @@ class TestApiVersions(functional.FunctionalTest):
|
|||
self.start_servers(**self.__dict__.copy())
|
||||
|
||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||
versions = {'versions': [
|
||||
{
|
||||
'id': 'v2.6',
|
||||
'status': 'EXPERIMENTAL',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.5',
|
||||
'status': 'CURRENT',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.4',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.3',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.2',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.1',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.0',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
]}
|
||||
versions = _generate_v2_versions(url)
|
||||
|
||||
# Verify version choices returned.
|
||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content_json = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(versions, content)
|
||||
|
||||
def test_v2_api_configuration_EXPERIMENTAL(self):
|
||||
self.api_server.enable_v1_api = False
|
||||
self.api_server.enable_v2_api = True
|
||||
self.api_server.enable_image_import = True
|
||||
self.start_servers(**self.__dict__.copy())
|
||||
|
||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||
versions = _generate_v2_versions(url, include_experimental=True)
|
||||
|
||||
# Verify version choices returned.
|
||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||
|
@ -145,18 +169,26 @@ class TestApiVersions(functional.FunctionalTest):
|
|||
self.start_servers(**self.__dict__.copy())
|
||||
|
||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||
versions = {'versions': [
|
||||
{
|
||||
'id': 'v1.1',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self', 'href': url % '1'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.0',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self', 'href': url % '1'}],
|
||||
},
|
||||
]}
|
||||
versions = _generate_v1_versions(url)
|
||||
|
||||
# Verify version choices returned.
|
||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content_json = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(versions, content)
|
||||
|
||||
def test_v1_api_configuration_EXPERIMENTAL(self):
|
||||
# enabling image import should have no effect, but
|
||||
# nothing else should blow up, either
|
||||
self.api_server.enable_v1_api = True
|
||||
self.api_server.enable_v2_api = False
|
||||
self.api_server.enable_image_import = True
|
||||
self.start_servers(**self.__dict__.copy())
|
||||
|
||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||
versions = _generate_v1_versions(url)
|
||||
|
||||
# Verify version choices returned.
|
||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||
|
@ -173,53 +205,188 @@ class TestApiPaths(functional.FunctionalTest):
|
|||
self.start_servers(**self.__dict__.copy())
|
||||
|
||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||
self.versions = {'versions': [
|
||||
{
|
||||
'id': 'v2.6',
|
||||
'status': 'EXPERIMENTAL',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.5',
|
||||
'status': 'CURRENT',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.4',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.3',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.2',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.1',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.0',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self', 'href': url % '2'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.1',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self', 'href': url % '1'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.0',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self', 'href': url % '1'}],
|
||||
},
|
||||
]}
|
||||
self.versions = _generate_all_versions(url)
|
||||
images = {'images': []}
|
||||
self.images_json = jsonutils.dumps(images)
|
||||
|
||||
def test_get_root_path(self):
|
||||
"""Assert GET / with `no Accept:` header.
|
||||
Verify version choices returned.
|
||||
Bug lp:803260 no Accept header causes a 500 in glance-api
|
||||
"""
|
||||
path = 'http://%s:%d' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content_json = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
def test_get_images_path(self):
|
||||
"""Assert GET /images with `no Accept:` header.
|
||||
Verify version choices returned.
|
||||
"""
|
||||
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content_json = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
def test_get_v1_images_path(self):
|
||||
"""GET /v1/images with `no Accept:` header.
|
||||
Verify empty images list returned.
|
||||
"""
|
||||
path = 'http://%s:%d/v1/images' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.OK, response.status)
|
||||
|
||||
def test_get_root_path_with_unknown_header(self):
|
||||
"""Assert GET / with Accept: unknown header
|
||||
Verify version choices returned. Verify message in API log about
|
||||
unknown accept header.
|
||||
"""
|
||||
path = 'http://%s:%d/' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
headers = {'Accept': 'unknown'}
|
||||
response, content_json = http.request(path, 'GET', headers=headers)
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
def test_get_root_path_with_openstack_header(self):
|
||||
"""Assert GET / with an Accept: application/vnd.openstack.images-v1
|
||||
Verify empty image list returned
|
||||
"""
|
||||
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
||||
response, content = http.request(path, 'GET', headers=headers)
|
||||
self.assertEqual(http_client.OK, response.status)
|
||||
self.assertEqual(self.images_json, content.decode())
|
||||
|
||||
def test_get_images_path_with_openstack_header(self):
|
||||
"""Assert GET /images with a
|
||||
`Accept: application/vnd.openstack.compute-v1` header.
|
||||
Verify version choices returned. Verify message in API log
|
||||
about unknown accept header.
|
||||
"""
|
||||
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
headers = {'Accept': 'application/vnd.openstack.compute-v1'}
|
||||
response, content_json = http.request(path, 'GET', headers=headers)
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
def test_get_v10_images_path(self):
|
||||
"""Assert GET /v1.0/images with no Accept: header
|
||||
Verify version choices returned
|
||||
"""
|
||||
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
|
||||
def test_get_v1a_images_path(self):
|
||||
"""Assert GET /v1.a/images with no Accept: header
|
||||
Verify version choices returned
|
||||
"""
|
||||
path = 'http://%s:%d/v1.a/images' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
|
||||
def test_get_va1_images_path(self):
|
||||
"""Assert GET /va.1/images with no Accept: header
|
||||
Verify version choices returned
|
||||
"""
|
||||
path = 'http://%s:%d/va.1/images' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content_json = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
def test_get_versions_path(self):
|
||||
"""Assert GET /versions with no Accept: header
|
||||
Verify version choices returned
|
||||
"""
|
||||
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content_json = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.OK, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
def test_get_versions_path_with_openstack_header(self):
|
||||
"""Assert GET /versions with the
|
||||
`Accept: application/vnd.openstack.images-v1` header.
|
||||
Verify version choices returned.
|
||||
"""
|
||||
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
headers = {'Accept': 'application/vnd.openstack.images-v1'}
|
||||
response, content_json = http.request(path, 'GET', headers=headers)
|
||||
self.assertEqual(http_client.OK, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
def test_get_v1_versions_path(self):
|
||||
"""Assert GET /v1/versions with `no Accept:` header
|
||||
Verify 404 returned
|
||||
"""
|
||||
path = 'http://%s:%d/v1/versions' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.NOT_FOUND, response.status)
|
||||
|
||||
def test_get_versions_choices(self):
|
||||
"""Verify version choices returned"""
|
||||
path = 'http://%s:%d/v10' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content_json = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
def test_get_images_path_with_openstack_v2_header(self):
|
||||
"""Assert GET /images with a
|
||||
`Accept: application/vnd.openstack.compute-v2` header.
|
||||
Verify version choices returned. Verify message in API log
|
||||
about unknown version in accept header.
|
||||
"""
|
||||
path = 'http://%s:%d/images' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
headers = {'Accept': 'application/vnd.openstack.images-v10'}
|
||||
response, content_json = http.request(path, 'GET', headers=headers)
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
def test_get_v12_images_path(self):
|
||||
"""Assert GET /v1.2/images with `no Accept:` header
|
||||
Verify version choices returned
|
||||
"""
|
||||
path = 'http://%s:%d/v1.2/images' % ('127.0.0.1', self.api_port)
|
||||
http = httplib2.Http()
|
||||
response, content_json = http.request(path, 'GET')
|
||||
self.assertEqual(http_client.MULTIPLE_CHOICES, response.status)
|
||||
content = jsonutils.loads(content_json.decode())
|
||||
self.assertEqual(self.versions, content)
|
||||
|
||||
|
||||
# NOTE(rosmaita): yes, this is a lot of duplicated code from the above
|
||||
# class, but it will be much easier to rip out in Queens if we simply
|
||||
# do a copy-pasta now
|
||||
class TestApiPathsEXPERIMENTAL(functional.FunctionalTest):
|
||||
def setUp(self):
|
||||
super(TestApiPathsEXPERIMENTAL, self).setUp()
|
||||
self.api_server.enable_image_import = True
|
||||
self.start_servers(**self.__dict__.copy())
|
||||
|
||||
url = 'http://127.0.0.1:%d/v%%s/' % self.api_port
|
||||
self.versions = _generate_all_versions(url, include_experimental=True)
|
||||
images = {'images': []}
|
||||
self.images_json = jsonutils.dumps(images)
|
||||
|
||||
|
|
|
@ -23,10 +23,76 @@ from glance.common.wsgi import Request as WsgiRequest
|
|||
from glance.tests.unit import base
|
||||
|
||||
|
||||
# NOTE(rosmaita): rip out all the EXPERIMENTAL stuff when 2.6 becomes
|
||||
# CURRENT in Queens (or figure out a better way to write these tests!)
|
||||
|
||||
class VersionsTest(base.IsolatedUnitTest):
|
||||
|
||||
"""Test the version information returned from the API service."""
|
||||
|
||||
def _get_versions_list(self, url):
|
||||
versions = [
|
||||
{
|
||||
'id': 'v2.5',
|
||||
'status': 'CURRENT',
|
||||
'links': [{'rel': 'self',
|
||||
'href': '%s/v2/' % url}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.4',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': '%s/v2/' % url}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.3',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': '%s/v2/' % url}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.2',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': '%s/v2/' % url}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.1',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': '%s/v2/' % url}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.0',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': '%s/v2/' % url}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.1',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': '%s/v1/' % url}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.0',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': '%s/v1/' % url}],
|
||||
},
|
||||
]
|
||||
return versions
|
||||
|
||||
def _get_versions_list_experimental(self, url):
|
||||
vplus = [
|
||||
{
|
||||
'id': 'v2.6',
|
||||
'status': 'EXPERIMENTAL',
|
||||
'links': [{'rel': 'self',
|
||||
'href': '%s/v2/' % url}],
|
||||
}] + self._get_versions_list(url)
|
||||
return vplus
|
||||
|
||||
def test_get_version_list(self):
|
||||
req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
|
||||
req.accept = 'application/json'
|
||||
|
@ -35,62 +101,20 @@ class VersionsTest(base.IsolatedUnitTest):
|
|||
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
|
||||
self.assertEqual('application/json', res.content_type)
|
||||
results = jsonutils.loads(res.body)['versions']
|
||||
expected = [
|
||||
{
|
||||
'id': 'v2.6',
|
||||
'status': 'EXPERIMENTAL',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://127.0.0.1:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.5',
|
||||
'status': 'CURRENT',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://127.0.0.1:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.4',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://127.0.0.1:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.3',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://127.0.0.1:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.2',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://127.0.0.1:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.1',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://127.0.0.1:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.0',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://127.0.0.1:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.1',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://127.0.0.1:9292/v1/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.0',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://127.0.0.1:9292/v1/'}],
|
||||
},
|
||||
]
|
||||
expected = self._get_versions_list('http://127.0.0.1:9292')
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
def test_get_version_list_EXPERIMENTAL(self):
|
||||
req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
|
||||
req.accept = 'application/json'
|
||||
self.config(bind_host='127.0.0.1', bind_port=9292,
|
||||
enable_image_import=True)
|
||||
res = versions.Controller().index(req)
|
||||
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
|
||||
self.assertEqual('application/json', res.content_type)
|
||||
results = jsonutils.loads(res.body)['versions']
|
||||
expected = self._get_versions_list_experimental(
|
||||
'http://127.0.0.1:9292')
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
def test_get_version_list_public_endpoint(self):
|
||||
|
@ -102,195 +126,75 @@ class VersionsTest(base.IsolatedUnitTest):
|
|||
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
|
||||
self.assertEqual('application/json', res.content_type)
|
||||
results = jsonutils.loads(res.body)['versions']
|
||||
expected = [
|
||||
{
|
||||
'id': 'v2.6',
|
||||
'status': 'EXPERIMENTAL',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://example.com:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.5',
|
||||
'status': 'CURRENT',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://example.com:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.4',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://example.com:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.3',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://example.com:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.2',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://example.com:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.1',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://example.com:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.0',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://example.com:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.1',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://example.com:9292/v1/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.0',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://example.com:9292/v1/'}],
|
||||
},
|
||||
]
|
||||
expected = self._get_versions_list('https://example.com:9292')
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
def test_get_version_list_public_endpoint_EXPERIMENTAL(self):
|
||||
req = webob.Request.blank('/', base_url='http://127.0.0.1:9292/')
|
||||
req.accept = 'application/json'
|
||||
self.config(bind_host='127.0.0.1', bind_port=9292,
|
||||
public_endpoint='https://example.com:9292',
|
||||
enable_image_import=True)
|
||||
res = versions.Controller().index(req)
|
||||
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
|
||||
self.assertEqual('application/json', res.content_type)
|
||||
results = jsonutils.loads(res.body)['versions']
|
||||
expected = self._get_versions_list_experimental(
|
||||
'https://example.com:9292')
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
def test_get_version_list_secure_proxy_ssl_header(self):
|
||||
self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO')
|
||||
environ = webob.request.environ_from_url('http://localhost:9292')
|
||||
url = 'http://localhost:9292'
|
||||
environ = webob.request.environ_from_url(url)
|
||||
req = WsgiRequest(environ)
|
||||
res = versions.Controller().index(req)
|
||||
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
|
||||
self.assertEqual('application/json', res.content_type)
|
||||
results = jsonutils.loads(res.body)['versions']
|
||||
expected = [
|
||||
{
|
||||
'id': 'v2.6',
|
||||
'status': 'EXPERIMENTAL',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.5',
|
||||
'status': 'CURRENT',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.4',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.3',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.2',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.1',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.0',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.1',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://localhost:9292/v1/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.0',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'http://localhost:9292/v1/'}],
|
||||
},
|
||||
]
|
||||
expected = self._get_versions_list(url)
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
def test_get_version_list_secure_proxy_ssl_header_EXPERIMENTAL(self):
|
||||
self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO',
|
||||
enable_image_import=True)
|
||||
url = 'http://localhost:9292'
|
||||
environ = webob.request.environ_from_url(url)
|
||||
req = WsgiRequest(environ)
|
||||
res = versions.Controller().index(req)
|
||||
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
|
||||
self.assertEqual('application/json', res.content_type)
|
||||
results = jsonutils.loads(res.body)['versions']
|
||||
expected = self._get_versions_list_experimental(url)
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
def test_get_version_list_secure_proxy_ssl_header_https(self):
|
||||
self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO')
|
||||
environ = webob.request.environ_from_url('http://localhost:9292')
|
||||
url = 'http://localhost:9292'
|
||||
ssl_url = 'https://localhost:9292'
|
||||
environ = webob.request.environ_from_url(url)
|
||||
environ['HTTP_X_FORWARDED_PROTO'] = "https"
|
||||
req = WsgiRequest(environ)
|
||||
res = versions.Controller().index(req)
|
||||
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
|
||||
self.assertEqual('application/json', res.content_type)
|
||||
results = jsonutils.loads(res.body)['versions']
|
||||
expected = [
|
||||
{
|
||||
'id': 'v2.6',
|
||||
'status': 'EXPERIMENTAL',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.5',
|
||||
'status': 'CURRENT',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.4',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.3',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.2',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.1',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v2.0',
|
||||
'status': 'SUPPORTED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://localhost:9292/v2/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.1',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://localhost:9292/v1/'}],
|
||||
},
|
||||
{
|
||||
'id': 'v1.0',
|
||||
'status': 'DEPRECATED',
|
||||
'links': [{'rel': 'self',
|
||||
'href': 'https://localhost:9292/v1/'}],
|
||||
},
|
||||
]
|
||||
expected = self._get_versions_list(ssl_url)
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
def test_get_version_list_secure_proxy_ssl_header_https_EXPERIMENTAL(self):
|
||||
self.config(secure_proxy_ssl_header='HTTP_X_FORWARDED_PROTO',
|
||||
enable_image_import=True)
|
||||
url = 'http://localhost:9292'
|
||||
ssl_url = 'https://localhost:9292'
|
||||
environ = webob.request.environ_from_url(url)
|
||||
environ['HTTP_X_FORWARDED_PROTO'] = "https"
|
||||
req = WsgiRequest(environ)
|
||||
res = versions.Controller().index(req)
|
||||
self.assertEqual(http.MULTIPLE_CHOICES, res.status_int)
|
||||
self.assertEqual('application/json', res.content_type)
|
||||
results = jsonutils.loads(res.body)['versions']
|
||||
expected = self._get_versions_list_experimental(ssl_url)
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
|
||||
|
@ -356,8 +260,14 @@ class VersionNegotiationTest(base.IsolatedUnitTest):
|
|||
self.middleware.process_request(request)
|
||||
self.assertEqual('/v2/images', request.path_info)
|
||||
|
||||
def test_request_url_v2_6(self):
|
||||
def test_request_url_v2_6_unsupported(self):
|
||||
request = webob.Request.blank('/v2.6/images')
|
||||
resp = self.middleware.process_request(request)
|
||||
self.assertIsInstance(resp, versions.Controller)
|
||||
|
||||
def test_request_url_v2_6_EXPERIMENTAL(self):
|
||||
request = webob.Request.blank('/v2.6/images')
|
||||
self.config(enable_image_import=True)
|
||||
self.middleware.process_request(request)
|
||||
self.assertEqual('/v2/images', request.path_info)
|
||||
|
||||
|
@ -366,11 +276,23 @@ class VersionNegotiationTest(base.IsolatedUnitTest):
|
|||
resp = self.middleware.process_request(request)
|
||||
self.assertIsInstance(resp, versions.Controller)
|
||||
|
||||
def test_request_url_v2_7_unsupported_EXPERIMENTAL(self):
|
||||
request = webob.Request.blank('/v2.7/images')
|
||||
self.config(enable_image_import=True)
|
||||
resp = self.middleware.process_request(request)
|
||||
self.assertIsInstance(resp, versions.Controller)
|
||||
|
||||
def test_request_url_v3_unsupported(self):
|
||||
request = webob.Request.blank('/v3/images')
|
||||
resp = self.middleware.process_request(request)
|
||||
self.assertIsInstance(resp, versions.Controller)
|
||||
|
||||
def test_request_url_v3_unsupported_EXPERIMENTAL(self):
|
||||
request = webob.Request.blank('/v3/images')
|
||||
self.config(enable_image_import=True)
|
||||
resp = self.middleware.process_request(request)
|
||||
self.assertIsInstance(resp, versions.Controller)
|
||||
|
||||
|
||||
class VersionsAndNegotiationTest(VersionNegotiationTest, VersionsTest):
|
||||
|
||||
|
@ -382,12 +304,16 @@ class VersionsAndNegotiationTest(VersionNegotiationTest, VersionsTest):
|
|||
def _get_list_of_version_ids(self, status):
|
||||
request = webob.Request.blank('/')
|
||||
request.accept = 'application/json'
|
||||
# TODO(rosmaita): remove in Queens when option is removed
|
||||
self.config(enable_image_import=True)
|
||||
response = versions.Controller().index(request)
|
||||
v_list = jsonutils.loads(response.body)['versions']
|
||||
return [v['id'] for v in v_list if v['status'] == status]
|
||||
|
||||
def _assert_version_is_negotiated(self, version_id):
|
||||
request = webob.Request.blank("/%s/images" % version_id)
|
||||
# TODO(rosmaita): remove in Queens when option is removed
|
||||
self.config(enable_image_import=True)
|
||||
self.middleware.process_request(request)
|
||||
major = version_id.split('.', 1)[0]
|
||||
expected = "/%s/images" % major
|
||||
|
|
Loading…
Reference in New Issue