Use the constant UNLIMITED_QUOTA=-1 in quota engine
This is a follow up patch for a comment in [1]. [1]https://review.opendev.org/c/openstack/neutron/+/926725 Related-Bug: #1953170 Change-Id: Icdb3e39b55ee443338310a7f7da30dd5fa630657
This commit is contained in:
parent
9ec96f5e68
commit
d9e580f5e5
@ -213,8 +213,9 @@ class DbQuotaDriver(nlib_quota_api.QuotaDriverAPI):
|
||||
# retrieved
|
||||
current_limits = self.get_project_quotas(
|
||||
context, resources, project_id)
|
||||
unlimited_resources = set([resource for (resource, limit) in
|
||||
current_limits.items() if limit < 0])
|
||||
unlimited_resources = set(
|
||||
[resource for (resource, limit) in current_limits.items()
|
||||
if limit <= quota_api.UNLIMITED_QUOTA])
|
||||
# Do not even bother counting resources and calculating headroom
|
||||
# for resources with unlimited quota
|
||||
LOG.debug("Resources %s have unlimited quota limit. It is not "
|
||||
|
@ -63,8 +63,9 @@ class DbQuotaNoLockDriver(quota_driver.DbQuotaDriver):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
# Filter out unlimited resources.
|
||||
limits = self.get_project_quotas(context, resources, project_id)
|
||||
unlimited_resources = set([resource for (resource, limit) in
|
||||
limits.items() if limit < 0])
|
||||
unlimited_resources = set(
|
||||
[resource for (resource, limit) in limits.items()
|
||||
if limit <= quota_api.UNLIMITED_QUOTA])
|
||||
requested_resources = (set(deltas.keys()) - unlimited_resources)
|
||||
|
||||
# Count the number of (1) used and (2) reserved resources for this
|
||||
|
@ -31,6 +31,7 @@ from neutron.api import extensions
|
||||
from neutron.api.v2 import base
|
||||
from neutron.api.v2 import resource
|
||||
from neutron.api import wsgi
|
||||
from neutron.db.quota import api as quota_api
|
||||
from neutron import policy
|
||||
from neutron import quota
|
||||
from neutron.quota import resource_registry
|
||||
@ -152,7 +153,7 @@ class QuotaSetsController(wsgi.Controller):
|
||||
if force is not True:
|
||||
resources = resource_registry.get_all_resources()
|
||||
for resource_name, limit in body[self._resource_name].items():
|
||||
if limit == -1:
|
||||
if limit == quota_api.UNLIMITED_QUOTA:
|
||||
# limit=-1 is disabling the quota thus it is not needed to
|
||||
# check the resource usage.
|
||||
continue
|
||||
|
@ -336,10 +336,12 @@ class TestDbQuotaDriver(testlib_api.SqlTestCase,
|
||||
|
||||
def test_quota_limit_check_unlimited(self):
|
||||
resources = self._create_resources()
|
||||
self.plugin.update_quota_limit(self.context, self.project_1,
|
||||
self.resource_1, -1)
|
||||
self.plugin.update_quota_limit(self.context, self.project_1,
|
||||
self.resource_2, -1)
|
||||
self.plugin.update_quota_limit(
|
||||
self.context, self.project_1, self.resource_1,
|
||||
quota_api.UNLIMITED_QUOTA)
|
||||
self.plugin.update_quota_limit(
|
||||
self.context, self.project_1, self.resource_2,
|
||||
quota_api.UNLIMITED_QUOTA)
|
||||
reservations = {self.resource_1: 8}
|
||||
self.quota_driver.make_reservation(
|
||||
self.context, self.project_1, resources, reservations, self.plugin)
|
||||
|
@ -29,6 +29,7 @@ from neutron.api import extensions
|
||||
from neutron.api.v2 import router
|
||||
from neutron.common import config
|
||||
from neutron.conf import quota as qconf
|
||||
from neutron.db.quota import api as quota_api
|
||||
from neutron.db.quota import driver
|
||||
from neutron.db.quota import driver_nolock
|
||||
from neutron.db.quota import driver_null
|
||||
@ -249,7 +250,7 @@ class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
|
||||
def test_update_quotas_to_unlimited(self):
|
||||
project_id = 'project_id1'
|
||||
env = test_base._get_neutron_env(project_id, as_admin=True)
|
||||
quotas = {'quota': {'network': -1}}
|
||||
quotas = {'quota': {'network': quota_api.UNLIMITED_QUOTA}}
|
||||
res = self.api.put(_get_path('quotas', id=project_id, fmt=self.fmt),
|
||||
self.serialize(quotas), extra_environ=env,
|
||||
expect_errors=False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user