diff --git a/cinder/db/migrations/versions/921e1a36b076_initial.py b/cinder/db/migrations/versions/921e1a36b076_initial.py index f3eddaa15c2..4e1fb2794c2 100644 --- a/cinder/db/migrations/versions/921e1a36b076_initial.py +++ b/cinder/db/migrations/versions/921e1a36b076_initial.py @@ -44,7 +44,6 @@ CONF = cfg.CONF CONF.import_opt('quota_volumes', 'cinder.quota') CONF.import_opt('quota_snapshots', 'cinder.quota') CONF.import_opt('quota_gigabytes', 'cinder.quota') -CONF.import_opt('quota_consistencygroups', 'cinder.quota') CLASS_NAME = 'default' CREATED_AT = datetime.datetime.now() # noqa @@ -994,13 +993,6 @@ def upgrade(): 'hard_limit': CONF.quota_gigabytes, 'deleted': False, }, - { - 'created_at': CREATED_AT, - 'class_name': CLASS_NAME, - 'resource': 'consistencygroups', - 'hard_limit': CONF.quota_consistencygroups, - 'deleted': False, - }, { 'created_at': CREATED_AT, 'class_name': CLASS_NAME, diff --git a/cinder/db/migrations/versions/b7b88f50aab5_remove_quota_consistencygroups.py b/cinder/db/migrations/versions/b7b88f50aab5_remove_quota_consistencygroups.py new file mode 100644 index 00000000000..3967fcf8cc9 --- /dev/null +++ b/cinder/db/migrations/versions/b7b88f50aab5_remove_quota_consistencygroups.py @@ -0,0 +1,45 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Remove quota consistencygroups + +Revision ID: b7b88f50aab5 +Revises: 9ab1b092a404 +Create Date: 2021-11-10 11:54:50.123389 +""" + +from alembic import op +from sqlalchemy import orm + +from cinder.db.sqlalchemy import models + + +# revision identifiers, used by Alembic. +revision = 'b7b88f50aab5' +down_revision = '9ab1b092a404' +branch_labels = None +depends_on = None + + +def upgrade(): + bind = op.get_bind() + session = orm.Session(bind=bind) + + with session.begin(): + for model in (models.QuotaClass, + models.Quota, + models.QuotaUsage, + models.Reservation): + + session.query(model)\ + .filter_by(deleted=False, resource='consistencygroups')\ + .update(model.delete_values()) diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 782ae8b3ca5..5218b43fedb 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -656,17 +656,6 @@ def _sync_gigabytes( return {key: vol_gigs + snap_gigs} -def _sync_consistencygroups( - context, - project_id, - volume_type_id=None, - volume_type_name=None, -): - _, groups = _consistencygroup_data_get_for_project(context, project_id) - key = 'consistencygroups' - return {key: groups} - - def _sync_backup_gigabytes( context, project_id, @@ -697,7 +686,6 @@ QUOTA_SYNC_FUNCTIONS = { '_sync_volumes': _sync_volumes, '_sync_snapshots': _sync_snapshots, '_sync_gigabytes': _sync_gigabytes, - '_sync_consistencygroups': _sync_consistencygroups, '_sync_backups': _sync_backups, '_sync_backup_gigabytes': _sync_backup_gigabytes, '_sync_groups': _sync_groups, diff --git a/cinder/quota.py b/cinder/quota.py index 4614b169159..aa88f2c97e0 100644 --- a/cinder/quota.py +++ b/cinder/quota.py @@ -39,9 +39,6 @@ quota_opts = [ cfg.IntOpt('quota_snapshots', default=10, help='Number of volume snapshots allowed per project'), - cfg.IntOpt('quota_consistencygroups', - default=10, - help='Number of consistencygroups allowed per project'), cfg.IntOpt('quota_groups', default=10, help='Number of groups allowed per project'), @@ -910,30 +907,6 @@ class VolumeTypeQuotaEngine(QuotaEngine): new_res) -class CGQuotaEngine(QuotaEngine): - """Represent the consistencygroup quotas.""" - - @property - def resources(self): - """Fetches all possible quota resources.""" - - result = {} - # Global quotas. - argses = [('consistencygroups', '_sync_consistencygroups', - 'quota_consistencygroups'), ] - for args in argses: - resource = ReservableResource(*args) - result[resource.name] = resource - - return result - - def register_resource(self, resource): - raise NotImplementedError(_("Cannot register resource")) - - def register_resources(self, resources): - raise NotImplementedError(_("Cannot register resources")) - - class GroupQuotaEngine(QuotaEngine): """Represent the group quotas.""" @@ -959,6 +932,5 @@ class GroupQuotaEngine(QuotaEngine): QUOTAS = VolumeTypeQuotaEngine() -CGQUOTAS = CGQuotaEngine() GROUP_QUOTAS = GroupQuotaEngine() NON_QUOTA_KEYS = ['tenant_id', 'id'] diff --git a/cinder/tests/unit/db/test_migrations.py b/cinder/tests/unit/db/test_migrations.py index 98efdd127e3..e004cbea3de 100644 --- a/cinder/tests/unit/db/test_migrations.py +++ b/cinder/tests/unit/db/test_migrations.py @@ -369,6 +369,18 @@ class MigrationsWalk( snapshots = db_utils.get_table(connection, 'snapshots') self.assertFalse(snapshots.c.use_quota.nullable) + def _check_b7b88f50aab5(self, connection): + """Test consistencygroups quota was removed.""" + quota_classes = db_utils.get_table(connection, 'quota_classes') + res = connection.execute( + quota_classes.select().where( + sqlalchemy.and_( + quota_classes.c.resource == 'consistencygroups', + ~quota_classes.c.deleted, + quota_classes.c.class_name == 'default') + )).all() + self.assertListEqual([], res) + # TODO: (D Release) Uncomment method _check_afd7494d43b7 and create a # migration with hash afd7494d43b7 using the following command: # $ tox -e venv -- alembic -c cinder/db/alembic.ini revision \