Merge "Add 'consistent_snapshot_support' attr to 'share_groups' DB model"
This commit is contained in:
commit
7579549c31
@ -57,6 +57,7 @@ class ShareGroupViewBuilder(common.ViewBuilder):
|
||||
'share_types': [st['share_type_id'] for st in share_group.get(
|
||||
'share_types')],
|
||||
'links': self._get_links(request, share_group['id']),
|
||||
# TODO(vponomaryov): add 'consistent_snapshot_support' key in Pike.
|
||||
}
|
||||
if context.is_admin:
|
||||
share_group_dict['share_server_id'] = share_group.get(
|
||||
|
@ -0,0 +1,58 @@
|
||||
# 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.
|
||||
|
||||
"""Add enum 'consistent_snapshot_support' attr to 'share_groups' model.
|
||||
|
||||
Revision ID: d5db24264f5c
|
||||
Revises: 927920b37453
|
||||
Create Date: 2017-02-03 15:59:31.134166
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'd5db24264f5c'
|
||||
down_revision = '927920b37453'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
SG_TABLE_NAME = 'share_groups'
|
||||
ATTR_NAME = 'consistent_snapshot_support'
|
||||
ENUM_POOL_VALUE = 'pool'
|
||||
ENUM_HOST_VALUE = 'host'
|
||||
|
||||
|
||||
def upgrade():
|
||||
# Workaround for following alembic bug:
|
||||
# https://bitbucket.org/zzzeek/alembic/issue/89
|
||||
context = op.get_context()
|
||||
if context.bind.dialect.name == 'postgresql':
|
||||
op.execute(
|
||||
"CREATE TYPE %s AS ENUM ('%s', '%s')" % (
|
||||
ATTR_NAME, ENUM_POOL_VALUE, ENUM_HOST_VALUE))
|
||||
|
||||
op.add_column(
|
||||
SG_TABLE_NAME,
|
||||
sa.Column(
|
||||
ATTR_NAME,
|
||||
sa.Enum(ENUM_POOL_VALUE, ENUM_HOST_VALUE, name=ATTR_NAME),
|
||||
nullable=True,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column(SG_TABLE_NAME, ATTR_NAME)
|
||||
context = op.get_context()
|
||||
if context.bind.dialect.name == 'postgresql':
|
||||
op.execute('DROP TYPE %s' % ATTR_NAME)
|
@ -1038,6 +1038,7 @@ class ShareGroup(BASE, ManilaBase):
|
||||
String(36), ForeignKey('share_servers.id'), nullable=True)
|
||||
share_group_type_id = Column(
|
||||
String(36), ForeignKey('share_group_types.id'), nullable=True)
|
||||
consistent_snapshot_support = Column(Enum('pool', 'host'), default=None)
|
||||
share_group_type = orm.relationship(
|
||||
ShareGroupTypes,
|
||||
backref="share_groups",
|
||||
|
@ -36,6 +36,7 @@ See BaseMigrationChecks class for more information.
|
||||
import abc
|
||||
import datetime
|
||||
|
||||
from oslo_db import exception as oslo_db_exc
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
from sqlalchemy import exc as sa_exc
|
||||
@ -2109,3 +2110,62 @@ class ShareGroupSnapshotMemberNewProviderLocationColumnChecks(
|
||||
self.test_case.assertEqual(1, db_result.rowcount)
|
||||
for sgsm in db_result:
|
||||
self.test_case.assertFalse(hasattr(sgsm, 'provider_location'))
|
||||
|
||||
|
||||
@map_to_migration('d5db24264f5c')
|
||||
class ShareGroupNewConsistentSnapshotSupportColumnChecks(BaseMigrationChecks):
|
||||
table_name = 'share_groups'
|
||||
new_attr_name = 'consistent_snapshot_support'
|
||||
share_group_type_id = uuidutils.generate_uuid()
|
||||
share_group_id = uuidutils.generate_uuid()
|
||||
|
||||
def setup_upgrade_data(self, engine):
|
||||
# Setup share group type
|
||||
sgt_data = {
|
||||
'id': self.share_group_type_id,
|
||||
'name': uuidutils.generate_uuid(),
|
||||
}
|
||||
sgt_table = utils.load_table('share_group_types', engine)
|
||||
engine.execute(sgt_table.insert(sgt_data))
|
||||
|
||||
# Setup share group
|
||||
sg_data = {
|
||||
'id': self.share_group_id,
|
||||
'project_id': 'fake_project_id',
|
||||
'user_id': 'fake_user_id',
|
||||
'share_group_type_id': self.share_group_type_id,
|
||||
}
|
||||
sg_table = utils.load_table('share_groups', engine)
|
||||
engine.execute(sg_table.insert(sg_data))
|
||||
|
||||
def check_upgrade(self, engine, data):
|
||||
sg_table = utils.load_table(self.table_name, engine)
|
||||
db_result = engine.execute(sg_table.select().where(
|
||||
sg_table.c.id == self.share_group_id))
|
||||
self.test_case.assertEqual(1, db_result.rowcount)
|
||||
for sg in db_result:
|
||||
self.test_case.assertTrue(hasattr(sg, self.new_attr_name))
|
||||
|
||||
# Check that we can write proper enum data to the new field
|
||||
for value in (None, 'pool', 'host'):
|
||||
engine.execute(sg_table.update().where(
|
||||
sg_table.c.id == self.share_group_id,
|
||||
).values({self.new_attr_name: value}))
|
||||
|
||||
# Check that we cannot write values that are not allowed by enum.
|
||||
for value in ('', 'fake', 'pool1', 'host1', '1pool', '1host'):
|
||||
self.test_case.assertRaises(
|
||||
oslo_db_exc.DBError,
|
||||
engine.execute,
|
||||
sg_table.update().where(
|
||||
sg_table.c.id == self.share_group_id
|
||||
).values({self.new_attr_name: value})
|
||||
)
|
||||
|
||||
def check_downgrade(self, engine):
|
||||
sg_table = utils.load_table(self.table_name, engine)
|
||||
db_result = engine.execute(sg_table.select().where(
|
||||
sg_table.c.id == self.share_group_id))
|
||||
self.test_case.assertEqual(1, db_result.rowcount)
|
||||
for sg in db_result:
|
||||
self.test_case.assertFalse(hasattr(sg, self.new_attr_name))
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- Added 'consistent_snapshot_support' attribute to 'share_groups' DB model,
|
||||
to ease possible future backport of bugfixes for 'share groups' feature.
|
Loading…
Reference in New Issue
Block a user