Remove quota from Tricircle
1. What is the problem? Tricircle provides networking deployment, quota management is no need in Tricircle project. We should remove it from the Tricircle. 2. What is the solution to the problem? Remove quota related files and some related unit test files from Tricircle project. 3. What the features need to be implemented to the Tricircle to realize the solution? No new features. Change-Id: Iee1ff838ee9643d78016b0b33cd104b03a2ee086
This commit is contained in:
parent
65c628d0b1
commit
133c99b28d
File diff suppressed because it is too large
Load Diff
|
@ -16,6 +16,7 @@
|
|||
import copy
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_db.sqlalchemy import utils as sa_utils
|
||||
import oslo_log.helpers as log_helpers
|
||||
from oslo_log import log
|
||||
|
||||
|
@ -31,7 +32,6 @@ from neutron.db import l3_agentschedulers_db # noqa
|
|||
from neutron.db import l3_db
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import portbindings_db
|
||||
from neutron.db import sqlalchemyutils
|
||||
from neutron.extensions import availability_zone as az_ext
|
||||
from neutron.extensions import external_net
|
||||
from neutron.extensions import l3
|
||||
|
@ -553,11 +553,13 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||
if search_step < 100:
|
||||
search_step = 100
|
||||
query = self._apply_ports_filters(query, models_v2.Port, filters)
|
||||
query = sqlalchemyutils.paginate_query(
|
||||
query, models_v2.Port, search_step, [('id', False)],
|
||||
query = sa_utils.paginate_query(
|
||||
query, models_v2.Port, search_step,
|
||||
# create a dummy port object
|
||||
marker_obj=models_v2.Port(
|
||||
id=last_port_id) if last_port_id else None)
|
||||
marker=models_v2.Port(
|
||||
id=last_port_id) if last_port_id else None,
|
||||
sort_keys=['id'],
|
||||
sort_dirs=['desc-nullsfirst'])
|
||||
total = 0
|
||||
ret = []
|
||||
for port in query:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,13 +13,9 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import six
|
||||
import unittest
|
||||
|
||||
from tricircle.common import context
|
||||
from tricircle.common import exceptions
|
||||
from tricircle.common import quota
|
||||
|
||||
from tricircle.db import api
|
||||
from tricircle.db import core
|
||||
|
@ -185,323 +181,3 @@ class APITest(unittest.TestCase):
|
|||
|
||||
def tearDown(self):
|
||||
core.ModelBase.metadata.drop_all(core.get_engine())
|
||||
|
||||
|
||||
class QuotaApiTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
core.initialize()
|
||||
core.ModelBase.metadata.create_all(core.get_engine())
|
||||
self.context = context.get_admin_context()
|
||||
|
||||
def _quota_reserve(self, context, project_id):
|
||||
"""Create sample Quota, QuotaUsage and Reservation objects.
|
||||
|
||||
There is no method api.quota_usage_create(), so we have to use
|
||||
api.quota_reserve() for creating QuotaUsage objects.
|
||||
|
||||
Returns reservations uuids.
|
||||
|
||||
"""
|
||||
quotas = {}
|
||||
resources = {}
|
||||
deltas = {}
|
||||
for i, resource in enumerate(('volumes', 'gigabytes')):
|
||||
quota_obj = api.quota_create(context, project_id, resource, i + 1)
|
||||
quotas[resource] = quota_obj.hard_limit
|
||||
resources[resource] = quota.ReservableResource(resource, None)
|
||||
deltas[resource] = i + 1
|
||||
return api.quota_reserve(
|
||||
context, resources, quotas, deltas,
|
||||
datetime.datetime.utcnow(), datetime.datetime.utcnow(),
|
||||
datetime.timedelta(days=1), project_id
|
||||
)
|
||||
|
||||
def _dict_from_object(self, obj, ignored_keys):
|
||||
if ignored_keys is None:
|
||||
ignored_keys = []
|
||||
if isinstance(obj, dict):
|
||||
items = obj.items()
|
||||
else:
|
||||
items = obj.iteritems()
|
||||
return {k: v for k, v in items
|
||||
if k not in ignored_keys}
|
||||
|
||||
def _assertEqualObjects(self, obj1, obj2, ignored_keys=None):
|
||||
obj1 = self._dict_from_object(obj1, ignored_keys)
|
||||
obj2 = self._dict_from_object(obj2, ignored_keys)
|
||||
|
||||
self.assertEqual(
|
||||
len(obj1), len(obj2),
|
||||
"Keys mismatch: %s" % six.text_type(
|
||||
set(obj1.keys()) ^ set(obj2.keys())))
|
||||
for key, value in obj1.items():
|
||||
self.assertEqual(value, obj2[key])
|
||||
|
||||
def tearDown(self):
|
||||
core.ModelBase.metadata.drop_all(core.get_engine())
|
||||
|
||||
|
||||
class DBAPIReservationTestCase(QuotaApiTestCase):
|
||||
|
||||
"""Tests for db.api.reservation_* methods."""
|
||||
|
||||
def setUp(self):
|
||||
super(DBAPIReservationTestCase, self).setUp()
|
||||
self.values = {
|
||||
'uuid': 'sample-uuid',
|
||||
'project_id': 'project1',
|
||||
'resource': 'resource',
|
||||
'delta': 42,
|
||||
'expire': (datetime.datetime.utcnow() +
|
||||
datetime.timedelta(days=1)),
|
||||
'usage': {'id': 1}
|
||||
}
|
||||
|
||||
def test_reservation_commit(self):
|
||||
reservations = self._quota_reserve(self.context, 'project1')
|
||||
expected = {'project_id': 'project1',
|
||||
'volumes': {'reserved': 1, 'in_use': 0},
|
||||
'gigabytes': {'reserved': 2, 'in_use': 0},
|
||||
}
|
||||
self.assertEqual(expected,
|
||||
api.quota_usage_get_all_by_project(
|
||||
self.context, 'project1'))
|
||||
api.reservation_commit(self.context, reservations, 'project1')
|
||||
expected = {'project_id': 'project1',
|
||||
'volumes': {'reserved': 0, 'in_use': 1},
|
||||
'gigabytes': {'reserved': 0, 'in_use': 2},
|
||||
}
|
||||
self.assertEqual(expected,
|
||||
api.quota_usage_get_all_by_project(
|
||||
self.context,
|
||||
'project1'))
|
||||
|
||||
def test_reservation_rollback(self):
|
||||
reservations = self._quota_reserve(self.context, 'project1')
|
||||
expected = {'project_id': 'project1',
|
||||
'volumes': {'reserved': 1, 'in_use': 0},
|
||||
'gigabytes': {'reserved': 2, 'in_use': 0},
|
||||
}
|
||||
self.assertEqual(expected,
|
||||
api.quota_usage_get_all_by_project(
|
||||
self.context,
|
||||
'project1'))
|
||||
api.reservation_rollback(self.context, reservations, 'project1')
|
||||
expected = {'project_id': 'project1',
|
||||
'volumes': {'reserved': 0, 'in_use': 0},
|
||||
'gigabytes': {'reserved': 0, 'in_use': 0},
|
||||
}
|
||||
self.assertEqual(expected,
|
||||
api.quota_usage_get_all_by_project(
|
||||
self.context,
|
||||
'project1'))
|
||||
|
||||
def test_reservation_expire(self):
|
||||
self.values['expire'] = datetime.datetime.utcnow() + \
|
||||
datetime.timedelta(days=1)
|
||||
self._quota_reserve(self.context, 'project1')
|
||||
api.reservation_expire(self.context)
|
||||
|
||||
expected = {'project_id': 'project1',
|
||||
'gigabytes': {'reserved': 0, 'in_use': 0},
|
||||
'volumes': {'reserved': 0, 'in_use': 0}}
|
||||
self.assertEqual(expected,
|
||||
api.quota_usage_get_all_by_project(
|
||||
self.context,
|
||||
'project1'))
|
||||
|
||||
|
||||
class DBAPIQuotaClassTestCase(QuotaApiTestCase):
|
||||
|
||||
"""Tests for api.api.quota_class_* methods."""
|
||||
|
||||
def setUp(self):
|
||||
super(DBAPIQuotaClassTestCase, self).setUp()
|
||||
self.sample_qc = api.quota_class_create(self.context, 'test_qc',
|
||||
'test_resource', 42)
|
||||
|
||||
def test_quota_class_get(self):
|
||||
qc = api.quota_class_get(self.context, 'test_qc', 'test_resource')
|
||||
self._assertEqualObjects(self.sample_qc, qc)
|
||||
|
||||
def test_quota_class_destroy(self):
|
||||
api.quota_class_destroy(self.context, 'test_qc', 'test_resource')
|
||||
self.assertRaises(exceptions.QuotaClassNotFound,
|
||||
api.quota_class_get, self.context,
|
||||
'test_qc', 'test_resource')
|
||||
|
||||
def test_quota_class_get_not_found(self):
|
||||
self.assertRaises(exceptions.QuotaClassNotFound,
|
||||
api.quota_class_get, self.context, 'nonexistent',
|
||||
'nonexistent')
|
||||
|
||||
def test_quota_class_get_all_by_name(self):
|
||||
api.quota_class_create(self.context, 'test2', 'res1', 43)
|
||||
api.quota_class_create(self.context, 'test2', 'res2', 44)
|
||||
self.assertEqual({'class_name': 'test_qc', 'test_resource': 42},
|
||||
api.quota_class_get_all_by_name(self.context,
|
||||
'test_qc'))
|
||||
self.assertEqual({'class_name': 'test2', 'res1': 43, 'res2': 44},
|
||||
api.quota_class_get_all_by_name(self.context,
|
||||
'test2'))
|
||||
|
||||
def test_quota_class_update(self):
|
||||
api.quota_class_update(self.context, 'test_qc', 'test_resource', 43)
|
||||
updated = api.quota_class_get(self.context, 'test_qc',
|
||||
'test_resource')
|
||||
self.assertEqual(43, updated['hard_limit'])
|
||||
|
||||
def test_quota_class_destroy_all_by_name(self):
|
||||
api.quota_class_create(self.context, 'test2', 'res1', 43)
|
||||
api.quota_class_create(self.context, 'test2', 'res2', 44)
|
||||
api.quota_class_destroy_all_by_name(self.context, 'test2')
|
||||
self.assertEqual({'class_name': 'test2'},
|
||||
api.quota_class_get_all_by_name(self.context,
|
||||
'test2'))
|
||||
|
||||
|
||||
class DBAPIQuotaTestCase(QuotaApiTestCase):
|
||||
|
||||
"""Tests for api.api.reservation_* methods."""
|
||||
|
||||
def test_quota_create(self):
|
||||
_quota = api.quota_create(self.context, 'project1', 'resource', 99)
|
||||
self.assertEqual('resource', _quota.resource)
|
||||
self.assertEqual(99, _quota.hard_limit)
|
||||
self.assertEqual('project1', _quota.project_id)
|
||||
|
||||
def test_quota_get(self):
|
||||
_quota = api.quota_create(self.context, 'project1', 'resource', 99)
|
||||
quota_db = api.quota_get(self.context, 'project1', 'resource')
|
||||
self._assertEqualObjects(_quota, quota_db)
|
||||
|
||||
def test_quota_get_all_by_project(self):
|
||||
for i in range(3):
|
||||
for j in range(3):
|
||||
api.quota_create(self.context, 'proj%d' % i, 'res%d' % j, j)
|
||||
for i in range(3):
|
||||
quotas_db = api.quota_get_all_by_project(self.context,
|
||||
'proj%d' % i)
|
||||
self.assertEqual({'project_id': 'proj%d' % i,
|
||||
'res0': 0,
|
||||
'res1': 1,
|
||||
'res2': 2}, quotas_db)
|
||||
|
||||
def test_quota_update(self):
|
||||
api.quota_create(self.context, 'project1', 'resource1', 41)
|
||||
api.quota_update(self.context, 'project1', 'resource1', 42)
|
||||
_quota = api.quota_get(self.context, 'project1', 'resource1')
|
||||
self.assertEqual(42, _quota.hard_limit)
|
||||
self.assertEqual('resource1', _quota.resource)
|
||||
self.assertEqual('project1', _quota.project_id)
|
||||
|
||||
def test_quota_update_nonexistent(self):
|
||||
self.assertRaises(exceptions.ProjectQuotaNotFound,
|
||||
api.quota_update,
|
||||
self.context,
|
||||
'project1',
|
||||
'resource1',
|
||||
42)
|
||||
|
||||
def test_quota_get_nonexistent(self):
|
||||
self.assertRaises(exceptions.ProjectQuotaNotFound,
|
||||
api.quota_get,
|
||||
self.context,
|
||||
'project1',
|
||||
'resource1')
|
||||
|
||||
def test_quota_reserve(self):
|
||||
reservations = self._quota_reserve(self.context, 'project1')
|
||||
self.assertEqual(2, len(reservations))
|
||||
quota_usage = api.quota_usage_get_all_by_project(self.context,
|
||||
'project1')
|
||||
self.assertEqual({'project_id': 'project1',
|
||||
'gigabytes': {'reserved': 2, 'in_use': 0},
|
||||
'volumes': {'reserved': 1, 'in_use': 0}},
|
||||
quota_usage)
|
||||
|
||||
def test_quota_destroy(self):
|
||||
api.quota_create(self.context, 'project1', 'resource1', 41)
|
||||
self.assertIsNone(api.quota_destroy(self.context, 'project1',
|
||||
'resource1'))
|
||||
self.assertRaises(exceptions.ProjectQuotaNotFound, api.quota_get,
|
||||
self.context, 'project1', 'resource1')
|
||||
|
||||
def test_quota_destroy_by_project(self):
|
||||
# Create limits, reservations and usage for project
|
||||
project = 'project1'
|
||||
self._quota_reserve(self.context, project)
|
||||
expected_usage = {'project_id': project,
|
||||
'volumes': {'reserved': 1, 'in_use': 0},
|
||||
'gigabytes': {'reserved': 2, 'in_use': 0}}
|
||||
expected = {'project_id': project, 'gigabytes': 2, 'volumes': 1}
|
||||
|
||||
# Check that quotas are there
|
||||
self.assertEqual(expected,
|
||||
api.quota_get_all_by_project(self.context, project))
|
||||
self.assertEqual(expected_usage,
|
||||
api.quota_usage_get_all_by_project(self.context,
|
||||
project))
|
||||
|
||||
# Destroy only the limits
|
||||
api.quota_destroy_by_project(self.context, project)
|
||||
|
||||
# Confirm that limits have been removed
|
||||
self.assertEqual({'project_id': project},
|
||||
api.quota_get_all_by_project(self.context, project))
|
||||
|
||||
# But that usage and reservations are the same
|
||||
self.assertEqual(expected_usage,
|
||||
api.quota_usage_get_all_by_project(self.context,
|
||||
project))
|
||||
|
||||
def test_quota_destroy_sqlalchemy_all_by_project_(self):
|
||||
# Create limits, reservations and usage for project
|
||||
project = 'project1'
|
||||
self._quota_reserve(self.context, project)
|
||||
expected_usage = {'project_id': project,
|
||||
'volumes': {'reserved': 1, 'in_use': 0},
|
||||
'gigabytes': {'reserved': 2, 'in_use': 0}}
|
||||
expected = {'project_id': project, 'gigabytes': 2, 'volumes': 1}
|
||||
expected_result = {'project_id': project}
|
||||
|
||||
# Check that quotas are there
|
||||
self.assertEqual(expected,
|
||||
api.quota_get_all_by_project(self.context, project))
|
||||
self.assertEqual(expected_usage,
|
||||
api.quota_usage_get_all_by_project(self.context,
|
||||
project))
|
||||
|
||||
# Destroy all quotas using SQLAlchemy Implementation
|
||||
api.quota_destroy_all_by_project(self.context, project,
|
||||
only_quotas=False)
|
||||
|
||||
# Check that all quotas have been deleted
|
||||
self.assertEqual(expected_result,
|
||||
api.quota_get_all_by_project(self.context, project))
|
||||
self.assertEqual(expected_result,
|
||||
api.quota_usage_get_all_by_project(self.context,
|
||||
project))
|
||||
|
||||
def test_quota_usage_get_nonexistent(self):
|
||||
self.assertRaises(exceptions.QuotaUsageNotFound,
|
||||
api.quota_usage_get,
|
||||
self.context,
|
||||
'p1',
|
||||
'nonexitent_resource')
|
||||
|
||||
def test_quota_usage_get(self):
|
||||
self._quota_reserve(self.context, 'p1')
|
||||
quota_usage = api.quota_usage_get(self.context, 'p1', 'gigabytes')
|
||||
expected = {'resource': 'gigabytes', 'project_id': 'p1',
|
||||
'in_use': 0, 'reserved': 2, 'total': 2}
|
||||
for key, value in expected.items():
|
||||
self.assertEqual(value, quota_usage[key], key)
|
||||
|
||||
def test_quota_usage_get_all_by_project(self):
|
||||
self._quota_reserve(self.context, 'p1')
|
||||
expected = {'project_id': 'p1',
|
||||
'volumes': {'in_use': 0, 'reserved': 1},
|
||||
'gigabytes': {'in_use': 0, 'reserved': 2}}
|
||||
self.assertEqual(expected, api.quota_usage_get_all_by_project(
|
||||
self.context, 'p1'))
|
||||
|
|
Loading…
Reference in New Issue