From: Swapnil Kulkarni Date: Sat, 4 Jan 2014 07:24:13 +0000 (+0530) Subject: Update V2 API to return detailed volume information on create X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=c32302c5d5f35df39b49d32fcba47a4d36b3783a;p=openstack-build%2Fcinder-build.git Update V2 API to return detailed volume information on create Current implementation returns only summary information, so cinderclient requires additional GET call to get details. Updated the api to return the details by default so the GET in cinderclient can be removed. Closes-Bug: #1265893 Change-Id: I56d4d79c4a942d8bf53318e46737674dc0bf9b56 --- diff --git a/cinder/api/v2/volumes.py b/cinder/api/v2/volumes.py index 1c65d33fd..1267cd0b1 100644 --- a/cinder/api/v2/volumes.py +++ b/cinder/api/v2/volumes.py @@ -398,7 +398,7 @@ class VolumeController(wsgi.Controller): self._add_visible_admin_metadata(context, new_volume) - retval = self._view_builder.summary(req, new_volume) + retval = self._view_builder.detail(req, new_volume) return retval diff --git a/cinder/tests/api/v2/test_volumes.py b/cinder/tests/api/v2/test_volumes.py index b2def7a81..ac767eccd 100644 --- a/cinder/tests/api/v2/test_volumes.py +++ b/cinder/tests/api/v2/test_volumes.py @@ -82,23 +82,32 @@ class VolumeApiTest(test.TestCase): body = {"volume": vol} req = fakes.HTTPRequest.blank('/v2/volumes') res_dict = self.controller.create(req, body) - expected = { - 'volume': { - 'name': 'Volume Test Name', - 'id': '1', - 'links': [ - { - 'href': 'http://localhost/v1/fake/volumes/1', - 'rel': 'self' - }, - { - 'href': 'http://localhost/fake/volumes/1', - 'rel': 'bookmark' - } - ], - } - } - self.assertEqual(res_dict, expected) + ex = {'volume': {'attachments': + [{'device': '/', + 'host_name': None, + 'id': '1', + 'server_id': 'fakeuuid', + 'volume_id': '1'}], + 'availability_zone': 'zone1:host1', + 'bootable': 'false', + 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'description': 'Volume Test Desc', + 'id': '1', + 'links': + [{'href': 'http://localhost/v1/fake/volumes/1', + 'rel': 'self'}, + {'href': 'http://localhost/fake/volumes/1', + 'rel': 'bookmark'}], + 'metadata': {'attached_mode': 'rw', + 'readonly': 'False'}, + 'name': 'Volume Test Name', + 'size': 100, + 'snapshot_id': None, + 'source_volid': None, + 'status': 'fakestatus', + 'user_id': 'fakeuser', + 'volume_type': 'vol_type_name'}} + self.assertEqual(res_dict, ex) def test_volume_create_with_type(self): vol_type = db.volume_type_create( @@ -176,26 +185,34 @@ class VolumeApiTest(test.TestCase): "description": "Volume Test Desc", "availability_zone": "nova", "imageRef": 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'} - expected = { - 'volume': { - 'name': 'Volume Test Name', - 'id': '1', - 'links': [ - { - 'href': 'http://localhost/v1/fake/volumes/1', - 'rel': 'self' - }, - { - 'href': 'http://localhost/fake/volumes/1', - 'rel': 'bookmark' - } - ], - } - } + ex = {'volume': {'attachments': [{'device': '/', + 'host_name': None, + 'id': '1', + 'server_id': 'fakeuuid', + 'volume_id': '1'}], + 'availability_zone': 'nova', + 'bootable': 'false', + 'created_at': datetime.datetime(1, 1, 1, 1, 1, 1), + 'description': 'Volume Test Desc', + 'id': '1', + 'links': + [{'href': 'http://localhost/v1/fake/volumes/1', + 'rel': 'self'}, + {'href': 'http://localhost/fake/volumes/1', + 'rel': 'bookmark'}], + 'metadata': {'attached_mode': 'rw', + 'readonly': 'False'}, + 'name': 'Volume Test Name', + 'size': '1', + 'snapshot_id': None, + 'source_volid': None, + 'status': 'fakestatus', + 'user_id': 'fakeuser', + 'volume_type': 'vol_type_name'}} body = {"volume": vol} req = fakes.HTTPRequest.blank('/v2/volumes') res_dict = self.controller.create(req, body) - self.assertEqual(res_dict, expected) + self.assertEqual(res_dict, ex) def test_volume_create_with_image_id_is_integer(self): self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)