Fix issues related to delete quota-class
Currently Kingbird doesnot raise any exception if there is no class in DB with the specified name. With this change we can fix this. Refactored some part of the code and added test-cases for the same. Closes-Bug: #1587363 Change-Id: I0953c95459de31e223ec1ef658b76b3ab9d16ea8
This commit is contained in:
parent
75cc997137
commit
fce80a3991
@ -72,37 +72,32 @@ def quota_destroy_all(context, project_id):
|
||||
|
||||
|
||||
def quota_class_get(context, class_name, resource):
|
||||
"""Retrieve quota from the given quota class"""
|
||||
"""Retrieve quota from the given quota class."""
|
||||
return IMPL.quota_class_get(context, class_name, resource)
|
||||
|
||||
|
||||
def quota_class_get_default(context):
|
||||
"""Get default class quotas"""
|
||||
"""Get default class quotas."""
|
||||
return IMPL.quota_class_get_default(context)
|
||||
|
||||
|
||||
def quota_class_get_all_by_name(context, class_name):
|
||||
"""Get all quota limits for a specified class"""
|
||||
"""Get all quota limits for a specified class."""
|
||||
return IMPL.quota_class_get_all_by_name(context, class_name)
|
||||
|
||||
|
||||
def quota_class_create(context, class_name, resource, limit):
|
||||
"""Create a new quota limit in a specified class"""
|
||||
"""Create a new quota limit in a specified class."""
|
||||
return IMPL.quota_class_create(context, class_name, resource, limit)
|
||||
|
||||
|
||||
def quota_class_destroy(context, class_name, resource):
|
||||
"""Destroy a class quota """
|
||||
return IMPL.quota_class_destroy(context, class_name, resource)
|
||||
|
||||
|
||||
def quota_class_destroy_all(context, class_name):
|
||||
"""Destroy all quotas for class"""
|
||||
"""Destroy all quotas for class."""
|
||||
return IMPL.quota_class_destroy_all(context, class_name)
|
||||
|
||||
|
||||
def quota_class_update(context, class_name, resource, limit):
|
||||
"""Update a quota or raise if it doesn't exist """
|
||||
"""Update a quota or raise if it doesn't exist."""
|
||||
return IMPL.quota_class_update(context, class_name, resource, limit)
|
||||
|
||||
|
||||
|
@ -276,13 +276,6 @@ def quota_class_update(context, class_name, resource, limit):
|
||||
return quota_class_ref
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def quota_class_destroy(context, class_name, resource):
|
||||
with write_session() as session:
|
||||
quota_class_ref = _quota_class_get(context, class_name, resource)
|
||||
session.delete(quota_class_ref)
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def quota_class_destroy_all(context, class_name):
|
||||
with write_session() as session:
|
||||
@ -290,8 +283,11 @@ def quota_class_destroy_all(context, class_name):
|
||||
filter_by(deleted=False). \
|
||||
filter_by(class_name=class_name). \
|
||||
all()
|
||||
for quota_class_ref in quota_classes:
|
||||
session.delete(quota_class_ref)
|
||||
if quota_classes:
|
||||
for quota_class_ref in quota_classes:
|
||||
session.delete(quota_class_ref)
|
||||
else:
|
||||
raise exception.QuotaClassNotFound()
|
||||
|
||||
|
||||
def db_sync(engine, version=None):
|
||||
|
@ -180,19 +180,19 @@ class DBAPIQuotaTest(base.KingbirdTestCase):
|
||||
resource=resource)
|
||||
self.assertEqual(30, updated_class.hard_limit)
|
||||
|
||||
def test_quota_class_destroy(self):
|
||||
def test_quota_class_delete_wrong_class(self):
|
||||
class_name = "test_class"
|
||||
resource = "cores"
|
||||
fake_class_name = "fake_class"
|
||||
quota_class = self.create_quota_class(self.ctx, class_name=class_name,
|
||||
resource=resource, limit=20)
|
||||
self.assertIsNotNone(quota_class)
|
||||
|
||||
db_api.quota_class_destroy(self.ctx, class_name=class_name,
|
||||
resource=resource)
|
||||
|
||||
db_api.quota_class_update(self.ctx, class_name=class_name,
|
||||
resource=resource, limit=30)
|
||||
self.assertRaises(exceptions.QuotaClassNotFound,
|
||||
db_api.quota_class_get,
|
||||
self.ctx, class_name, resource)
|
||||
db_api.quota_class_destroy_all,
|
||||
self.ctx, fake_class_name)
|
||||
|
||||
def test_quota_class_destroy_all(self):
|
||||
class_name = "test_class"
|
||||
|
Loading…
x
Reference in New Issue
Block a user