From: Szymon Borkowski Date: Fri, 11 Dec 2015 11:20:03 +0000 (+0100) Subject: Fix for showing default quotas to non-admin user X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ef0bfc288d6513a868e0e25b1f7effd13fccb754;p=openstack-build%2Fcinder-build.git Fix for showing default quotas to non-admin user Earlier, when non-admin user wanted to get quotas for his own projects, if there were no custom quota values set, the API used to return zero values. Change-Id: I753af89aa5aae5ad20abe48441df3dbd02b8e05e Closes-Bug: 1523928 --- diff --git a/cinder/api/contrib/quotas.py b/cinder/api/contrib/quotas.py index e513f410b..13edb857d 100644 --- a/cinder/api/contrib/quotas.py +++ b/cinder/api/contrib/quotas.py @@ -231,7 +231,7 @@ class QuotaSetsController(wsgi.Controller): # NOTE(e0ne): Keystone API v2 requires admin permissions for # project_get method. We ignore Forbidden exception for # non-admin users. - parent_project_id = target_project_id + parent_project_id = None try: sqlalchemy_api.authorize_project_context(context, diff --git a/cinder/tests/unit/api/contrib/test_quotas.py b/cinder/tests/unit/api/contrib/test_quotas.py index 398f096d9..021f094f5 100644 --- a/cinder/tests/unit/api/contrib/test_quotas.py +++ b/cinder/tests/unit/api/contrib/test_quotas.py @@ -32,6 +32,7 @@ from cinder import db from cinder import test from cinder.tests.unit import test_db_api +from keystoneclient import exceptions from keystonemiddleware import auth_token from oslo_config import cfg from oslo_config import fixture as config_fixture @@ -207,6 +208,17 @@ class QuotaSetsControllerTest(test.TestCase): self.assertRaises(webob.exc.HTTPForbidden, self.controller.show, self.req, 'foo') + def test_show_non_admin_user(self): + self.controller._get_project = mock.Mock() + self.controller._get_project.side_effect = exceptions.Forbidden + self.controller._get_quotas = mock.Mock(side_effect= + self.controller._get_quotas) + result = self.controller.show(self.req, 'foo') + self.assertDictMatch(make_body(), result) + self.controller._get_quotas.assert_called_with( + self.req.environ['cinder.context'], 'foo', False, + parent_project_id=None) + def test_subproject_show_not_authorized(self): self.controller._get_project = mock.Mock() self.controller._get_project.side_effect = self._get_project