Merge "Increase the length of resource property in quota_usages"

This commit is contained in:
Zuul 2018-12-11 23:34:52 +00:00 committed by Gerrit Code Review
commit 0a19233f79
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,27 @@
# 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.
from sqlalchemy import MetaData, String, Table
def upgrade(migrate_engine):
"""Increase the resource column size to the quota_usages table.
The resource value is constructed from (prefix + volume_type_name),
but the length of volume_type_name is limited to 255, if we add a
prefix such as 'volumes_' or 'gigabytes_' to volume_type_name it
will exceed the db length limit.
"""
meta = MetaData(bind=migrate_engine)
quota_usages = Table('quota_usages', meta, autoload=True)
quota_usages.c.resource.alter(type=String(300))

View File

@ -631,7 +631,7 @@ class QuotaUsage(BASE, CinderBase):
id = Column(Integer, primary_key=True)
project_id = Column(String(255), index=True)
resource = Column(String(255), index=True)
resource = Column(String(300), index=True)
in_use = Column(Integer)
reserved = Column(Integer)

View File

@ -115,6 +115,12 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
# NOTE : 104 modifies size of messages.project_id to 255.
# This should be safe for the same reason as migration 87.
104,
# NOTE(brinzhang): 127 changes size of quota_usage.resource
# to 300. This should be safe for the 'quota_usage' db table,
# because of the 255 is the length limit of volume_type_name,
# it should be add the additional prefix before volume_type_name,
# which we of course allow *this* size to 300.
127,
]
if version not in exceptions:
@ -409,6 +415,13 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
volume_transfer = db_utils.get_table(engine, 'transfers')
self.assertIn('no_snapshots', volume_transfer.c)
def _check_127(self, engine, data):
quota_usage_resource = db_utils.get_table(engine, 'quota_usages')
self.assertIn('resource', quota_usage_resource.c)
self.assertIsInstance(quota_usage_resource.c.resource.type,
self.VARCHAR_TYPE)
self.assertEqual(300, quota_usage_resource.c.resource.type.length)
def test_walk_versions(self):
self.walk_versions(False, False)
self.assert_each_foreign_key_is_part_of_an_index()