Restrict CONF.quota.driver to DB and noop quota drivers
The quota driver config option was deprecated in Newton via
change 430638888c
. That was a
bit wrong in that the config option shouldn't have been
deprecated since we still use it, but we wanted to deprecate
the ability to load custom quota driver classes, which is done
in this change.
To be clear, this doesn't remove the option nor the ability
to configure the quota driver, it only removes the ability
to class-load out of tree quota drivers.
Change-Id: I021a2bcb923739409b393cbb2684ffdf20180f73
This commit is contained in:
parent
8ede37e8b1
commit
1bbd144f5e
@ -287,24 +287,21 @@ to help keep quota usage up-to-date and reduce the impact of out of sync usage
|
||||
issues. Note that quotas are not updated on a periodic task, they will update
|
||||
on a new reservation if max_age has passed since the last reservation.
|
||||
"""),
|
||||
# TODO(pumaranikar): Add a new config to select between the db_driver and
|
||||
# the no_op driver using stevedore.
|
||||
cfg.StrOpt('driver',
|
||||
default='nova.quota.DbQuotaDriver',
|
||||
deprecated_for_removal=True,
|
||||
deprecated_since='14.0.0',
|
||||
deprecated_group='DEFAULT',
|
||||
deprecated_name='quota_driver',
|
||||
help="""
|
||||
The quota enforcer driver.
|
||||
|
||||
default='nova.quota.DbQuotaDriver',
|
||||
choices=('nova.quota.DbQuotaDriver',
|
||||
'nova.quota.NoopQuotaDriver'),
|
||||
help="""
|
||||
Provides abstraction for quota checks. Users can configure a specific
|
||||
driver to use for quota checks.
|
||||
|
||||
Possible values:
|
||||
|
||||
* nova.quota.DbQuotaDriver (default) or any string representing fully
|
||||
qualified class name.
|
||||
* nova.quota.DbQuotaDriver: Stores quota limit information
|
||||
in the database and relies on the quota_* configuration options for default
|
||||
quota limit values. Counts quota usage on-demand.
|
||||
* nova.quota.NoopQuotaDriver: Ignores quota and treats all resources as
|
||||
unlimited.
|
||||
"""),
|
||||
cfg.BoolOpt('recheck_quota',
|
||||
default=True,
|
||||
|
@ -20,7 +20,6 @@ import copy
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
import nova.conf
|
||||
from nova import context as nova_context
|
||||
@ -995,21 +994,18 @@ class CountableResource(AbsoluteResource):
|
||||
class QuotaEngine(object):
|
||||
"""Represent the set of recognized quotas."""
|
||||
|
||||
def __init__(self, quota_driver_class=None):
|
||||
def __init__(self, quota_driver=None):
|
||||
"""Initialize a Quota object."""
|
||||
self._resources = {}
|
||||
self._driver_cls = quota_driver_class
|
||||
self.__driver = None
|
||||
# NOTE(mriedem): quota_driver is ever only supplied in tests with a
|
||||
# fake driver.
|
||||
self.__driver = quota_driver
|
||||
|
||||
@property
|
||||
def _driver(self):
|
||||
if self.__driver:
|
||||
return self.__driver
|
||||
if not self._driver_cls:
|
||||
self._driver_cls = CONF.quota.driver
|
||||
if isinstance(self._driver_cls, six.string_types):
|
||||
self._driver_cls = importutils.import_object(self._driver_cls)
|
||||
self.__driver = self._driver_cls
|
||||
self.__driver = importutils.import_object(CONF.quota.driver)
|
||||
return self.__driver
|
||||
|
||||
def register_resource(self, resource):
|
||||
|
@ -66,7 +66,7 @@ def stub_call_to_cells(context, instance, method, *args, **kwargs):
|
||||
# Use NoopQuotaDriver in child cells.
|
||||
saved_quotas = quota.QUOTAS
|
||||
quota.QUOTAS = quota.QuotaEngine(
|
||||
quota_driver_class=quota.NoopQuotaDriver())
|
||||
quota_driver=quota.NoopQuotaDriver())
|
||||
compute_api.QUOTAS = quota.QUOTAS
|
||||
try:
|
||||
return fn(context, instance, *args, **kwargs)
|
||||
@ -88,7 +88,7 @@ def stub_cast_to_cells(context, instance, method, *args, **kwargs):
|
||||
# Use NoopQuotaDriver in child cells.
|
||||
saved_quotas = quota.QUOTAS
|
||||
quota.QUOTAS = quota.QuotaEngine(
|
||||
quota_driver_class=quota.NoopQuotaDriver())
|
||||
quota_driver=quota.NoopQuotaDriver())
|
||||
compute_api.QUOTAS = quota.QUOTAS
|
||||
try:
|
||||
fn(context, instance, *args, **kwargs)
|
||||
|
@ -489,15 +489,8 @@ class QuotaEngineTestCase(test.TestCase):
|
||||
self.assertEqual(quota_obj._resources, {})
|
||||
self.assertIsInstance(quota_obj._driver, quota.DbQuotaDriver)
|
||||
|
||||
def test_init_override_string(self):
|
||||
quota_obj = quota.QuotaEngine(
|
||||
quota_driver_class='nova.tests.unit.test_quota.FakeDriver')
|
||||
|
||||
self.assertEqual(quota_obj._resources, {})
|
||||
self.assertIsInstance(quota_obj._driver, FakeDriver)
|
||||
|
||||
def test_init_override_obj(self):
|
||||
quota_obj = quota.QuotaEngine(quota_driver_class=FakeDriver)
|
||||
quota_obj = quota.QuotaEngine(quota_driver=FakeDriver)
|
||||
|
||||
self.assertEqual(quota_obj._resources, {})
|
||||
self.assertEqual(quota_obj._driver, FakeDriver)
|
||||
@ -528,7 +521,7 @@ class QuotaEngineTestCase(test.TestCase):
|
||||
context = FakeContext('test_project', 'test_class')
|
||||
driver = FakeDriver(by_user=dict(
|
||||
fake_user=dict(test_resource=42)))
|
||||
quota_obj = quota.QuotaEngine(quota_driver_class=driver)
|
||||
quota_obj = quota.QuotaEngine(quota_driver=driver)
|
||||
result = quota_obj.get_by_project_and_user(context, 'test_project',
|
||||
'fake_user', 'test_resource')
|
||||
|
||||
@ -542,7 +535,7 @@ class QuotaEngineTestCase(test.TestCase):
|
||||
context = FakeContext('test_project', 'test_class')
|
||||
driver = FakeDriver(by_project=dict(
|
||||
test_project=dict(test_resource=42)))
|
||||
quota_obj = quota.QuotaEngine(quota_driver_class=driver)
|
||||
quota_obj = quota.QuotaEngine(quota_driver=driver)
|
||||
result = quota_obj.get_by_project(context, 'test_project',
|
||||
'test_resource')
|
||||
|
||||
@ -555,7 +548,7 @@ class QuotaEngineTestCase(test.TestCase):
|
||||
context = FakeContext('test_project', 'test_class')
|
||||
driver = FakeDriver(by_class=dict(
|
||||
test_class=dict(test_resource=42)))
|
||||
quota_obj = quota.QuotaEngine(quota_driver_class=driver)
|
||||
quota_obj = quota.QuotaEngine(quota_driver=driver)
|
||||
result = quota_obj.get_by_class(context, 'test_class', 'test_resource')
|
||||
|
||||
self.assertEqual(driver.called, [
|
||||
@ -564,7 +557,7 @@ class QuotaEngineTestCase(test.TestCase):
|
||||
self.assertEqual(result, 42)
|
||||
|
||||
def _make_quota_obj(self, driver):
|
||||
quota_obj = quota.QuotaEngine(quota_driver_class=driver)
|
||||
quota_obj = quota.QuotaEngine(quota_driver=driver)
|
||||
resources = [
|
||||
quota.AbsoluteResource('test_resource4'),
|
||||
quota.AbsoluteResource('test_resource3'),
|
||||
|
@ -0,0 +1,11 @@
|
||||
---
|
||||
upgrade:
|
||||
- |
|
||||
The ``[quota]/driver`` configuration option is no longer deprecated
|
||||
but now only allows one of two possible values:
|
||||
|
||||
* ``nova.quota.DbQuotaDriver``
|
||||
* ``nova.quota.NoopQuotaDriver``
|
||||
|
||||
This means it is no longer possible to class-load custom out-of-tree
|
||||
quota drivers.
|
Loading…
Reference in New Issue
Block a user