]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix updating only volume type is_public
authorliyingjun <liyingjun1988@gmail.com>
Wed, 9 Sep 2015 01:46:21 +0000 (09:46 +0800)
committerJohn Griffith <john.griffith8@gmail.com>
Tue, 13 Oct 2015 18:26:09 +0000 (18:26 +0000)
When updating only volume type is_public, error will be raised: `ERROR:
Specify either volume type name and/or description`. Fixed this by
adding a check that is_public is None, the same way name and description
do.

APIImpact
Change-Id: I4b7ece238f76d9acb7f0555c180c6336f6cf1830
Implement blueprint: only-update-volume-type-public
Closes-bug: #1493616

cinder/api/contrib/types_manage.py
cinder/tests/unit/api/contrib/test_types_manage.py

index 56afb9317b28c21d3af99ea043e03b8bf54a4a03..ff928fec687de36cf0bddc94b7508abfb5a83afb 100644 (file)
@@ -120,8 +120,9 @@ class VolumeTypesManageController(wsgi.Controller):
             msg = _("Volume type name can not be empty.")
             raise webob.exc.HTTPBadRequest(explanation=msg)
 
-        if name is None and description is None:
-            msg = _("Specify either volume type name and/or description.")
+        if name is None and description is None and is_public is None:
+            msg = _("Specify volume type name, description, is_public or"
+                    "a combination thereof.")
             raise webob.exc.HTTPBadRequest(explanation=msg)
 
         if is_public is not None and not utils.is_valid_boolstr(is_public):
index 542206ef2ca38e14707f0a8ef71b38ad5e836c2b..629b2b2bc2628733737ad9a994e4e2a1815637fc 100644 (file)
@@ -399,6 +399,25 @@ class VolumeTypesManageApiTest(test.TestCase):
                                  {'expected_name': 'vol_type_888',
                                   'expected_desc': 'vol_type_desc_888_888'})
 
+    @mock.patch('cinder.volume.volume_types.update')
+    @mock.patch('cinder.volume.volume_types.get_volume_type')
+    def test_update_only_is_public(self, mock_get, mock_update):
+        is_public = False
+        mock_get.return_value = return_volume_types_get_volume_type_updated(
+            '123', is_public=is_public)
+
+        body = {"volume_type": {"is_public": is_public}}
+        req = fakes.HTTPRequest.blank('/v2/fake/types/123')
+        req.method = 'PUT'
+
+        self.assertEqual(0, len(self.notifier.notifications))
+        res_dict = self.controller._update(req, '123', body)
+        self.assertEqual(1, len(self.notifier.notifications))
+        self._check_test_results(res_dict,
+                                 {'expected_name': 'vol_type_123_123',
+                                  'expected_desc': 'vol_type_desc_123_123',
+                                  'is_public': False})
+
     def test_update_invalid_is_public(self):
         body = {"volume_type": {"name": "test",
                                 "description": "something",