From 6a2716de161a1143b56c92bf1cc672c34573233a Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Wed, 10 Nov 2021 12:42:44 +0100 Subject: [PATCH] Quota: Add backup related default limits Logs show deprecation warning in the logs when creating backups. Warnings are related to the "backups" and "backup_gigabytes" quota resources: Deprecated: Default quota for resource: backups is set by the default quota flag: quota_backups, it is now deprecated. Please use the default quota class for default quota. Deprecated: Default quota for resource: backup_gigabytes is set by the default quota flag: quota_backup_gigabytes, it is now deprecated. Please use the default quota class for default quota. This warning is shown because the ``quota_classes`` table doesn't have entries for these 2 resources for the "default" quota class. This patch adds a database migration to create the ``backups`` and ``backup_gigabytes`` entries in the ``quota_classes`` table like we have for the other standard resources, such as ``volumes``, ``gigabytes``, etc. Closes-Bug: #1952420 Change-Id: I2a83e9b23f40a8ef4a734b456e4b7afb1ad65f94 --- ...uota_add_backup_defaults_in_quota_class.py | 64 +++++++++++++++++++ cinder/tests/unit/db/test_migrations.py | 15 +++++ ...ota-backup-resources-fc4e0795f520c4ab.yaml | 6 ++ 3 files changed, 85 insertions(+) create mode 100644 cinder/db/migrations/versions/9c74c1c6971f_quota_add_backup_defaults_in_quota_class.py create mode 100644 releasenotes/notes/quota-backup-resources-fc4e0795f520c4ab.yaml diff --git a/cinder/db/migrations/versions/9c74c1c6971f_quota_add_backup_defaults_in_quota_class.py b/cinder/db/migrations/versions/9c74c1c6971f_quota_add_backup_defaults_in_quota_class.py new file mode 100644 index 00000000000..60d2e28b04c --- /dev/null +++ b/cinder/db/migrations/versions/9c74c1c6971f_quota_add_backup_defaults_in_quota_class.py @@ -0,0 +1,64 @@ +# 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. + +"""Quota: Add backup defaults in quota class + +Revision ID: 9c74c1c6971f +Revises: b7b88f50aab5 +Create Date: 2021-11-10 12:17:06.713239 +""" + +from datetime import datetime + +from alembic import op +from oslo_config import cfg +import sqlalchemy as sa + +from cinder.db.sqlalchemy import models + +# revision identifiers, used by Alembic. +revision = '9c74c1c6971f' +down_revision = 'b7b88f50aab5' +branch_labels = None +depends_on = None + + +def _create_default(bind, resource, hard_limit): + session = sa.orm.Session(bind=bind) + + class_name = 'default' + created_at = datetime.now() # noqa + + with session.begin(): + if session.query(sa.sql.exists() + .where( + sa.and_( + ~models.QuotaClass.deleted, + models.QuotaClass.class_name == class_name, + models.QuotaClass.resource == resource)))\ + .scalar(): + return + + quota_class = models.QuotaClass(created_at=created_at, + class_name=class_name, + resource=resource, + hard_limit=hard_limit, + deleted=False) + + session.add(quota_class) + + +def upgrade(): + bind = op.get_bind() + + _create_default(bind, 'backups', cfg.CONF.quota_backups) + _create_default(bind, 'backup_gigabytes', cfg.CONF.quota_backup_gigabytes) diff --git a/cinder/tests/unit/db/test_migrations.py b/cinder/tests/unit/db/test_migrations.py index e004cbea3de..8e1676d270e 100644 --- a/cinder/tests/unit/db/test_migrations.py +++ b/cinder/tests/unit/db/test_migrations.py @@ -381,6 +381,21 @@ class MigrationsWalk( )).all() self.assertListEqual([], res) + def _check_9c74c1c6971f(self, connection): + """Test backup related quota was added.""" + quota_classes = db_utils.get_table(connection, 'quota_classes') + res = connection.execute( + sqlalchemy.select(quota_classes.c.resource).where( + sqlalchemy.and_( + quota_classes.c.resource.startswith('backup'), + ~quota_classes.c.deleted, + quota_classes.c.class_name == 'default') + )).all() + + self.assertEqual(2, len(res)) + self.assertEqual({'backups', 'backup_gigabytes'}, + {r[0] for r in 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 \ diff --git a/releasenotes/notes/quota-backup-resources-fc4e0795f520c4ab.yaml b/releasenotes/notes/quota-backup-resources-fc4e0795f520c4ab.yaml new file mode 100644 index 00000000000..be1e0a63684 --- /dev/null +++ b/releasenotes/notes/quota-backup-resources-fc4e0795f520c4ab.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + `Bug #1952420 `_: Fixed + quota warnings about ``backups`` and ``backup_gigabytes`` when creating + backups.