]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Updates for version list to show correct references
authorSwapnil Kulkarni <swapnilkulkarni2608@gmail.com>
Thu, 16 Jan 2014 07:58:31 +0000 (13:28 +0530)
committerSwapnil Kulkarni <swapnilkulkarni2608@gmail.com>
Thu, 16 Jan 2014 08:04:34 +0000 (13:34 +0530)
Updated views to consider version while creating href.
Updated fakes to consider version while creating fake href.
Updated some test cases in v2 api which were using v1 as
expected output

Change-Id: Ib05180041309ef75c3718924969bd2354d6d8b3a
Closes-Bug: #1261849

cinder/api/views/versions.py
cinder/tests/api/fakes.py
cinder/tests/api/v2/test_volumes.py

index afa03afe455d5f54941cc4aac3771afd55731c56..40de3290711b516b8f6633189155558af207e3c3 100644 (file)
@@ -38,7 +38,8 @@ class ViewBuilder(object):
                 "id": version['id'],
                 "status": version['status'],
                 "links": [{"rel": "self",
-                           "href": self.generate_href(req.path), }, ],
+                           "href": self.generate_href(version['id'],
+                                                      req.path), }, ],
                 "media-types": version['media-types'], })
 
         return dict(choices=version_objs)
@@ -64,16 +65,20 @@ class ViewBuilder(object):
 
     def _build_links(self, version_data):
         """Generate a container of links that refer to the provided version."""
-        href = self.generate_href()
+        href = self.generate_href(version_data['id'])
 
         links = [{'rel': 'self',
                   'href': href, }, ]
 
         return links
 
-    def generate_href(self, path=None):
+    def generate_href(self, version, path=None):
         """Create an url that refers to a specific version_number."""
-        version_number = 'v1'
+        if version.find('v1.') == 0:
+            version_number = 'v1'
+        else:
+            version_number = 'v2'
+
         if path:
             path = path.strip('/')
             return os.path.join(self.base_url, version_number, path)
index db10d43a611ed4dd723f0ade53b612fed1bda7d3..822363d8804a238e8f69f9c6c5f915b232dc1baf 100644 (file)
@@ -133,7 +133,12 @@ class HTTPRequest(webob.Request):
 
     @classmethod
     def blank(cls, *args, **kwargs):
-        kwargs['base_url'] = 'http://localhost/v1'
+        if args != None:
+            if args[0].find('v1') == 0:
+                kwargs['base_url'] = 'http://localhost/v1'
+            else:
+                kwargs['base_url'] = 'http://localhost/v2'
+
         use_admin_context = kwargs.pop('use_admin_context', False)
         out = os_wsgi.Request.blank(*args, **kwargs)
         out.environ['cinder.context'] = FakeRequestContext(
index ac767eccda3eb8cf0d23315d0c035a20a801cbee..da6ba5dc94d5af7f351ec2c89c82b0134b4d9d9f 100644 (file)
@@ -94,7 +94,7 @@ class VolumeApiTest(test.TestCase):
                          'description': 'Volume Test Desc',
                          'id': '1',
                          'links':
-                         [{'href': 'http://localhost/v1/fake/volumes/1',
+                         [{'href': 'http://localhost/v2/fake/volumes/1',
                            'rel': 'self'},
                           {'href': 'http://localhost/fake/volumes/1',
                            'rel': 'bookmark'}],
@@ -196,7 +196,7 @@ class VolumeApiTest(test.TestCase):
                          'description': 'Volume Test Desc',
                          'id': '1',
                          'links':
-                         [{'href': 'http://localhost/v1/fake/volumes/1',
+                         [{'href': 'http://localhost/v2/fake/volumes/1',
                            'rel': 'self'},
                           {'href': 'http://localhost/fake/volumes/1',
                            'rel': 'bookmark'}],
@@ -284,7 +284,7 @@ class VolumeApiTest(test.TestCase):
                 'size': 1,
                 'links': [
                     {
-                        'href': 'http://localhost/v1/fake/volumes/1',
+                        'href': 'http://localhost/v2/fake/volumes/1',
                         'rel': 'self'
                     },
                     {
@@ -331,7 +331,7 @@ class VolumeApiTest(test.TestCase):
             'size': 1,
             'links': [
                 {
-                    'href': 'http://localhost/v1/fake/volumes/1',
+                    'href': 'http://localhost/v2/fake/volumes/1',
                     'rel': 'self'
                 },
                 {
@@ -388,7 +388,7 @@ class VolumeApiTest(test.TestCase):
             'size': 1,
             'links': [
                 {
-                    'href': 'http://localhost/v1/fake/volumes/1',
+                    'href': 'http://localhost/v2/fake/volumes/1',
                     'rel': 'self'
                 },
                 {
@@ -440,7 +440,7 @@ class VolumeApiTest(test.TestCase):
                     'id': '1',
                     'links': [
                         {
-                            'href': 'http://localhost/v1/fake/volumes/1',
+                            'href': 'http://localhost/v2/fake/volumes/1',
                             'rel': 'self'
                         },
                         {
@@ -489,7 +489,7 @@ class VolumeApiTest(test.TestCase):
                     'size': 1,
                     'links': [
                         {
-                            'href': 'http://localhost/v1/fake/volumes/1',
+                            'href': 'http://localhost/v2/fake/volumes/1',
                             'rel': 'self'
                         },
                         {
@@ -547,7 +547,7 @@ class VolumeApiTest(test.TestCase):
                     'size': 1,
                     'links': [
                         {
-                            'href': 'http://localhost/v1/fakeproject'
+                            'href': 'http://localhost/v2/fakeproject'
                                     '/volumes/1',
                             'rel': 'self'
                         },
@@ -879,7 +879,7 @@ class VolumeApiTest(test.TestCase):
                 'size': 1,
                 'links': [
                     {
-                        'href': 'http://localhost/v1/fake/volumes/1',
+                        'href': 'http://localhost/v2/fake/volumes/1',
                         'rel': 'self'
                     },
                     {
@@ -919,7 +919,7 @@ class VolumeApiTest(test.TestCase):
                 'size': 1,
                 'links': [
                     {
-                        'href': 'http://localhost/v1/fake/volumes/1',
+                        'href': 'http://localhost/v2/fake/volumes/1',
                         'rel': 'self'
                     },
                     {
@@ -984,7 +984,7 @@ class VolumeApiTest(test.TestCase):
                 'size': 1,
                 'links': [
                     {
-                        'href': 'http://localhost/v1/fakeproject/volumes/1',
+                        'href': 'http://localhost/v2/fakeproject/volumes/1',
                         'rel': 'self'
                     },
                     {