Remove verification functionality

We want the initial implementation of oslo.limit to be as simple as
possible. Originally, we thought we were going to implement resource
verification, but that's something we can do later.

Resource verification is meant to protect against race conditions when
two clients claim the same amount of resources and the project is over
limit. Unfortunately, having services implement resource verification
requires them to use either a context manager or make multiple calls
to enforce limits and sprinkling those calls around existing business
logic. Since we don't know which approach we want to use to implement
this, let's just focus on enforcing limits and come back to resource
verification when we get more feedback from developers incorporating
this into their services.

Change-Id: I50f52189862bc3d109654e158cba381b156e70b6
This commit is contained in:
Lance Bragstad 2019-06-17 14:38:57 +00:00
parent af184185fe
commit 8bf64bb278
2 changed files with 2 additions and 25 deletions

View File

@ -15,7 +15,7 @@
class Enforcer(object):
def __init__(self, deltas, callback=None, verify=True):
def __init__(self, deltas, callback=None):
"""An object for checking usage against resource limits and requests.
:param deltas: An dictionary containing resource names as keys and
@ -25,11 +25,6 @@ class Enforcer(object):
as a parameter and calculates the current usage of a
resource.
:type callable function:
:param verify: Boolean denoting whether or not to verify the new usage
after checking the resource delta. This can be useful
for handling race conditions between clients claiming
resources.
:type verify: boolean
"""
@ -39,13 +34,9 @@ class Enforcer(object):
if callback and not callable(callback):
msg = 'callback must be a callable function.'
raise ValueError(msg)
if verify and not isinstance(verify, bool):
msg = 'verify must be a boolean value.'
raise ValueError(msg)
self.deltas = deltas
self.callback = callback
self.verify = verify
def __enter__(self):
pass

View File

@ -40,15 +40,13 @@ class TestEnforcer(base.BaseTestCase):
self.assertEqual(self.deltas, enforcer.deltas)
self.assertIsNone(enforcer.callback)
self.assertTrue(enforcer.verify)
def test_optional_parameters(self):
callback = self._get_usage_for_project
enforcer = limit.Enforcer(self.deltas, callback=callback, verify=True)
enforcer = limit.Enforcer(self.deltas, callback=callback)
self.assertEqual(self.deltas, enforcer.deltas)
self.assertEqual(self._get_usage_for_project, enforcer.callback)
self.assertTrue(enforcer.verify)
def test_callback_must_be_callable(self):
invalid_callback_types = [uuid.uuid4().hex, 5, 5.1]
@ -61,18 +59,6 @@ class TestEnforcer(base.BaseTestCase):
callback=invalid_callback
)
def test_verify_must_be_boolean(self):
invalid_verify_types = [uuid.uuid4().hex, 5, 5.1]
for invalid_verify in invalid_verify_types:
self.assertRaises(
ValueError,
limit.Enforcer,
self.deltas,
callback=self._get_usage_for_project,
verify=invalid_verify
)
def test_deltas_must_be_a_dictionary(self):
invalid_delta_types = [uuid.uuid4().hex, 5, 5.1, True, False, []]