diff --git a/manila/api/v2/quota_sets.py b/manila/api/v2/quota_sets.py index 7db0d5e9a1..5baf5ac91a 100644 --- a/manila/api/v2/quota_sets.py +++ b/manila/api/v2/quota_sets.py @@ -139,6 +139,20 @@ class QuotaSetsMixin(object): @wsgi.Controller.authorize("update") def _update(self, req, id, body): + body = body.get('quota_set', {}) + if (body.get('gigabytes') is None and + body.get('snapshots') is None and + body.get('snapshot_gigabytes') is None and + body.get('shares') is None and + body.get('share_networks') is None and + body.get('share_groups') is None and + body.get('share_group_snapshots') is None and + body.get('share_replicas') is None and + body.get('replica_gigabytes') is None and + body.get('per_share_gigabytes') is None): + msg = _("Must supply at least one quota field to update.") + raise webob.exc.HTTPBadRequest(explanation=msg) + context = req.environ['manila.context'] project_id = id bad_keys = [] @@ -148,7 +162,6 @@ class QuotaSetsMixin(object): share_type = params.get('share_type', [None])[0] self._validate_user_id_and_share_type_args(user_id, share_type) share_type_id = self._get_share_type_id(context, share_type) - body = body.get('quota_set', {}) if share_type and body.get('share_groups', body.get('share_group_snapshots')): msg = _("Share type quotas cannot constrain share groups and " diff --git a/manila/tests/api/v2/test_quota_sets.py b/manila/tests/api/v2/test_quota_sets.py index 4526fe6ae9..27318f866f 100644 --- a/manila/tests/api/v2/test_quota_sets.py +++ b/manila/tests/api/v2/test_quota_sets.py @@ -771,3 +771,18 @@ class QuotaSetsControllerTest(test.TestCase): exception.VersionNotFoundForAPIMethod, controller().update, req, self.project_id) + + def test_update_without_quota(self): + body = { + 'quota_set': { + 'tenant_id': self.project_id, + } + } + req = _get_request(True, False) + + self.assertRaises( + webob.exc.HTTPBadRequest, + self.controller.update, + req, self.project_id, body=body) + self.mock_policy_check.assert_called_once_with( + req.environ['manila.context'], self.resource_name, 'update') diff --git a/releasenotes/notes/bug-1778975-fix-quota-update-does-not-require-a-value-496ec846d2c43963.yaml b/releasenotes/notes/bug-1778975-fix-quota-update-does-not-require-a-value-496ec846d2c43963.yaml new file mode 100644 index 0000000000..1cd9bd18f2 --- /dev/null +++ b/releasenotes/notes/bug-1778975-fix-quota-update-does-not-require-a-value-496ec846d2c43963.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed a manila issue while updating quotas. Now manila requires at least + a quota value to be updated.