summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nova/quota.py15
-rw-r--r--nova/tests/test_quota.py9
2 files changed, 14 insertions, 10 deletions
diff --git a/nova/quota.py b/nova/quota.py
index b98282ecb1..20225b3b5a 100644
--- a/nova/quota.py
+++ b/nova/quota.py
@@ -452,16 +452,11 @@ class DbQuotaDriver(object):
(user_quotas[key] >= 0 and user_quotas[key] < val)]
if overs:
headroom = {}
- # Check project_quotas:
- for key in quotas:
- if quotas[key] >= 0 and quotas[key] < val:
- headroom[key] = quotas[key]
- # Check user quotas:
- for key in user_quotas:
- if (user_quotas[key] >= 0 and user_quotas[key] < val and
- headroom.get(key) > user_quotas[key]):
- headroom[key] = user_quotas[key]
-
+ for key in overs:
+ headroom[key] = min(
+ val for val in (quotas.get(key), project_quotas.get(key))
+ if val is not None
+ )
raise exception.OverQuota(overs=sorted(overs), quotas=quotas,
usages={}, headroom=headroom)
diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py
index b00ed7e9e1..763c85d39b 100644
--- a/nova/tests/test_quota.py
+++ b/nova/tests/test_quota.py
@@ -1947,6 +1947,15 @@ class DbQuotaDriverTestCase(test.TestCase):
quota.QUOTAS._resources,
dict(metadata_items=129))
+ def test_limit_check_project_overs(self):
+ self._stub_get_project_quotas()
+ self.assertRaises(exception.OverQuota,
+ self.driver.limit_check,
+ FakeContext('test_project', 'test_class'),
+ quota.QUOTAS._resources,
+ dict(injected_file_content_bytes=10241,
+ injected_file_path_bytes=256))
+
def test_limit_check_unlimited(self):
self.flags(quota_metadata_items=-1)
self._stub_get_project_quotas()