Don't return 300 when requesting /versions

Whenever the versions resource is used, it'll reply with a 300 status
code. This is the desired behavior when requesting versions that we
don't support and/or non-existent.

However, when the user requests specifically for the `/versions`
endpoint, Glance shouldn't reply with a 300 since there's just 1 choice
for such endpoint.

APIImpact
Closes-bug: #1491350

Change-Id: I23e3780e5d1b609753ffef59418115f45ab45fe7
This commit is contained in:
Flavio Percoco 2015-09-02 13:16:24 +02:00
parent b2c2ecee50
commit 3fc253c197
4 changed files with 7 additions and 8 deletions

View File

@ -49,7 +49,7 @@ class VersionNegotiationFilter(wsgi.Middleware):
# If the request is for /versions, just return the versions container
# TODO(bcwaldon): deprecate this behavior
if req.path_info_peek() == "versions":
return self.versions_app
return self.versions_app.index(req, explicit=True)
accept = str(req.accept)
if accept.startswith('application/vnd.openstack.images-'):

View File

@ -41,7 +41,7 @@ class Controller(object):
"""A wsgi controller that reports which API versions are supported."""
def index(self, req):
def index(self, req, explicit=False):
"""Respond to a request for all OpenStack API versions."""
def build_version_object(version, path, status):
url = CONF.public_endpoint or req.host_url
@ -73,8 +73,9 @@ class Controller(object):
build_version_object(1.0, 'v1', 'SUPPORTED'),
])
status = explicit and http_client.OK or http_client.MULTIPLE_CHOICES
response = webob.Response(request=req,
status=http_client.MULTIPLE_CHOICES,
status=status,
content_type='application/json')
json = jsonutils.dumps(dict(versions=version_objs))
if six.PY3:

View File

@ -295,7 +295,7 @@ class TestApiPaths(functional.FunctionalTest):
path = 'http://%s:%d/versions' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(300, response.status)
self.assertEqual(200, response.status)
self.assertEqual(self.versions_json, content)
def test_get_versions_path_with_openstack_header(self):
@ -307,7 +307,7 @@ class TestApiPaths(functional.FunctionalTest):
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.images-v1'}
response, content = http.request(path, 'GET', headers=headers)
self.assertEqual(300, response.status)
self.assertEqual(200, response.status)
self.assertEqual(self.versions_json, content)
def test_get_v1_versions_path(self):

View File

@ -79,6 +79,4 @@ class TestSSL(functional.FunctionalTest):
path = "https://%s:%d/versions" % ("127.0.0.1", self.api_port)
https = httplib2.Http(ca_certs=self.ca_file)
response, content = https.request(path, 'GET')
# Expect a "300 Multiple Choices"
self.assertEqual(300, response.status)
self.assertEqual(200, response.status)