Fix _quota_reserve test setup for incompatible type checking

The db.quota_reserve() method expects to get project_quotas and
user_quotas as dicts that map resource types to limits which are ints.

The _quota_reserve test setup method was just mapping the resource type
to the Quota sqlalchemy dict-like object that was coming back from
db.quota_create. Since db._calculate_overquota compares the delta (int)
to the user_quotas/project_quotas value, which was a Quota object, and
py34 doesn't allow incompatible type checks like that, this fails with
py34.

This fixes the _quota_reserve test setup method to map the resource type
to the hard_limit like the actual DB APIs do in the normal nova.quota
flows.  It also has to adjust the setup method to avoid going over-quota
immediately due to the limit and usage being the same (which is why we
add a buffer to the i value for the limit).

Closes-Bug: #1461665

Change-Id: I9f5f537eff58fe83caa7bff2fb0800ce9f7272fa
This commit is contained in:
Matt Riedemann 2015-06-03 19:00:02 -07:00
parent 13beb4edc7
commit 27236e3d6a
1 changed files with 8 additions and 5 deletions

View File

@ -106,14 +106,16 @@ def _quota_reserve(context, project_id, user_id):
# test for project level resources
resource = 'fixed_ips'
quotas[resource] = db.quota_create(context,
project_id, resource, i)
project_id,
resource, i + 2).hard_limit
user_quotas[resource] = quotas[resource]
else:
quotas[resource] = db.quota_create(context,
project_id, resource, i)
project_id,
resource, i + 1).hard_limit
user_quotas[resource] = db.quota_create(context, project_id,
resource, i,
user_id=user_id)
resource, i + 1,
user_id=user_id).hard_limit
sync_name = '_sync_%s' % resource
resources[resource] = quota.ReservableResource(
resource, sync_name, 'quota_res_%d' % i)
@ -6194,7 +6196,8 @@ class QuotaTestCase(test.TestCase, ModelsObjectComparatorMixin):
for i, resource in enumerate(quota.resources):
if isinstance(resource, quota.ReservableResource):
quotas[resource.name] = db.quota_create(self.ctxt, 'project1',
resource.name, 100)
resource.name,
100).hard_limit
deltas[resource.name] = i
reservable_resources[resource.name] = resource