]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix get default quota values for subprojects
authorErickson Santos <erickson@lsd.ufcg.edu.br>
Mon, 27 Jul 2015 17:52:47 +0000 (14:52 -0300)
committerVilobh Meshram <vilobhmm@yahoo-inc.com>
Tue, 28 Jul 2015 21:26:39 +0000 (14:26 -0700)
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 <vilobhmm@yahoo-inc.com>
Change-Id: Ib88bafca915dfd387086c353c25b2af037e6d50f
Closes-bug: #1478651

cinder/quota.py
cinder/tests/unit/test_quota.py

index e547d90bbfc2f42a38f267e9be5f97c9386acf95..8fa1d81ba33ec7bbe77c51fa16dc608891030b8d 100644 (file)
@@ -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))
index 0dba833775b216709e457d45959150d767230a47..511345cd769709949f63115f51654095493b0e05 100644 (file)
@@ -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, ),