From: wangxiyuan Date: Tue, 26 May 2015 12:12:51 +0000 (+0800) Subject: Fix wrong response with version details X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=21735a215914006add55ad2ae0d8ced085858821;p=openstack-build%2Fcinder-build.git 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 --- diff --git a/cinder/api/versions.py b/cinder/api/versions.py index ca80e8e1f..8bbf18803 100644 --- a/cinder/api/versions.py +++ b/cinder/api/versions.py @@ -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()) diff --git a/cinder/tests/unit/api/test_versions.py b/cinder/tests/unit/api/test_versions.py index 7573142fc..eb00321c2 100644 --- a/cinder/tests/unit/api/test_versions.py +++ b/cinder/tests/unit/api/test_versions.py @@ -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)