]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix wrong response with version details
authorwangxiyuan <wangxiyuan@huawei.com>
Tue, 26 May 2015 12:12:51 +0000 (20:12 +0800)
committerwangxiyuan <wangxiyuan@huawei.com>
Wed, 27 May 2015 00:13:34 +0000 (08:13 +0800)
Now,Version details for API v2 were being reported as v1.

This patch fixed this bug.

Change-Id: I9698b33210e7d2f89f8a717d0ad2ada3edb4c391
Closes-bug:#1458850

cinder/api/versions.py
cinder/tests/unit/api/test_versions.py

index ca80e8e1f36e6d74917c0c99e3714c94ee461490..8bbf188034232cc88c0e02177404248631238ddd 100644 (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())
index 7573142fc3765e99d69055b5ff59d2950ba2df02..eb00321c2337da4b50f023e9dbaff11576a06521 100644 (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)