quota: remove QuotaDriver.destroy_all_by_project()

Removes the unnecessary QuotaDriver.destroy_all_by_project() and
destroy_all_by_project_and_users() methods. nova.objects.Quotas already
had these methods and this patch changes the one place that was calling
the old QuotaDriver method (from the nova API /quota_sets endpoint) to
just call the nova.objects.Quotas methods of the same name.

Note that the NoopQuotaDriver's destroy_all_by_project() and
destroy_all_by_project_and_user() methods were no-ops. Now the
quota-sets API will be calling the objects.Quotas.destroy_xxx() methods
which will raise ProjectUserQuotaNotFound instead of returning a 204.
If the user is calling DELETE /os-quota-sets and there is the Noop quota
driver configured, and the response is a 404 Not Found, do we really
care?

In the future, we should be getting rid of the os-quota-sets API
entirely and using Keystone's /limits API.

One more set of methods gone from QuotaDriver...

Change-Id: Ifc0a409bd179807db18f2e7b59ea9d4d67e9a798
This commit is contained in:
Jay Pipes 2018-10-24 10:16:26 -04:00
parent 1aa758e522
commit 8153cddad1
4 changed files with 5 additions and 93 deletions

View File

@ -275,7 +275,7 @@ class QuotaSetsController(wsgi.Controller):
params = urlparse.parse_qs(req.environ.get('QUERY_STRING', ''))
user_id = params.get('user_id', [None])[0]
if user_id:
QUOTAS.destroy_all_by_project_and_user(context,
id, user_id)
objects.Quotas.destroy_all_by_project_and_user(
context, id, user_id)
else:
QUOTAS.destroy_all_by_project(context, id)
objects.Quotas.destroy_all_by_project(context, id)

View File

@ -612,26 +612,6 @@ class DbQuotaDriver(object):
quotas=quotas_exceeded, usages={},
headroom=headroom)
def destroy_all_by_project_and_user(self, context, project_id, user_id):
"""Destroy all quotas associated with a project and user.
:param context: The request context, for access checks.
:param project_id: The ID of the project being deleted.
:param user_id: The ID of the user being deleted.
"""
objects.Quotas.destroy_all_by_project_and_user(context, project_id,
user_id)
def destroy_all_by_project(self, context, project_id):
"""Destroy all quotas associated with a project.
:param context: The request context, for access checks.
:param project_id: The ID of the project being deleted.
"""
objects.Quotas.destroy_all_by_project(context, project_id)
class NoopQuotaDriver(object):
"""Driver that turns quotas calls into no-ops and pretends that quotas
@ -805,23 +785,6 @@ class NoopQuotaDriver(object):
"""
pass
def destroy_all_by_project_and_user(self, context, project_id, user_id):
"""Destroy all quotas associated with a project and user.
:param context: The request context, for access checks.
:param project_id: The ID of the project being deleted.
:param user_id: The ID of the user being deleted.
"""
pass
def destroy_all_by_project(self, context, project_id):
"""Destroy all quotas associated with a project.
:param context: The request context, for access checks.
:param project_id: The ID of the project being deleted.
"""
pass
class BaseResource(object):
"""Describe a single resource for quota checking."""
@ -1116,28 +1079,6 @@ class QuotaEngine(object):
context, self._resources, project_values=project_values,
user_values=user_values, project_id=project_id, user_id=user_id)
def destroy_all_by_project_and_user(self, context, project_id, user_id):
"""Destroy all quotas, usages, and reservations associated with a
project and user.
:param context: The request context, for access checks.
:param project_id: The ID of the project being deleted.
:param user_id: The ID of the user being deleted.
"""
self._driver.destroy_all_by_project_and_user(context,
project_id, user_id)
def destroy_all_by_project(self, context, project_id):
"""Destroy all quotas, usages, and reservations associated with a
project.
:param context: The request context, for access checks.
:param project_id: The ID of the project being deleted.
"""
self._driver.destroy_all_by_project(context, project_id)
@property
def resources(self):
return sorted(self._resources.keys())

View File

@ -275,7 +275,7 @@ class QuotaSetsTestV21(BaseQuotaSetsTest):
body = {'quota_set': self.default_quotas}
self._quotas_update_bad_request_case(body)
@mock.patch.object(quota.QUOTAS, 'destroy_all_by_project')
@mock.patch('nova.objects.Quotas.destroy_all_by_project')
def test_quotas_delete(self, mock_destroy_all_by_project):
req = self._get_http_request()
res = self.controller.delete(req, 1234)
@ -470,7 +470,7 @@ class UserQuotasTestV21(BaseQuotaSetsTest):
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
req, 'update_me', body=body)
@mock.patch.object(quota.QUOTAS, "destroy_all_by_project_and_user")
@mock.patch('nova.objects.Quotas.destroy_all_by_project_and_user')
def test_user_quotas_delete(self, mock_destroy_all_by_project_and_user):
url = '/v2/fake4/os-quota-sets/1234?user_id=1'
req = self._get_http_request(url)

View File

@ -317,13 +317,6 @@ class FakeDriver(object):
self.called.append(('limit_check_project_and_user', context, resources,
project_values, user_values, project_id, user_id))
def destroy_all_by_project_and_user(self, context, project_id, user_id):
self.called.append(('destroy_all_by_project_and_user', context,
project_id, user_id))
def destroy_all_by_project(self, context, project_id):
self.called.append(('destroy_all_by_project', context, project_id))
class BaseResourceTestCase(test.TestCase):
def test_no_flag(self):
@ -567,28 +560,6 @@ class QuotaEngineTestCase(test.TestCase):
None, None)],
driver.called)
def test_destroy_all_by_project_and_user(self):
context = FakeContext(None, None)
driver = FakeDriver()
quota_obj = self._make_quota_obj(driver)
quota_obj.destroy_all_by_project_and_user(context,
'test_project', 'fake_user')
self.assertEqual(driver.called, [
('destroy_all_by_project_and_user', context, 'test_project',
'fake_user'),
])
def test_destroy_all_by_project(self):
context = FakeContext(None, None)
driver = FakeDriver()
quota_obj = self._make_quota_obj(driver)
quota_obj.destroy_all_by_project(context, 'test_project')
self.assertEqual(driver.called, [
('destroy_all_by_project', context, 'test_project'),
])
def test_resources(self):
quota_obj = self._make_quota_obj(None)