Restrict CONF.quota.driver to DB and noop quota drivers
The quota driver config option was deprecated in Newton via change 430638888c987a99e537e2ac956087a7310ecdc6. 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
nova
releasenotes/notes
@ -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
|
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.
|
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',
|
cfg.StrOpt('driver',
|
||||||
default='nova.quota.DbQuotaDriver',
|
default='nova.quota.DbQuotaDriver',
|
||||||
deprecated_for_removal=True,
|
choices=('nova.quota.DbQuotaDriver',
|
||||||
deprecated_since='14.0.0',
|
'nova.quota.NoopQuotaDriver'),
|
||||||
deprecated_group='DEFAULT',
|
help="""
|
||||||
deprecated_name='quota_driver',
|
|
||||||
help="""
|
|
||||||
The quota enforcer driver.
|
|
||||||
|
|
||||||
Provides abstraction for quota checks. Users can configure a specific
|
Provides abstraction for quota checks. Users can configure a specific
|
||||||
driver to use for quota checks.
|
driver to use for quota checks.
|
||||||
|
|
||||||
Possible values:
|
Possible values:
|
||||||
|
|
||||||
* nova.quota.DbQuotaDriver (default) or any string representing fully
|
* nova.quota.DbQuotaDriver: Stores quota limit information
|
||||||
qualified class name.
|
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',
|
cfg.BoolOpt('recheck_quota',
|
||||||
default=True,
|
default=True,
|
||||||
|
@ -20,7 +20,6 @@ import copy
|
|||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
import six
|
|
||||||
|
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova import context as nova_context
|
from nova import context as nova_context
|
||||||
@ -995,21 +994,18 @@ class CountableResource(AbsoluteResource):
|
|||||||
class QuotaEngine(object):
|
class QuotaEngine(object):
|
||||||
"""Represent the set of recognized quotas."""
|
"""Represent the set of recognized quotas."""
|
||||||
|
|
||||||
def __init__(self, quota_driver_class=None):
|
def __init__(self, quota_driver=None):
|
||||||
"""Initialize a Quota object."""
|
"""Initialize a Quota object."""
|
||||||
self._resources = {}
|
self._resources = {}
|
||||||
self._driver_cls = quota_driver_class
|
# NOTE(mriedem): quota_driver is ever only supplied in tests with a
|
||||||
self.__driver = None
|
# fake driver.
|
||||||
|
self.__driver = quota_driver
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _driver(self):
|
def _driver(self):
|
||||||
if self.__driver:
|
if self.__driver:
|
||||||
return self.__driver
|
return self.__driver
|
||||||
if not self._driver_cls:
|
self.__driver = importutils.import_object(CONF.quota.driver)
|
||||||
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
|
|
||||||
return self.__driver
|
return self.__driver
|
||||||
|
|
||||||
def register_resource(self, resource):
|
def register_resource(self, resource):
|
||||||
|
@ -66,7 +66,7 @@ def stub_call_to_cells(context, instance, method, *args, **kwargs):
|
|||||||
# Use NoopQuotaDriver in child cells.
|
# Use NoopQuotaDriver in child cells.
|
||||||
saved_quotas = quota.QUOTAS
|
saved_quotas = quota.QUOTAS
|
||||||
quota.QUOTAS = quota.QuotaEngine(
|
quota.QUOTAS = quota.QuotaEngine(
|
||||||
quota_driver_class=quota.NoopQuotaDriver())
|
quota_driver=quota.NoopQuotaDriver())
|
||||||
compute_api.QUOTAS = quota.QUOTAS
|
compute_api.QUOTAS = quota.QUOTAS
|
||||||
try:
|
try:
|
||||||
return fn(context, instance, *args, **kwargs)
|
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.
|
# Use NoopQuotaDriver in child cells.
|
||||||
saved_quotas = quota.QUOTAS
|
saved_quotas = quota.QUOTAS
|
||||||
quota.QUOTAS = quota.QuotaEngine(
|
quota.QUOTAS = quota.QuotaEngine(
|
||||||
quota_driver_class=quota.NoopQuotaDriver())
|
quota_driver=quota.NoopQuotaDriver())
|
||||||
compute_api.QUOTAS = quota.QUOTAS
|
compute_api.QUOTAS = quota.QUOTAS
|
||||||
try:
|
try:
|
||||||
fn(context, instance, *args, **kwargs)
|
fn(context, instance, *args, **kwargs)
|
||||||
|
@ -489,15 +489,8 @@ class QuotaEngineTestCase(test.TestCase):
|
|||||||
self.assertEqual(quota_obj._resources, {})
|
self.assertEqual(quota_obj._resources, {})
|
||||||
self.assertIsInstance(quota_obj._driver, quota.DbQuotaDriver)
|
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):
|
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._resources, {})
|
||||||
self.assertEqual(quota_obj._driver, FakeDriver)
|
self.assertEqual(quota_obj._driver, FakeDriver)
|
||||||
@ -528,7 +521,7 @@ class QuotaEngineTestCase(test.TestCase):
|
|||||||
context = FakeContext('test_project', 'test_class')
|
context = FakeContext('test_project', 'test_class')
|
||||||
driver = FakeDriver(by_user=dict(
|
driver = FakeDriver(by_user=dict(
|
||||||
fake_user=dict(test_resource=42)))
|
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',
|
result = quota_obj.get_by_project_and_user(context, 'test_project',
|
||||||
'fake_user', 'test_resource')
|
'fake_user', 'test_resource')
|
||||||
|
|
||||||
@ -542,7 +535,7 @@ class QuotaEngineTestCase(test.TestCase):
|
|||||||
context = FakeContext('test_project', 'test_class')
|
context = FakeContext('test_project', 'test_class')
|
||||||
driver = FakeDriver(by_project=dict(
|
driver = FakeDriver(by_project=dict(
|
||||||
test_project=dict(test_resource=42)))
|
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',
|
result = quota_obj.get_by_project(context, 'test_project',
|
||||||
'test_resource')
|
'test_resource')
|
||||||
|
|
||||||
@ -555,7 +548,7 @@ class QuotaEngineTestCase(test.TestCase):
|
|||||||
context = FakeContext('test_project', 'test_class')
|
context = FakeContext('test_project', 'test_class')
|
||||||
driver = FakeDriver(by_class=dict(
|
driver = FakeDriver(by_class=dict(
|
||||||
test_class=dict(test_resource=42)))
|
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')
|
result = quota_obj.get_by_class(context, 'test_class', 'test_resource')
|
||||||
|
|
||||||
self.assertEqual(driver.called, [
|
self.assertEqual(driver.called, [
|
||||||
@ -564,7 +557,7 @@ class QuotaEngineTestCase(test.TestCase):
|
|||||||
self.assertEqual(result, 42)
|
self.assertEqual(result, 42)
|
||||||
|
|
||||||
def _make_quota_obj(self, driver):
|
def _make_quota_obj(self, driver):
|
||||||
quota_obj = quota.QuotaEngine(quota_driver_class=driver)
|
quota_obj = quota.QuotaEngine(quota_driver=driver)
|
||||||
resources = [
|
resources = [
|
||||||
quota.AbsoluteResource('test_resource4'),
|
quota.AbsoluteResource('test_resource4'),
|
||||||
quota.AbsoluteResource('test_resource3'),
|
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…
x
Reference in New Issue
Block a user