quota: remove default kwarg on get_class_quotas()

No code was calling the QuotaDriver.get_class_quotas() method with
anything other the default=True kwarg value (other than unit tests) so
this patch removes that complexity.

Change-Id: If330320e92ba9249ccdad14582119923ac57f885
This commit is contained in:
Jay Pipes 2018-10-24 13:24:05 -04:00
parent 8153cddad1
commit a0f64b80be
2 changed files with 9 additions and 46 deletions

View File

@ -61,8 +61,7 @@ class DbQuotaDriver(object):
return quotas
def get_class_quotas(self, context, resources, quota_class,
defaults=True):
def get_class_quotas(self, context, resources, quota_class):
"""Given a list of resources, retrieve the quotas for the given
quota class.
@ -70,18 +69,14 @@ class DbQuotaDriver(object):
:param resources: A dictionary of the registered resources.
:param quota_class: The name of the quota class to return
quotas for.
:param defaults: If True, the default value will be reported
if there is no specific value for the
resource.
"""
quotas = {}
class_quotas = objects.Quotas.get_all_class_by_name(context,
quota_class)
for resource in resources.values():
if defaults or resource.name in class_quotas:
quotas[resource.name] = class_quotas.get(resource.name,
resource.default)
quotas[resource.name] = class_quotas.get(resource.name,
resource.default)
return quotas
@ -632,8 +627,7 @@ class NoopQuotaDriver(object):
quotas[resource.name] = -1
return quotas
def get_class_quotas(self, context, resources, quota_class,
defaults=True):
def get_class_quotas(self, context, resources, quota_class):
"""Given a list of resources, retrieve the quotas for the given
quota class.
@ -641,9 +635,6 @@ class NoopQuotaDriver(object):
:param resources: A dictionary of the registered resources.
:param quota_class: The name of the quota class to return
quotas for.
:param defaults: If True, the default value will be reported
if there is no specific value for the
resource.
"""
quotas = {}
for resource in resources.values():
@ -913,19 +904,16 @@ class QuotaEngine(object):
return self._driver.get_defaults(context, self._resources)
def get_class_quotas(self, context, quota_class, defaults=True):
def get_class_quotas(self, context, quota_class):
"""Retrieve the quotas for the given quota class.
:param context: The request context, for access checks.
:param quota_class: The name of the quota class to return
quotas for.
:param defaults: If True, the default value will be reported
if there is no specific value for the
resource.
"""
return self._driver.get_class_quotas(context, self._resources,
quota_class, defaults=defaults)
quota_class)
def get_user_quotas(self, context, project_id, user_id, quota_class=None,
defaults=True, usages=True):

View File

@ -285,10 +285,9 @@ class FakeDriver(object):
self.called.append(('get_defaults', context, resources))
return resources
def get_class_quotas(self, context, resources, quota_class,
defaults=True):
def get_class_quotas(self, context, resources, quota_class):
self.called.append(('get_class_quotas', context, resources,
quota_class, defaults))
quota_class))
return resources
def get_user_quotas(self, context, resources, project_id, user_id,
@ -444,16 +443,12 @@ class QuotaEngineTestCase(test.TestCase):
driver = FakeDriver()
quota_obj = self._make_quota_obj(driver)
result1 = quota_obj.get_class_quotas(context, 'test_class')
result2 = quota_obj.get_class_quotas(context, 'test_class', False)
self.assertEqual(driver.called, [
('get_class_quotas', context, quota_obj._resources,
'test_class', True),
('get_class_quotas', context, quota_obj._resources,
'test_class', False),
'test_class'),
])
self.assertEqual(result1, quota_obj._resources)
self.assertEqual(result2, quota_obj._resources)
def test_get_user_quotas(self):
context = FakeContext(None, None)
@ -667,19 +662,6 @@ class DbQuotaDriverTestCase(test.TestCase):
server_group_members=10,
))
def test_get_class_quotas_no_defaults(self):
self._stub_quota_class_get_all_by_name()
result = self.driver.get_class_quotas(None, quota.QUOTAS._resources,
'test_class', False)
self.assertEqual(self.calls, ['quota_class_get_all_by_name'])
self.assertEqual(result, dict(
instances=5,
ram=25 * 1024,
metadata_items=64,
injected_file_content_bytes=5 * 1024,
))
def _stub_get_by_project_and_user(self):
def fake_qgabpau(context, project_id, user_id):
self.calls.append('quota_get_all_by_project_and_user')
@ -2020,13 +2002,6 @@ class NoopQuotaDriverTestCase(test.TestCase):
'test_class')
self.assertEqual(self.expected_without_dict, result)
def test_get_class_quotas_no_defaults(self):
result = self.driver.get_class_quotas(None,
quota.QUOTAS._resources,
'test_class',
False)
self.assertEqual(self.expected_without_dict, result)
def test_get_project_quotas(self):
result = self.driver.get_project_quotas(None,
quota.QUOTAS._resources,