From 1447b8117bc4de27243913208ead210b8f36d635 Mon Sep 17 00:00:00 2001 From: Tianpeng Wang Date: Tue, 26 Nov 2013 13:10:40 +0000 Subject: [PATCH] Fix incorrect argument position in DbQuotaDriver The prototype of db.quota_get is: `quota_get(context, project_id, resource, user_id=None)` However, in DbQuotaDriver::get_by_project_and_user(), the `user_id` is incorrectly used as a positional argument. Closes-Bug: #1255035 Change-Id: I5b6a4c59efe6d9bdc8380e50b7f7c1ff0d2029b1 --- nova/quota.py | 2 +- nova/tests/test_quota.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/nova/quota.py b/nova/quota.py index d023a55f1da..ee2451c4f88 100644 --- a/nova/quota.py +++ b/nova/quota.py @@ -97,7 +97,7 @@ class DbQuotaDriver(object): def get_by_project_and_user(self, context, project_id, user_id, resource): """Get a specific quota by project and user.""" - return db.quota_get(context, project_id, user_id, resource) + return db.quota_get(context, project_id, resource, user_id=user_id) def get_by_project(self, context, project_id, resource): """Get a specific quota by project.""" diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py index 498d1d1fa3d..31621bff064 100644 --- a/nova/tests/test_quota.py +++ b/nova/tests/test_quota.py @@ -977,6 +977,28 @@ def test_get_user_quotas(self): ), )) + def _stub_get_by_project_and_user_specific(self): + def fake_quota_get(context, project_id, resource, user_id=None): + self.calls.append('quota_get') + self.assertEqual(project_id, 'test_project') + self.assertEqual(user_id, 'fake_user') + self.assertEqual(resource, 'test_resource') + return dict( + test_resource=dict(in_use=20, reserved=10), + ) + self.stubs.Set(db, 'quota_get', fake_quota_get) + + def test_get_by_project_and_user(self): + self._stub_get_by_project_and_user_specific() + result = self.driver.get_by_project_and_user( + FakeContext('test_project', 'test_class'), + 'test_project', 'fake_user', 'test_resource') + + self.assertEqual(self.calls, ['quota_get']) + self.assertEqual(result, dict( + test_resource=dict(in_use=20, reserved=10), + )) + def _stub_get_by_project(self): def fake_qgabp(context, project_id): self.calls.append('quota_get_all_by_project')