Merge "quota: remove defaults kwarg in get_project_quotas"

This commit is contained in:
Zuul 2019-02-26 13:26:24 +00:00 committed by Gerrit Code Review
commit f7fd6cb58b
2 changed files with 20 additions and 129 deletions

View File

@ -81,7 +81,7 @@ class DbQuotaDriver(object):
return quotas
def _process_quotas(self, context, resources, project_id, quotas,
quota_class=None, defaults=True, usages=None,
quota_class=None, usages=None,
remains=False):
modified_quotas = {}
# Get the quotas for the appropriate class. If the project ID
@ -99,10 +99,6 @@ class DbQuotaDriver(object):
default_quotas = self.get_defaults(context, resources)
for resource in resources.values():
# Omit default/quota class values
if not defaults and resource.name not in quotas:
continue
limit = quotas.get(resource.name, class_quotas.get(
resource.name, default_quotas[resource.name]))
modified_quotas[resource.name] = dict(limit=limit)
@ -194,7 +190,7 @@ class DbQuotaDriver(object):
return usages
def get_user_quotas(self, context, resources, project_id, user_id,
quota_class=None, defaults=True,
quota_class=None,
usages=True, project_quotas=None,
user_quotas=None):
"""Given a list of resources, retrieve the quotas for the given
@ -209,10 +205,6 @@ class DbQuotaDriver(object):
parameter allows it to be specified. It
will be ignored if project_id ==
context.project_id.
:param defaults: If True, the quota class value (or the
default value, if there is no value from the
quota class) will be reported if there is no
specific value for the resource.
:param usages: If True, the current counts will also be returned.
:param project_quotas: Quotas dictionary for the specified project.
:param user_quotas: Quotas dictionary for the specified project
@ -235,10 +227,10 @@ class DbQuotaDriver(object):
user_id=user_id)
return self._process_quotas(context, resources, project_id,
user_quotas, quota_class,
defaults=defaults, usages=user_usages)
usages=user_usages)
def get_project_quotas(self, context, resources, project_id,
quota_class=None, defaults=True,
quota_class=None,
usages=True, remains=False, project_quotas=None):
"""Given a list of resources, retrieve the quotas for the given
project.
@ -251,10 +243,6 @@ class DbQuotaDriver(object):
parameter allows it to be specified. It
will be ignored if project_id ==
context.project_id.
:param defaults: If True, the quota class value (or the
default value, if there is no value from the
quota class) will be reported if there is no
specific value for the resource.
:param usages: If True, the current counts will also be returned.
:param remains: If True, the current remains of the project will
will be returned.
@ -267,7 +255,7 @@ class DbQuotaDriver(object):
project_usages = self._get_usages(context, resources, project_id)
return self._process_quotas(context, resources, project_id,
project_quotas, quota_class,
defaults=defaults, usages=project_usages,
usages=project_usages,
remains=remains)
def _is_unlimited_value(self, v):
@ -653,7 +641,7 @@ class NoopQuotaDriver(object):
return quotas
def get_user_quotas(self, context, resources, project_id, user_id,
quota_class=None, defaults=True,
quota_class=None,
usages=True):
"""Given a list of resources, retrieve the quotas for the given
user and project.
@ -667,16 +655,12 @@ class NoopQuotaDriver(object):
parameter allows it to be specified. It
will be ignored if project_id ==
context.project_id.
:param defaults: If True, the quota class value (or the
default value, if there is no value from the
quota class) will be reported if there is no
specific value for the resource.
:param usages: If True, the current counts will also be returned.
"""
return self._get_noop_quotas(resources, usages=usages)
def get_project_quotas(self, context, resources, project_id,
quota_class=None, defaults=True,
quota_class=None,
usages=True, remains=False):
"""Given a list of resources, retrieve the quotas for the given
project.
@ -689,10 +673,6 @@ class NoopQuotaDriver(object):
parameter allows it to be specified. It
will be ignored if project_id ==
context.project_id.
:param defaults: If True, the quota class value (or the
default value, if there is no value from the
quota class) will be reported if there is no
specific value for the resource.
:param usages: If True, the current counts will also be returned.
:param remains: If True, the current remains of the project will
will be returned.
@ -919,7 +899,7 @@ class QuotaEngine(object):
quota_class)
def get_user_quotas(self, context, project_id, user_id, quota_class=None,
defaults=True, usages=True):
usages=True):
"""Retrieve the quotas for the given user and project.
:param context: The request context, for access checks.
@ -928,21 +908,16 @@ class QuotaEngine(object):
:param quota_class: If project_id != context.project_id, the
quota class cannot be determined. This
parameter allows it to be specified.
:param defaults: If True, the quota class value (or the
default value, if there is no value from the
quota class) will be reported if there is no
specific value for the resource.
:param usages: If True, the current counts will also be returned.
"""
return self._driver.get_user_quotas(context, self._resources,
project_id, user_id,
quota_class=quota_class,
defaults=defaults,
usages=usages)
def get_project_quotas(self, context, project_id, quota_class=None,
defaults=True, usages=True, remains=False):
usages=True, remains=False):
"""Retrieve the quotas for the given project.
:param context: The request context, for access checks.
@ -950,10 +925,6 @@ class QuotaEngine(object):
:param quota_class: If project_id != context.project_id, the
quota class cannot be determined. This
parameter allows it to be specified.
:param defaults: If True, the quota class value (or the
default value, if there is no value from the
quota class) will be reported if there is no
specific value for the resource.
:param usages: If True, the current counts will also be returned.
:param remains: If True, the current remains of the project will
will be returned.
@ -962,7 +933,6 @@ class QuotaEngine(object):
return self._driver.get_project_quotas(context, self._resources,
project_id,
quota_class=quota_class,
defaults=defaults,
usages=usages,
remains=remains)

View File

@ -301,17 +301,17 @@ class FakeDriver(object):
return resources
def get_user_quotas(self, context, resources, project_id, user_id,
quota_class=None, defaults=True, usages=True):
quota_class=None, usages=True):
self.called.append(('get_user_quotas', context, resources,
project_id, user_id, quota_class, defaults,
project_id, user_id, quota_class,
usages))
return resources
def get_project_quotas(self, context, resources, project_id,
quota_class=None, defaults=True, usages=True,
quota_class=None, usages=True,
remains=False):
self.called.append(('get_project_quotas', context, resources,
project_id, quota_class, defaults, usages,
project_id, quota_class, usages,
remains))
return resources
@ -447,14 +447,13 @@ class QuotaEngineTestCase(test.TestCase):
result2 = quota_obj.get_user_quotas(context, 'test_project',
'fake_user',
quota_class='test_class',
defaults=False,
usages=False)
self.assertEqual(driver.called, [
('get_user_quotas', context, quota_obj._resources,
'test_project', 'fake_user', None, True, True),
'test_project', 'fake_user', None, True),
('get_user_quotas', context, quota_obj._resources,
'test_project', 'fake_user', 'test_class', False, False),
'test_project', 'fake_user', 'test_class', False),
])
self.assertEqual(result1, quota_obj._resources)
self.assertEqual(result2, quota_obj._resources)
@ -466,14 +465,13 @@ class QuotaEngineTestCase(test.TestCase):
result1 = quota_obj.get_project_quotas(context, 'test_project')
result2 = quota_obj.get_project_quotas(context, 'test_project',
quota_class='test_class',
defaults=False,
usages=False)
self.assertEqual(driver.called, [
('get_project_quotas', context, quota_obj._resources,
'test_project', None, True, True, False),
'test_project', None, True, False),
('get_project_quotas', context, quota_obj._resources,
'test_project', 'test_class', False, False, False),
'test_project', 'test_class', False, False),
])
self.assertEqual(result1, quota_obj._resources)
self.assertEqual(result2, quota_obj._resources)
@ -1334,68 +1332,6 @@ class DbQuotaDriverTestCase(test.TestCase):
),
))
@mock.patch('nova.quota.DbQuotaDriver._get_usages',
side_effect=_get_fake_get_usages())
def test_get_user_quotas_no_defaults(self, mock_get_usages):
self._stub_get_by_project_and_user()
ctxt = FakeContext('test_project', 'test_class')
result = self.driver.get_user_quotas(
ctxt, quota.QUOTAS._resources, 'test_project', 'fake_user',
defaults=False)
self.assertEqual(self.calls, [
'quota_get_all_by_project_and_user',
'quota_get_all_by_project',
'quota_class_get_all_by_name',
])
mock_get_usages.assert_called_once_with(ctxt, quota.QUOTAS._resources,
'test_project',
user_id='fake_user')
self.assertEqual(result, dict(
cores=dict(
limit=10,
in_use=4,
),
injected_files=dict(
limit=2,
in_use=0,
),
injected_file_path_bytes=dict(
limit=127,
in_use=0,
),
))
@mock.patch('nova.quota.DbQuotaDriver._get_usages',
side_effect=_get_fake_get_usages())
def test_get_project_quotas_no_defaults(self, mock_get_usages):
self._stub_get_by_project()
ctxt = FakeContext('test_project', 'test_class')
result = self.driver.get_project_quotas(
ctxt, quota.QUOTAS._resources, 'test_project', defaults=False)
self.assertEqual(self.calls, [
'quota_get_all_by_project',
'quota_class_get_all_by_name',
'quota_class_get_default',
])
mock_get_usages.assert_called_once_with(ctxt, quota.QUOTAS._resources,
'test_project')
self.assertEqual(result, dict(
cores=dict(
limit=10,
in_use=4,
),
injected_files=dict(
limit=2,
in_use=0,
),
injected_file_path_bytes=dict(
limit=127,
in_use=0,
),
))
def test_get_user_quotas_no_usages(self):
self._stub_get_by_project_and_user()
result = self.driver.get_user_quotas(
@ -1515,7 +1451,7 @@ class DbQuotaDriverTestCase(test.TestCase):
return {'floating_ips': 20}
def fake_get_project_quotas(dbdrv, context, resources, project_id,
quota_class=None, defaults=True,
quota_class=None,
usages=True, remains=False,
project_quotas=None):
self.calls.append('get_project_quotas')
@ -1543,7 +1479,7 @@ class DbQuotaDriverTestCase(test.TestCase):
def fake_process_quotas_in_get_user_quotas(dbdrv, context, resources,
project_id, quotas,
quota_class=None,
defaults=True, usages=None,
usages=None,
remains=False):
self.calls.append('_process_quotas')
result = {}
@ -1784,7 +1720,7 @@ class DbQuotaDriverTestCase(test.TestCase):
def _stub_get_project_quotas(self):
def fake_get_project_quotas(dbdrv, context, resources, project_id,
quota_class=None, defaults=True,
quota_class=None,
usages=True, remains=False,
project_quotas=None):
self.calls.append('get_project_quotas')
@ -1998,21 +1934,6 @@ class NoopQuotaDriverTestCase(test.TestCase):
'fake_user')
self.assertEqual(self.expected_with_usages, result)
def test_get_project_quotas_no_defaults(self):
result = self.driver.get_project_quotas(None,
quota.QUOTAS._resources,
'test_project',
defaults=False)
self.assertEqual(self.expected_with_usages, result)
def test_get_user_quotas_no_defaults(self):
result = self.driver.get_user_quotas(None,
quota.QUOTAS._resources,
'test_project',
'fake_user',
defaults=False)
self.assertEqual(self.expected_with_usages, result)
def test_get_project_quotas_no_usages(self):
result = self.driver.get_project_quotas(None,
quota.QUOTAS._resources,