Fix `NoopQuotaDriver.get_(project|user)_quotas` format
The quota API extension expects `get_project_quotas` and `get_user_quotas` to
return a dictionary where the value is another dictionary with a `limit` key.
The `DbQuotaDriver` adhered to this spec, but the `NoopQuotaDriver` didn't.
This fixes the `NoopQuotaDriver` to return the results in the correct format.
Fixes bug 1244842
Change-Id: Iea274dab1c3f10c3cb0a2815f431e15b4d4934b1
(cherry picked from commit 711a12b402
)
This commit is contained in:
parent
f7cfc1cc6b
commit
a520438584
|
@ -651,6 +651,18 @@ class NoopQuotaDriver(object):
|
|||
quotas[resource.name] = -1
|
||||
return quotas
|
||||
|
||||
def _get_noop_quotas(self, resources, usages=None, remains=False):
|
||||
quotas = {}
|
||||
for resource in resources.values():
|
||||
quotas[resource.name] = {}
|
||||
quotas[resource.name]['limit'] = -1
|
||||
if usages:
|
||||
quotas[resource.name]['in_use'] = -1
|
||||
quotas[resource.name]['reserved'] = -1
|
||||
if remains:
|
||||
quotas[resource.name]['remains'] = -1
|
||||
return quotas
|
||||
|
||||
def get_user_quotas(self, context, resources, project_id, user_id,
|
||||
quota_class=None, defaults=True,
|
||||
usages=True):
|
||||
|
@ -674,10 +686,7 @@ class NoopQuotaDriver(object):
|
|||
:param usages: If True, the current in_use and reserved counts
|
||||
will also be returned.
|
||||
"""
|
||||
quotas = {}
|
||||
for resource in resources.values():
|
||||
quotas[resource.name] = -1
|
||||
return quotas
|
||||
return self._get_noop_quotas(resources, usages=usages)
|
||||
|
||||
def get_project_quotas(self, context, resources, project_id,
|
||||
quota_class=None, defaults=True,
|
||||
|
@ -703,10 +712,7 @@ class NoopQuotaDriver(object):
|
|||
:param remains: If True, the current remains of the project will
|
||||
will be returned.
|
||||
"""
|
||||
quotas = {}
|
||||
for resource in resources.values():
|
||||
quotas[resource.name] = -1
|
||||
return quotas
|
||||
return self._get_noop_quotas(resources, usages=usages, remains=remains)
|
||||
|
||||
def get_settable_quotas(self, context, resources, project_id,
|
||||
user_id=None):
|
||||
|
|
|
@ -2356,47 +2356,55 @@ class NoopQuotaDriverTestCase(test.TestCase):
|
|||
max_age=0,
|
||||
)
|
||||
|
||||
self.expected_quotas = dict([(r, -1)
|
||||
for r in quota.QUOTAS._resources])
|
||||
self.expected_with_usages = {}
|
||||
self.expected_without_usages = {}
|
||||
self.expected_without_dict = {}
|
||||
for r in quota.QUOTAS._resources:
|
||||
self.expected_with_usages[r] = dict(limit=-1,
|
||||
in_use=-1,
|
||||
reserved=-1)
|
||||
self.expected_without_usages[r] = dict(limit=-1)
|
||||
self.expected_without_dict[r] = -1
|
||||
|
||||
self.driver = quota.NoopQuotaDriver()
|
||||
|
||||
def test_get_defaults(self):
|
||||
# Use our pre-defined resources
|
||||
result = self.driver.get_defaults(None, quota.QUOTAS._resources)
|
||||
self.assertEqual(self.expected_quotas, result)
|
||||
self.assertEqual(self.expected_without_dict, result)
|
||||
|
||||
def test_get_class_quotas(self):
|
||||
result = self.driver.get_class_quotas(None,
|
||||
quota.QUOTAS._resources,
|
||||
'test_class')
|
||||
self.assertEqual(self.expected_quotas, result)
|
||||
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_quotas, result)
|
||||
self.assertEqual(self.expected_without_dict, result)
|
||||
|
||||
def test_get_project_quotas(self):
|
||||
result = self.driver.get_project_quotas(None,
|
||||
quota.QUOTAS._resources,
|
||||
'test_project')
|
||||
self.assertEqual(self.expected_quotas, result)
|
||||
self.assertEqual(self.expected_with_usages, result)
|
||||
|
||||
def test_get_user_quotas(self):
|
||||
result = self.driver.get_user_quotas(None,
|
||||
quota.QUOTAS._resources,
|
||||
'test_project',
|
||||
'fake_user')
|
||||
self.assertEqual(self.expected_quotas, result)
|
||||
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_quotas, result)
|
||||
self.assertEqual(self.expected_with_usages, result)
|
||||
|
||||
def test_get_user_quotas_no_defaults(self):
|
||||
result = self.driver.get_user_quotas(None,
|
||||
|
@ -2404,14 +2412,14 @@ class NoopQuotaDriverTestCase(test.TestCase):
|
|||
'test_project',
|
||||
'fake_user',
|
||||
defaults=False)
|
||||
self.assertEqual(self.expected_quotas, result)
|
||||
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,
|
||||
'test_project',
|
||||
usages=False)
|
||||
self.assertEqual(self.expected_quotas, result)
|
||||
self.assertEqual(self.expected_without_usages, result)
|
||||
|
||||
def test_get_user_quotas_no_usages(self):
|
||||
result = self.driver.get_user_quotas(None,
|
||||
|
@ -2419,4 +2427,4 @@ class NoopQuotaDriverTestCase(test.TestCase):
|
|||
'test_project',
|
||||
'fake_user',
|
||||
usages=False)
|
||||
self.assertEqual(self.expected_quotas, result)
|
||||
self.assertEqual(self.expected_without_usages, result)
|
||||
|
|
Loading…
Reference in New Issue