]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Allow deprecated volume update keys in v2
authorMike Perez <thingee@gmail.com>
Thu, 3 Apr 2014 00:52:11 +0000 (17:52 -0700)
committerjohn-griffith <john.griffith@solidfire.com>
Fri, 4 Apr 2014 14:36:49 +0000 (08:36 -0600)
Keys like display_name and display_description were deprecated for other
actions in v2 like creating volumes, so for consistency they should work
with updating.

DocImpact
Closes-Bug: #1301172
Change-Id: I19bc7c85352578bb57fa9fdaf1817f78e0ee2f2a
(cherry picked from commit d75a90ec1daff1444f20f6b68255890391bdb4e5)

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

index 9316432d2f83fc3e7f20077ee6566c1d6e2e750b..4a938bac01b8b19334d4de9e2c8ba2c3a5858f58 100644 (file)
@@ -379,6 +379,8 @@ class VolumeController(wsgi.Controller):
         valid_update_keys = (
             'name',
             'description',
+            'display_name',
+            'display_description',
             'metadata',
         )
 
index fab7d98b6d1d627edf26194a6a2f863b6d6e483f..fc6c183fedf86f9e5e1c7b84950cc1128d3e0894 100644 (file)
@@ -308,6 +308,113 @@ class VolumeApiTest(test.TestCase):
         self.assertEqual(res_dict, expected)
         self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
 
+    def test_volume_update_deprecation(self):
+        self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
+        self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
+
+        updates = {
+            "display_name": "Updated Test Name",
+            "display_description": "Updated Test Description",
+        }
+        body = {"volume": updates}
+        req = fakes.HTTPRequest.blank('/v2/volumes/1')
+        self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
+        res_dict = self.controller.update(req, '1', body)
+        expected = {
+            'volume': {
+                'status': 'fakestatus',
+                'description': 'Updated Test Description',
+                'encrypted': False,
+                'availability_zone': 'fakeaz',
+                'bootable': 'false',
+                'name': 'Updated Test Name',
+                'attachments': [
+                    {
+                        'id': '1',
+                        'volume_id': '1',
+                        'server_id': 'fakeuuid',
+                        'host_name': None,
+                        'device': '/',
+                    }
+                ],
+                'user_id': 'fakeuser',
+                'volume_type': 'vol_type_name',
+                'snapshot_id': None,
+                'source_volid': None,
+                'metadata': {'attached_mode': 'rw', 'readonly': 'False'},
+                'id': '1',
+                'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
+                'size': 1,
+                'links': [
+                    {
+                        'href': 'http://localhost/v2/fake/volumes/1',
+                        'rel': 'self'
+                    },
+                    {
+                        'href': 'http://localhost/fake/volumes/1',
+                        'rel': 'bookmark'
+                    }
+                ],
+            }
+        }
+        self.assertEqual(res_dict, expected)
+        self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
+
+    def test_volume_update_deprecation_key_priority(self):
+        """Test current update keys have priority over deprecated keys."""
+        self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
+        self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
+
+        updates = {
+            "name": "New Name",
+            "description": "New Description",
+            "display_name": "Not Shown Name",
+            "display_description": "Not Shown Description",
+        }
+        body = {"volume": updates}
+        req = fakes.HTTPRequest.blank('/v2/volumes/1')
+        self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
+        res_dict = self.controller.update(req, '1', body)
+        expected = {
+            'volume': {
+                'status': 'fakestatus',
+                'description': 'New Description',
+                'encrypted': False,
+                'availability_zone': 'fakeaz',
+                'bootable': 'false',
+                'name': 'New Name',
+                'attachments': [
+                    {
+                        'id': '1',
+                        'volume_id': '1',
+                        'server_id': 'fakeuuid',
+                        'host_name': None,
+                        'device': '/',
+                    }
+                ],
+                'user_id': 'fakeuser',
+                'volume_type': 'vol_type_name',
+                'snapshot_id': None,
+                'source_volid': None,
+                'metadata': {'attached_mode': 'rw', 'readonly': 'False'},
+                'id': '1',
+                'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
+                'size': 1,
+                'links': [
+                    {
+                        'href': 'http://localhost/v2/fake/volumes/1',
+                        'rel': 'self'
+                    },
+                    {
+                        'href': 'http://localhost/fake/volumes/1',
+                        'rel': 'bookmark'
+                    }
+                ],
+            }
+        }
+        self.assertEqual(res_dict, expected)
+        self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
+
     def test_volume_update_metadata(self):
         self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
         self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
@@ -372,7 +479,7 @@ class VolumeApiTest(test.TestCase):
                                         False)
 
         updates = {
-            "display_name": "Updated Test Name",
+            "name": "Updated Test Name",
         }
         body = {"volume": updates}
         req = fakes.HTTPRequest.blank('/v2/volumes/1')
@@ -386,7 +493,7 @@ class VolumeApiTest(test.TestCase):
             'encrypted': False,
             'availability_zone': 'fakeaz',
             'bootable': 'false',
-            'name': 'displayname',
+            'name': 'Updated Test Name',
             'attachments': [{
                 'id': '1',
                 'volume_id': '1',