From: Mike Perez Date: Thu, 3 Apr 2014 00:52:11 +0000 (-0700) Subject: Allow deprecated volume update keys in v2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e9324decdddf63794ae2e8ba97293c037828045e;p=openstack-build%2Fcinder-build.git Allow deprecated volume update keys in v2 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) --- diff --git a/cinder/api/v2/volumes.py b/cinder/api/v2/volumes.py index 9316432d2..4a938bac0 100644 --- a/cinder/api/v2/volumes.py +++ b/cinder/api/v2/volumes.py @@ -379,6 +379,8 @@ class VolumeController(wsgi.Controller): valid_update_keys = ( 'name', 'description', + 'display_name', + 'display_description', 'metadata', ) diff --git a/cinder/tests/api/v2/test_volumes.py b/cinder/tests/api/v2/test_volumes.py index fab7d98b6..fc6c183fe 100644 --- a/cinder/tests/api/v2/test_volumes.py +++ b/cinder/tests/api/v2/test_volumes.py @@ -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',