Skip to content

Commit

Permalink
Fix NoopQuotaDriver.get_(project|user)_quotas format
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rconradharris committed Nov 1, 2013
1 parent c6e54d4 commit 711a12b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
22 changes: 14 additions & 8 deletions nova/quota.py
Expand Up @@ -651,6 +651,18 @@ def get_class_quotas(self, context, resources, quota_class,
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):
Expand All @@ -674,10 +686,7 @@ def get_user_quotas(self, context, resources, project_id, user_id,
: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,
Expand All @@ -703,10 +712,7 @@ def get_project_quotas(self, context, resources, project_id,
: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):
Expand Down
30 changes: 19 additions & 11 deletions nova/tests/test_quota.py
Expand Up @@ -2356,67 +2356,75 @@ def setUp(self):
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,
quota.QUOTAS._resources,
'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,
quota.QUOTAS._resources,
'test_project',
'fake_user',
usages=False)
self.assertEqual(self.expected_quotas, result)
self.assertEqual(self.expected_without_usages, result)

0 comments on commit 711a12b

Please sign in to comment.