Skip to content

Commit

Permalink
Version negotiation api middleware to include v2.3
Browse files Browse the repository at this point in the history
Glance API is at v2.3 listed to be CURRENT version but the version
negotiation middleware lists only v2, v2.0, v2.1, v2.2.

Also, adds test class to versions tests.

The current versions tests contain a class to test the versions
response, and a class to test version negotiation, but this put us
in a situation where the 'versions' response was correctly updated
for v2.3, but the negotiation to map v2.3 -> v2 was not, thereby
making calls to /v2.3/whatever fail even though all tests in both
classes passed.

This patch adds a new test class that inherits from both of the
current test classes.  It contains tests to verify that all the
versions mentioned in the versions response are mapped correctly
so this kind of partial update situation won't happen again.

Closes-Bug: 1609571

Co-Authored-By: Nikhil Komawar <nik.komawar@gmail.com>
Co-Authored-By: Brian Rosmaita <brian.rosmaita@rackspace.com>

Change-Id: I4018af408fa45f3ac0ad6e9c8229428a9f87089f
(Cherry-picked from commit 0d1daf4 and
commit 8c3560b)
  • Loading branch information
komawar committed Aug 11, 2016
1 parent b495488 commit 75a74b3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion glance/api/middleware/version_negotiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def _match_version_string(self, subject):
"""
if subject in ('v1', 'v1.0', 'v1.1') and CONF.enable_v1_api:
major_version = 1
elif subject in ('v2', 'v2.0', 'v2.1', 'v2.2') and CONF.enable_v2_api:
elif (subject in ('v2', 'v2.0', 'v2.1', 'v2.2', 'v2.3')
and CONF.enable_v2_api):
major_version = 2
elif subject in ('v3', 'v3.0') and CONF.enable_v3_api:
major_version = 3
Expand Down
49 changes: 47 additions & 2 deletions glance/tests/unit/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ def test_request_url_v2_2(self):
self.middleware.process_request(request)
self.assertEqual('/v2/images', request.path_info)

def test_request_url_v2_3(self):
request = webob.Request.blank('/v2.3/images')
self.middleware.process_request(request)
self.assertEqual('/v2/images', request.path_info)

def test_request_url_v3(self):
request = webob.Request.blank('/v3/artifacts')
resp = self.middleware.process_request(request)
Expand All @@ -180,12 +185,52 @@ def test_request_url_v3_0(self):
resp = self.middleware.process_request(request)
self.assertIsInstance(resp, versions.Controller)

def test_request_url_v2_3_unsupported(self):
request = webob.Request.blank('/v2.3/images')
def test_request_url_v2_4_unsupported(self):
request = webob.Request.blank('/v2.4/images')
resp = self.middleware.process_request(request)
self.assertIsInstance(resp, versions.Controller)

def test_request_url_v4_unsupported(self):
request = webob.Request.blank('/v4/images')
resp = self.middleware.process_request(request)
self.assertIsInstance(resp, versions.Controller)


class VersionsAndNegotiationTest(VersionNegotiationTest, VersionsTest):

"""
Test that versions mentioned in the versions response are correctly
negotiated.
"""

def _get_list_of_version_ids(self, status):
request = webob.Request.blank('/')
request.accept = 'application/json'
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)
self.middleware.process_request(request)
major = version_id.split('.', 1)[0]
expected = "/%s/images" % major
self.assertEqual(expected, request.path_info)

def test_current_is_negotiated(self):
# NOTE(rosmaita): Bug 1609571: the versions response was correct, but
# the negotiation had not been updated for the CURRENT version.
to_check = self._get_list_of_version_ids('CURRENT')
self.assertTrue(to_check)
for version_id in to_check:
self._assert_version_is_negotiated(version_id)

def test_supported_is_negotiated(self):
to_check = self._get_list_of_version_ids('SUPPORTED')
for version_id in to_check:
self._assert_version_is_negotiated(version_id)

def test_deprecated_is_negotiated(self):
to_check = self._get_list_of_version_ids('DEPRECATED')
for version_id in to_check:
self._assert_version_is_negotiated(version_id)

0 comments on commit 75a74b3

Please sign in to comment.