From ee45707a4917b5d59a99f1cb0609cf90b3384a35 Mon Sep 17 00:00:00 2001 From: mjbright Date: Mon, 14 Oct 2013 11:12:19 -0700 Subject: [PATCH] Moved quota headroom calculations into quota_reserve Moved headroom calculations into quota_reserve and modified headroom calculations to take into account -ve quota limits (unlimited) on cores and ram. Updated test cases to generate OverQuota exceptions with new headroom parameter. Added new tests for 'unlimited' quotas to test_quota.py in QuotaIntegrationTestCase and DbQuotaDriverTestCase classes. Add Exception kwargs checking for OverQuota and QuotaError exceptions. Change-Id: I855b0cad495182c5c4ee42b2acf5eedd198557b5 Closes-Bug: #1224453 min_count ignored for instance create --- nova/quota.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/nova/quota.py b/nova/quota.py index 719f89462..121b83583 100644 --- a/nova/quota.py +++ b/nova/quota.py @@ -405,11 +405,22 @@ class DbQuotaDriver(object): # Check the quotas and construct a list of the resources that # would be put over limit by the desired values overs = [key for key, val in values.items() - if (quotas[key] >= 0 and quotas[key] < val) or + if quotas[key] >= 0 and quotas[key] < val or (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] + raise exception.OverQuota(overs=sorted(overs), quotas=quotas, - usages={}) + usages={}, headroom=headroom) def reserve(self, context, resources, deltas, expire=None, project_id=None, user_id=None):