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
This commit is contained in:
parent
2b88148c6c
commit
6a2716de16
@ -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)
|
@ -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 \
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
`Bug #1952420 <https://bugs.launchpad.net/cinder/+bug/1952420>`_: Fixed
|
||||
quota warnings about ``backups`` and ``backup_gigabytes`` when creating
|
||||
backups.
|
Loading…
Reference in New Issue
Block a user