Merge "Make query to quota usage table order preserved"

This commit is contained in:
Jenkins 2015-09-17 21:14:36 +00:00 committed by Gerrit Code Review
commit 33c3191dc9
2 changed files with 11 additions and 3 deletions

View File

@ -3373,9 +3373,10 @@ def _get_project_user_quota_usages(context, session, project_id,
rows = model_query(context, models.QuotaUsage,
read_deleted="no",
session=session).\
filter_by(project_id=project_id).\
with_lockmode('update').\
all()
filter_by(project_id=project_id).\
order_by(models.QuotaUsage.id.asc()).\
with_lockmode('update').\
all()
proj_result = dict()
user_result = dict()
# Get the total count of in_use,reserved

View File

@ -6740,6 +6740,13 @@ class QuotaTestCase(test.TestCase, ModelsObjectComparatorMixin):
self.assertEqual(expected, db.quota_usage_get_all_by_project_and_user(
self.ctxt, 'p1', 'u1'))
def test_get_project_user_quota_usages_in_order(self):
_quota_reserve(self.ctxt, 'p1', 'u1')
with mock.patch.object(query.Query, 'order_by') as order_mock:
sqlalchemy_api._get_project_user_quota_usages(
self.ctxt, None, 'p1', 'u1')
self.assertTrue(order_mock.called)
def test_quota_usage_update_nonexistent(self):
self.assertRaises(exception.QuotaUsageNotFound, db.quota_usage_update,
self.ctxt, 'p1', 'u1', 'resource', in_use=42)