diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 9bb81b2e8e7c..7f1e513fbaaf 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -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 diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index 0efce4e3bab9..d4a79114ab1c 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -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)