Fix wrong response with version details

Now,Version details for API v2 were being reported as v1.

This patch fixed this bug.

Change-Id: I9698b33210e7d2f89f8a717d0ad2ada3edb4c391
Closes-bug:#1458850
This commit is contained in:
wangxiyuan 2015-05-26 20:12:51 +08:00
parent 7ed2476311
commit 21735a2159
2 changed files with 78 additions and 3 deletions

View File

@ -254,13 +254,16 @@ class Versions(wsgi.Resource):
return args
class VolumeVersionV1(object):
class VolumeVersion(object):
@wsgi.serializers(xml=VersionTemplate,
atom=VersionAtomSerializer)
def show(self, req):
builder = views_versions.get_view_builder(req)
return builder.build_version(_KNOWN_VERSIONS['v1.0'])
if 'v1' in builder.base_url:
return builder.build_version(_KNOWN_VERSIONS['v1.0'])
else:
return builder.build_version(_KNOWN_VERSIONS['v2.0'])
def create_resource():
return wsgi.Resource(VolumeVersionV1())
return wsgi.Resource(VolumeVersion())

View File

@ -69,3 +69,75 @@ class VersionsTest(test.TestCase):
},
]
self.assertEqual(expected, results)
def test_get_version_detail_v1(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:8776/v1')
req.accept = 'application/json'
res = versions.VolumeVersion().show(req)
expected = {
"version": {
"status": "SUPPORTED",
"updated": "2014-06-28T12:20:21Z",
"media-types": [
{
"base": "application/xml",
"type":
"application/vnd.openstack.volume+xml;version=1"
},
{
"base": "application/json",
"type":
"application/vnd.openstack.volume+json;version=1"
}
],
"id": "v1.0",
"links": [
{
"href": "http://127.0.0.1:8776/v1/",
"rel": "self"
},
{
"href": "http://docs.openstack.org/",
"type": "text/html",
"rel": "describedby"
}
]
}
}
self.assertEqual(expected, res)
def test_get_version_detail_v2(self):
req = webob.Request.blank('/', base_url='http://127.0.0.1:8776/v2')
req.accept = 'application/json'
res = versions.VolumeVersion().show(req)
expected = {
"version": {
"status": "CURRENT",
"updated": "2012-11-21T11:33:21Z",
"media-types": [
{
"base": "application/xml",
"type":
"application/vnd.openstack.volume+xml;version=1"
},
{
"base": "application/json",
"type":
"application/vnd.openstack.volume+json;version=1"
}
],
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8776/v2/",
"rel": "self"
},
{
"href": "http://docs.openstack.org/",
"type": "text/html",
"rel": "describedby"
}
]
}
}
self.assertEqual(expected, res)