summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorKevin L. Mitchell <kevin.mitchell@rackspace.com>2012-10-30 18:03:29 -0500
committerGerrit Code Review <review@openstack.org>2012-10-31 15:07:54 +0000
commitdaf78cfb970af42242466c7edb082bdb7bbbb118 (patch)
tree7f5b1ef5b5a76095125724831142b6d0d56c6252 /nova/tests
parentefc291257fb8655ab57e77c57de23f15968af998 (diff)
Add call to reset quota usage
There are certain circumstances where we may need to indicate an uncertainty in a user's current usage of a given resource, thus forcing a recount of those resources currently in use. This adds a QUOTAS.usage_reset() call which can be used to do this. It works by resetting the current usage to -1, which will force the usage record to be refreshed the next time that user reserves those resources. Change-Id: I4a40c8edcc78ed9a7d18a293d4d7d6418b04b7f2
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_quota.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py
index 5ec753efe..5cc5dedde 100644
--- a/nova/tests/test_quota.py
+++ b/nova/tests/test_quota.py
@@ -304,6 +304,9 @@ class FakeDriver(object):
def rollback(self, context, reservations):
self.called.append(('rollback', context, reservations))
+ def usage_reset(self, context, resources):
+ self.called.append(('usage_reset', context, resources))
+
def destroy_all_by_project(self, context, project_id):
self.called.append(('destroy_all_by_project', context, project_id))
@@ -664,6 +667,16 @@ class QuotaEngineTestCase(test.TestCase):
('rollback', context, ['resv-01', 'resv-02', 'resv-03']),
])
+ def test_usage_reset(self):
+ context = FakeContext(None, None)
+ driver = FakeDriver()
+ quota_obj = self._make_quota_obj(driver)
+ quota_obj.usage_reset(context, ['res1', 'res2', 'res3'])
+
+ self.assertEqual(driver.called, [
+ ('usage_reset', context, ['res1', 'res2', 'res3']),
+ ])
+
def test_destroy_all_by_project(self):
context = FakeContext(None, None)
driver = FakeDriver()
@@ -1362,6 +1375,35 @@ class DbQuotaDriverTestCase(test.TestCase):
])
self.assertEqual(result, ['resv-1', 'resv-2', 'resv-3'])
+ def test_usage_reset(self):
+ calls = []
+
+ def fake_quota_usage_update(context, project_id, resource, **kwargs):
+ calls.append(('quota_usage_update', context, project_id,
+ resource, kwargs))
+ if resource == 'nonexist':
+ raise exception.QuotaUsageNotFound()
+ self.stubs.Set(db, 'quota_usage_update', fake_quota_usage_update)
+
+ ctx = FakeContext('test_project', 'test_class')
+ resources = ['res1', 'res2', 'nonexist', 'res4']
+ self.driver.usage_reset(ctx, resources)
+
+ # Make sure we had some calls
+ self.assertEqual(len(calls), len(resources))
+
+ # Extract the elevated context that was used and do some
+ # sanity checks
+ elevated = calls[0][1]
+ self.assertEqual(elevated.project_id, ctx.project_id)
+ self.assertEqual(elevated.quota_class, ctx.quota_class)
+ self.assertEqual(elevated.is_admin, True)
+
+ # Now check that all the expected calls were made
+ exemplar = [('quota_usage_update', elevated, 'test_project',
+ res, dict(in_use=-1)) for res in resources]
+ self.assertEqual(calls, exemplar)
+
class FakeSession(object):
def begin(self):