From d6a3b481bf767d518d08401384abb7cfa64e50af Mon Sep 17 00:00:00 2001 From: liyingjun Date: Wed, 9 Sep 2015 09:46:21 +0800 Subject: [PATCH] Fix updating only volume type is_public 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 | 5 +++-- .../unit/api/contrib/test_types_manage.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cinder/api/contrib/types_manage.py b/cinder/api/contrib/types_manage.py index 56afb9317..ff928fec6 100644 --- a/cinder/api/contrib/types_manage.py +++ b/cinder/api/contrib/types_manage.py @@ -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): diff --git a/cinder/tests/unit/api/contrib/test_types_manage.py b/cinder/tests/unit/api/contrib/test_types_manage.py index 542206ef2..629b2b2bc 100644 --- a/cinder/tests/unit/api/contrib/test_types_manage.py +++ b/cinder/tests/unit/api/contrib/test_types_manage.py @@ -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", -- 2.45.2