From c8cc7979c4218fef9f7c1b76d89d173a2ab91ecf Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Thu, 25 Feb 2021 12:12:47 +0100 Subject: [PATCH] Remove unused quota python classes In Change-Id I221c7a9dc51a2bb9bf7228c056f63ba9546cf5f9 Cinder added quota support, and there were some classes added for countable resources that were not used by Cinder. After such a long time we still haven't used these resources, moreover, they don't seem useful for how Cinder uses quotas. Instead of keeping this code in case we need it in the future, it makes more sense to reduce our code base to what we use to reduce confusion for developers when reading our code. Change-Id: I3fd627639a6a72a2e158b84e0219c1e97bc6192a (cherry picked from commit 29edc0fd250c88f01f8b678577258dcda1d2821e) --- cinder/quota.py | 61 --------------------------------- cinder/tests/unit/test_quota.py | 49 +++++--------------------- 2 files changed, 9 insertions(+), 101 deletions(-) diff --git a/cinder/quota.py b/cinder/quota.py index 7eb4b864805..83a5629c21a 100644 --- a/cinder/quota.py +++ b/cinder/quota.py @@ -560,48 +560,6 @@ class ReservableResource(BaseResource): self.sync = sync -class AbsoluteResource(BaseResource): - """Describe a non-reservable resource.""" - - pass - - -class CountableResource(AbsoluteResource): - """Describe a resource where counts aren't based only on the project ID.""" - - def __init__(self, name, count, flag=None): - """Initializes a CountableResource. - - Countable resources are those resources which directly - correspond to objects in the database, i.e., volumes, gigabytes, - etc., but for which a count by project ID is inappropriate. A - CountableResource must be constructed with a counting - function, which will be called to determine the current counts - of the resource. - - The counting function will be passed the context, along with - the extra positional and keyword arguments that are passed to - Quota.count(). It should return an integer specifying the - count. - - Note that this counting is not performed in a transaction-safe - manner. This resource class is a temporary measure to provide - required functionality, until a better approach to solving - this problem can be evolved. - - :param name: The name of the resource, i.e., "volumes". - :param count: A callable which returns the count of the - resource. The arguments passed are as described - above. - :param flag: The name of the flag or configuration option - which specifies the default value of the quota - for this resource. - """ - - super(CountableResource, self).__init__(name, flag=flag) - self.count = count - - class VolumeTypeResource(ReservableResource): """ReservableResource for a specific volume type.""" @@ -735,25 +693,6 @@ class QuotaEngine(object): defaults=defaults, usages=usages) - def count(self, context, resource, *args, **kwargs): - """Count a resource. - - For countable resources, invokes the count() function and - returns its result. Arguments following the context and - resource are passed directly to the count function declared by - the resource. - - :param context: The request context, for access checks. - :param resource: The name of the resource, as a string. - """ - - # Get the resource - res = self.resources.get(resource) - if not res or not hasattr(res, 'count'): - raise exception.QuotaResourceUnknown(unknown=[resource]) - - return res.count(context, *args, **kwargs) - def limit_check(self, context, project_id=None, **values): """Check simple quota limits. diff --git a/cinder/tests/unit/test_quota.py b/cinder/tests/unit/test_quota.py index 18e59062a21..e8acb62a6ba 100644 --- a/cinder/tests/unit/test_quota.py +++ b/cinder/tests/unit/test_quota.py @@ -165,7 +165,7 @@ class QuotaIntegrationTestCase(test.TestCase): status='available', host=CONF.host, volume_type_id=self.vt['id']) - volume_api = volume.api.API() + volume_api = volume.API() volume_api.create_snapshots_in_db(self.context, [test_volume1, test_volume2], 'fake_name', @@ -546,7 +546,7 @@ class QuotaEngineTestCase(test.TestCase): def test_register_resource(self): quota_obj = quota.QuotaEngine() - resource = quota.AbsoluteResource('test_resource') + resource = quota.BaseResource('test_resource') quota_obj.register_resource(resource) self.assertEqual(dict(test_resource=resource), quota_obj.resources) @@ -554,9 +554,9 @@ class QuotaEngineTestCase(test.TestCase): def test_register_resources(self): quota_obj = quota.QuotaEngine() resources = [ - quota.AbsoluteResource('test_resource1'), - quota.AbsoluteResource('test_resource2'), - quota.AbsoluteResource('test_resource3'), ] + quota.BaseResource('test_resource1'), + quota.BaseResource('test_resource2'), + quota.BaseResource('test_resource3'), ] quota_obj.register_resources(resources) self.assertEqual(dict(test_resource1=resources[0], @@ -596,10 +596,10 @@ class QuotaEngineTestCase(test.TestCase): def _make_quota_obj(self, driver): quota_obj = quota.QuotaEngine(quota_driver_class=driver) resources = [ - quota.AbsoluteResource('test_resource4'), - quota.AbsoluteResource('test_resource3'), - quota.AbsoluteResource('test_resource2'), - quota.AbsoluteResource('test_resource1'), ] + quota.BaseResource('test_resource4'), + quota.BaseResource('test_resource3'), + quota.BaseResource('test_resource2'), + quota.BaseResource('test_resource1'), ] quota_obj.register_resources(resources) return quota_obj @@ -691,37 +691,6 @@ class QuotaEngineTestCase(test.TestCase): self.assertEqual(quota_obj.resources, result1) self.assertEqual(quota_obj.resources, result2) - def test_count_no_resource(self): - context = FakeContext(None, None) - driver = FakeDriver() - quota_obj = self._make_quota_obj(driver) - self.assertRaises(exception.QuotaResourceUnknown, - quota_obj.count, context, 'test_resource5', - True, foo='bar') - - def test_count_wrong_resource(self): - context = FakeContext(None, None) - driver = FakeDriver() - quota_obj = self._make_quota_obj(driver) - self.assertRaises(exception.QuotaResourceUnknown, - quota_obj.count, context, 'test_resource1', - True, foo='bar') - - def test_count(self): - def fake_count(context, *args, **kwargs): - self.assertEqual((True,), args) - self.assertEqual(dict(foo='bar'), kwargs) - return 5 - - context = FakeContext(None, None) - driver = FakeDriver() - quota_obj = self._make_quota_obj(driver) - quota_obj.register_resource(quota.CountableResource('test_resource5', - fake_count)) - result = quota_obj.count(context, 'test_resource5', True, foo='bar') - - self.assertEqual(5, result) - def test_limit_check(self): context = FakeContext(None, None) driver = FakeDriver()