]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Update V2 API to return detailed volume information on create
authorSwapnil Kulkarni <swapnilkulkarni2608@gmail.com>
Sat, 4 Jan 2014 07:24:13 +0000 (12:54 +0530)
committerSwapnil Kulkarni <swapnilkulkarni2608@gmail.com>
Sat, 4 Jan 2014 15:51:12 +0000 (21:21 +0530)
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

cinder/api/v2/volumes.py
cinder/tests/api/v2/test_volumes.py

index 1c65d33fd411d8deb14999b9c89cc325a9a8a486..1267cd0b185ec0b28fec682457df9a4725ccacd3 100644 (file)
@@ -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
 
index b2def7a81afcfe69c63dffdf842d6c12ce15b305..ac767eccda3eb8cf0d23315d0c035a20a801cbee 100644 (file)
@@ -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)