Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
User quota update should not exceed project quota
Browse files Browse the repository at this point in the history
When user quota is not set, the default quota set in
config file will be used as the default user quota,
this will break the logic of user quota (the default
user quota should be restricted by the project quota)

Fixes bug 1208400
Fixes bug 1205582

Change-Id: Id98d504d8f5e0dda642fa5e7c550acea79520c3d
  • Loading branch information
liyingjun committed Aug 13, 2013
1 parent bec54ac commit 4d5ce85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions openstack/common/quota.py
Expand Up @@ -305,6 +305,11 @@ def get_user_quotas(self, context, resources, project_id, user_id,
"""
user_quotas = self.db.quota_get_all_by_project_and_user(
context, project_id, user_id)
# Use the project quota for default user quota.
proj_quotas = self.db.quota_get_all_by_project(context, project_id)
for key, value in proj_quotas.iteritems():
if key not in user_quotas:
user_quotas[key] = value
user_usages = None
if usages:
user_usages = self.db.quota_usage_get_all_by_project_and_user(
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_quota.py
Expand Up @@ -83,6 +83,7 @@ def setUp(self):
dbapi.quota_usage_get_all_by_project = mock.Mock(
return_value=dict([('r%d' % i, {'in_use': i, 'reserved': i + 1})
for i in range(3)]))
self.dbapi = dbapi
self.driver = quota.DbQuotaDriver(dbapi)
self.ctxt = FakeContext()
return super(DbQuotaDriverTestCase, self).setUp()
Expand Down Expand Up @@ -126,6 +127,18 @@ def test_get_user_quotas(self):
'r2': {'in_use': 3, 'limit': 6, 'reserved': 2}}
self.assertEqual(actual, expected)

def test_get_default_user_quotas(self):
self.dbapi.quota_get_all_by_project_and_user = mock.Mock(
return_value={'project_id': 'p1', 'user_id': 'u1'})
self.dbapi.quota_get_all_by_project = mock.Mock(
return_value={'r1': 5, 'r2': 6})
driver = quota.DbQuotaDriver(self.dbapi)
actual = driver.get_user_quotas(
self.ctxt, self.sample_resources.copy(), 'p1', 'u1')
expected = {'r1': {'in_use': 2, 'limit': 5, 'reserved': 1},
'r2': {'in_use': 3, 'limit': 6, 'reserved': 2}}
self.assertEqual(actual, expected)

def test_get_settable_quotas(self):
actual = self.driver.get_settable_quotas(self.ctxt,
self.sample_resources, 'p1')
Expand Down

0 comments on commit 4d5ce85

Please sign in to comment.