From edc93383f7cd9d055d655a8e345a3efa81b7de5b Mon Sep 17 00:00:00 2001 From: Swapnil Kulkarni Date: Thu, 16 Jan 2014 13:28:31 +0530 Subject: [PATCH] Updates for version list to show correct references 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 | 13 +++++++++---- cinder/tests/api/fakes.py | 7 ++++++- cinder/tests/api/v2/test_volumes.py | 22 +++++++++++----------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/cinder/api/views/versions.py b/cinder/api/views/versions.py index afa03afe4..40de32907 100644 --- a/cinder/api/views/versions.py +++ b/cinder/api/views/versions.py @@ -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) diff --git a/cinder/tests/api/fakes.py b/cinder/tests/api/fakes.py index db10d43a6..822363d88 100644 --- a/cinder/tests/api/fakes.py +++ b/cinder/tests/api/fakes.py @@ -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( diff --git a/cinder/tests/api/v2/test_volumes.py b/cinder/tests/api/v2/test_volumes.py index ac767eccd..da6ba5dc9 100644 --- a/cinder/tests/api/v2/test_volumes.py +++ b/cinder/tests/api/v2/test_volumes.py @@ -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' }, { -- 2.45.2