Permalink
Browse files

Treat -1 quotas as unlimited.

Updates quota db API calls so they treat -1 quotas as unlimited
for consistency with the Nova flags.

Fixes LP Bug #972034.

Change-Id: I56456c2780110f8fd55afa9d1fe30193bf99d928
  • Loading branch information...
1 parent 15ce773 commit d9465624ba68e513c02539c685d5d834ca3094ba @dprince dprince committed with vishvananda Apr 3, 2012
Showing with 30 additions and 0 deletions.
  1. +6 −0 nova/db/sqlalchemy/api.py
  2. +24 −0 nova/tests/test_quota.py
@@ -2232,6 +2232,9 @@ def quota_get_all_by_project(context, project_id):
@require_admin_context
def quota_create(context, project_id, resource, limit):
+ # NOTE: Treat -1 as unlimited for consistency w/ flags
+ if limit == -1:
+ limit = None
quota_ref = models.Quota()
quota_ref.project_id = project_id
quota_ref.resource = resource
@@ -2242,6 +2245,9 @@ def quota_create(context, project_id, resource, limit):
@require_admin_context
def quota_update(context, project_id, resource, limit):
+ # NOTE: Treat -1 as unlimited for consistency w/ flags
+ if limit == -1:
+ limit = None
session = get_session()
with session.begin():
quota_ref = quota_get(context, project_id, resource, session=session)
View
@@ -152,6 +152,10 @@ def test_unlimited_instances(self):
num_instances = quota.allowed_instances(self.context, 100,
instance_type)
self.assertEqual(num_instances, 100)
+ db.quota_create(self.context, self.project_id, 'instances', -1)
+ num_instances = quota.allowed_instances(self.context, 100,
+ instance_type)
+ self.assertEqual(num_instances, 100)
num_instances = quota.allowed_instances(self.context, 101,
instance_type)
self.assertEqual(num_instances, 101)
@@ -166,6 +170,10 @@ def test_unlimited_ram(self):
num_instances = quota.allowed_instances(self.context, 100,
instance_type)
self.assertEqual(num_instances, 100)
+ db.quota_create(self.context, self.project_id, 'ram', -1)
+ num_instances = quota.allowed_instances(self.context, 100,
+ instance_type)
+ self.assertEqual(num_instances, 100)
num_instances = quota.allowed_instances(self.context, 101,
instance_type)
self.assertEqual(num_instances, 101)
@@ -180,6 +188,10 @@ def test_unlimited_cores(self):
num_instances = quota.allowed_instances(self.context, 100,
instance_type)
self.assertEqual(num_instances, 100)
+ db.quota_create(self.context, self.project_id, 'cores', -1)
+ num_instances = quota.allowed_instances(self.context, 100,
+ instance_type)
+ self.assertEqual(num_instances, 100)
num_instances = quota.allowed_instances(self.context, 101,
instance_type)
self.assertEqual(num_instances, 101)
@@ -191,6 +203,9 @@ def test_unlimited_volumes(self):
db.quota_create(self.context, self.project_id, 'volumes', None)
volumes = quota.allowed_volumes(self.context, 100, 1)
self.assertEqual(volumes, 100)
+ db.quota_create(self.context, self.project_id, 'volumes', -1)
+ volumes = quota.allowed_volumes(self.context, 100, 1)
+ self.assertEqual(volumes, 100)
volumes = quota.allowed_volumes(self.context, 101, 1)
self.assertEqual(volumes, 101)
@@ -201,6 +216,9 @@ def test_unlimited_gigabytes(self):
db.quota_create(self.context, self.project_id, 'gigabytes', None)
volumes = quota.allowed_volumes(self.context, 100, 1)
self.assertEqual(volumes, 100)
+ db.quota_create(self.context, self.project_id, 'gigabytes', -1)
+ volumes = quota.allowed_volumes(self.context, 100, 1)
+ self.assertEqual(volumes, 100)
volumes = quota.allowed_volumes(self.context, 101, 1)
self.assertEqual(volumes, 101)
@@ -211,6 +229,9 @@ def test_unlimited_floating_ips(self):
db.quota_create(self.context, self.project_id, 'floating_ips', None)
floating_ips = quota.allowed_floating_ips(self.context, 100)
self.assertEqual(floating_ips, 100)
+ db.quota_create(self.context, self.project_id, 'floating_ips', -1)
+ floating_ips = quota.allowed_floating_ips(self.context, 100)
+ self.assertEqual(floating_ips, 100)
floating_ips = quota.allowed_floating_ips(self.context, 101)
self.assertEqual(floating_ips, 101)
@@ -221,6 +242,9 @@ def test_unlimited_metadata_items(self):
db.quota_create(self.context, self.project_id, 'metadata_items', None)
items = quota.allowed_metadata_items(self.context, 100)
self.assertEqual(items, 100)
+ db.quota_create(self.context, self.project_id, 'metadata_items', -1)
+ items = quota.allowed_metadata_items(self.context, 100)
+ self.assertEqual(items, 100)
items = quota.allowed_metadata_items(self.context, 101)
self.assertEqual(items, 101)

0 comments on commit d946562

Please sign in to comment.