From e2eb94bdbbe7dae57247cdf0e9f06debceb673cb Mon Sep 17 00:00:00 2001 From: Erickson Santos Date: Mon, 27 Jul 2015 14:52:47 -0300 Subject: [PATCH] Fix get default quota values for subprojects When getting the default quota value for a project, the DBQuotaDriver is just checking if the default_quota_class CONF is set to True. But this conf should not be considered when getting default quota values for subprojects. Previously, when we asked for the default quota values of a subproject, the default quota values of the root project was returned. Co-Authored-By: Vilobh Meshram Change-Id: Ib88bafca915dfd387086c353c25b2af037e6d50f Closes-bug: #1478651 --- cinder/quota.py | 17 +++++++++-------- cinder/tests/unit/test_quota.py | 12 +----------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/cinder/quota.py b/cinder/quota.py index e547d90bb..8fa1d81ba 100644 --- a/cinder/quota.py +++ b/cinder/quota.py @@ -122,17 +122,18 @@ class DbQuotaDriver(object): quotas = {} default_quotas = {} - if CONF.use_default_quota_class: + if CONF.use_default_quota_class and not parent_project_id: default_quotas = db.quota_class_get_default(context) for resource in resources.values(): - if resource.name not in default_quotas: - versionutils.report_deprecated_feature(LOG, _( - "Default quota for resource: %(res)s is set " - "by the default quota flag: quota_%(res)s, " - "it is now deprecated. Please use the " - "default quota class for default " - "quota.") % {'res': resource.name}) + if default_quotas: + if resource.name not in default_quotas: + versionutils.report_deprecated_feature(LOG, _( + "Default quota for resource: %(res)s is set " + "by the default quota flag: quota_%(res)s, " + "it is now deprecated. Please use the " + "default quota class for default " + "quota.") % {'res': resource.name}) quotas[resource.name] = default_quotas.get(resource.name, (0 if parent_project_id else resource.default)) diff --git a/cinder/tests/unit/test_quota.py b/cinder/tests/unit/test_quota.py index 0dba83377..511345cd7 100644 --- a/cinder/tests/unit/test_quota.py +++ b/cinder/tests/unit/test_quota.py @@ -913,7 +913,6 @@ class DbQuotaDriverTestCase(test.TestCase): def test_subproject_get_defaults(self): # Test subproject default values. - self._stub_quota_class_get_default_subproject() self._stub_volume_type_get_all() parent_project_id = 'test_parent_project_id' result = self.driver.get_defaults(None, @@ -942,13 +941,6 @@ class DbQuotaDriverTestCase(test.TestCase): ) self.stubs.Set(db, 'quota_class_get_default', fake_qcgd) - def _stub_quota_class_get_default_subproject(self): - # Stub out quota_class_get_default for subprojects - def fake_qcgd(context): - self.calls.append('quota_class_get_default') - return {} - self.stubs.Set(db, 'quota_class_get_default', fake_qcgd) - def _stub_volume_type_get_all(self): def fake_vtga(context, inactive=False, filters=None): return {} @@ -1029,7 +1021,6 @@ class DbQuotaDriverTestCase(test.TestCase): self.stubs.Set(db, 'quota_usage_get_all_by_project', fake_qugabp) self._stub_quota_class_get_all_by_name() - self._stub_quota_class_get_default_subproject() def test_get_project_quotas(self): self._stub_get_by_project() @@ -1072,8 +1063,7 @@ class DbQuotaDriverTestCase(test.TestCase): parent_project_id=parent_project_id) self.assertEqual(self.calls, ['quota_get_all_by_project', - 'quota_usage_get_all_by_project', - 'quota_class_get_default', ]) + 'quota_usage_get_all_by_project', ]) self.assertEqual(result, dict(volumes=dict(limit=10, in_use=2, reserved=0, ), -- 2.45.2