Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default quota class into DB during migration
For some time now use_default_quota_class has been the default setting for Cinder. Cinder, however, has not been putting any defaults for the default quota class into the database. This resulted in any command that queried for the default quotas to cause the message "Deprecated: Default quota for resource: <resource> is set by the default quota flag: <quota flag>, it is now deprecated. Please use the default quota class for default quota." This commit resolves this issue by setting the default value for volumes, snapshots and gigabytes in the quota_class table at migration time if there is not already a class_name of 'default' in the quota_classes table. Unit tests are included with this commit. Closes-bug 1233763 Change-Id: I457ed8a9b78492eda22e31dfc198b2ee051d3ece
- Loading branch information
Jay S. Bryant
committed
Nov 20, 2013
1 parent
1099f09
commit 7d26416
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
cinder/db/sqlalchemy/migrate_repo/versions/021_add_default_quota_class.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright 2013 IBM Corp. | ||
# | ||
# 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. | ||
|
||
import datetime | ||
|
||
from cinder.openstack.common import log as logging | ||
from oslo.config import cfg | ||
from sqlalchemy import MetaData, Table | ||
|
||
# Get default values via config. The defaults will either | ||
# come from the default values set in the quota option | ||
# configuration or via cinder.conf if the user has configured | ||
# default values for quotas there. | ||
CONF = cfg.CONF | ||
CONF.import_opt('quota_volumes', 'cinder.quota') | ||
CONF.import_opt('quota_snapshots', 'cinder.quota') | ||
CONF.import_opt('quota_gigabytes', 'cinder.quota') | ||
LOG = logging.getLogger(__name__) | ||
|
||
CLASS_NAME = 'default' | ||
CREATED_AT = datetime.datetime.now() | ||
|
||
|
||
def upgrade(migrate_engine): | ||
"""Add default quota class data into DB.""" | ||
meta = MetaData() | ||
meta.bind = migrate_engine | ||
|
||
quota_classes = Table('quota_classes', meta, autoload=True) | ||
|
||
rows = quota_classes.count().\ | ||
where(quota_classes.c.class_name == 'default').execute().scalar() | ||
|
||
# Do not add entries if there are already 'default' entries. We don't | ||
# want to write over something the user added. | ||
if rows: | ||
LOG.info(_("Found existing 'default' entries in the quota_classes " | ||
"table. Skipping insertion of default values.")) | ||
return | ||
|
||
try: | ||
#Set default volumes | ||
qci = quota_classes.insert() | ||
qci.execute({'created_at': CREATED_AT, | ||
'class_name': CLASS_NAME, | ||
'resource': 'volumes', | ||
'hard_limit': CONF.quota_volumes, | ||
'deleted': False, }) | ||
#Set default snapshots | ||
qci.execute({'created_at': CREATED_AT, | ||
'class_name': CLASS_NAME, | ||
'resource': 'snapshots', | ||
'hard_limit': CONF.quota_snapshots, | ||
'deleted': False, }) | ||
#Set default gigabytes | ||
qci.execute({'created_at': CREATED_AT, | ||
'class_name': CLASS_NAME, | ||
'resource': 'gigabytes', | ||
'hard_limit': CONF.quota_gigabytes, | ||
'deleted': False, }) | ||
LOG.info(_("Added default quota class data into the DB.")) | ||
except Exception: | ||
LOG.error(_("Default quota class data not inserted into the DB.")) | ||
raise | ||
|
||
|
||
def downgrade(migrate_engine): | ||
"""Don't delete the 'default' entries at downgrade time. | ||
We don't know if the user had default entries when we started. | ||
If they did, we wouldn't want to remove them. So, the safest | ||
thing to do is just leave the 'default' entries at downgrade time. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters