summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-02-07 19:28:11 +0000
committerGerrit Code Review <review@openstack.org>2017-02-07 19:28:11 +0000
commit7579549c31c5777b9af53ea8e715feb00a070018 (patch)
treedca49ef67e5a52fe9e95cf69f99ec508365f7705
parent3726c89f20d48929a498ad61d1270014cef8a223 (diff)
parent1684b59eed9c16f1516203040364d86b475a629b (diff)
Merge "Add 'consistent_snapshot_support' attr to 'share_groups' DB model"4.0.0.0rc1
-rw-r--r--manila/api/views/share_groups.py1
-rw-r--r--manila/db/migrations/alembic/versions/d5db24264f5c_add_consistent_snapshot_support_attr_to_share_group_model.py58
-rw-r--r--manila/db/sqlalchemy/models.py1
-rw-r--r--manila/tests/db/migrations/alembic/migrations_data_checks.py60
-rw-r--r--releasenotes/notes/bug-1661266-add-consistent-snapshot-support-attr-to-share-groups-DB-model-daa1d05129802796.yaml4
5 files changed, 124 insertions, 0 deletions
diff --git a/manila/api/views/share_groups.py b/manila/api/views/share_groups.py
index 1028e15..1a82a30 100644
--- a/manila/api/views/share_groups.py
+++ b/manila/api/views/share_groups.py
@@ -57,6 +57,7 @@ class ShareGroupViewBuilder(common.ViewBuilder):
57 'share_types': [st['share_type_id'] for st in share_group.get( 57 'share_types': [st['share_type_id'] for st in share_group.get(
58 'share_types')], 58 'share_types')],
59 'links': self._get_links(request, share_group['id']), 59 'links': self._get_links(request, share_group['id']),
60 # TODO(vponomaryov): add 'consistent_snapshot_support' key in Pike.
60 } 61 }
61 if context.is_admin: 62 if context.is_admin:
62 share_group_dict['share_server_id'] = share_group.get( 63 share_group_dict['share_server_id'] = share_group.get(
diff --git a/manila/db/migrations/alembic/versions/d5db24264f5c_add_consistent_snapshot_support_attr_to_share_group_model.py b/manila/db/migrations/alembic/versions/d5db24264f5c_add_consistent_snapshot_support_attr_to_share_group_model.py
new file mode 100644
index 0000000..18567a5
--- /dev/null
+++ b/manila/db/migrations/alembic/versions/d5db24264f5c_add_consistent_snapshot_support_attr_to_share_group_model.py
@@ -0,0 +1,58 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13"""Add enum 'consistent_snapshot_support' attr to 'share_groups' model.
14
15Revision ID: d5db24264f5c
16Revises: 927920b37453
17Create Date: 2017-02-03 15:59:31.134166
18
19"""
20
21# revision identifiers, used by Alembic.
22revision = 'd5db24264f5c'
23down_revision = '927920b37453'
24
25from alembic import op
26import sqlalchemy as sa
27
28
29SG_TABLE_NAME = 'share_groups'
30ATTR_NAME = 'consistent_snapshot_support'
31ENUM_POOL_VALUE = 'pool'
32ENUM_HOST_VALUE = 'host'
33
34
35def upgrade():
36 # Workaround for following alembic bug:
37 # https://bitbucket.org/zzzeek/alembic/issue/89
38 context = op.get_context()
39 if context.bind.dialect.name == 'postgresql':
40 op.execute(
41 "CREATE TYPE %s AS ENUM ('%s', '%s')" % (
42 ATTR_NAME, ENUM_POOL_VALUE, ENUM_HOST_VALUE))
43
44 op.add_column(
45 SG_TABLE_NAME,
46 sa.Column(
47 ATTR_NAME,
48 sa.Enum(ENUM_POOL_VALUE, ENUM_HOST_VALUE, name=ATTR_NAME),
49 nullable=True,
50 ),
51 )
52
53
54def downgrade():
55 op.drop_column(SG_TABLE_NAME, ATTR_NAME)
56 context = op.get_context()
57 if context.bind.dialect.name == 'postgresql':
58 op.execute('DROP TYPE %s' % ATTR_NAME)
diff --git a/manila/db/sqlalchemy/models.py b/manila/db/sqlalchemy/models.py
index 7271d32..17c1948 100644
--- a/manila/db/sqlalchemy/models.py
+++ b/manila/db/sqlalchemy/models.py
@@ -1038,6 +1038,7 @@ class ShareGroup(BASE, ManilaBase):
1038 String(36), ForeignKey('share_servers.id'), nullable=True) 1038 String(36), ForeignKey('share_servers.id'), nullable=True)
1039 share_group_type_id = Column( 1039 share_group_type_id = Column(
1040 String(36), ForeignKey('share_group_types.id'), nullable=True) 1040 String(36), ForeignKey('share_group_types.id'), nullable=True)
1041 consistent_snapshot_support = Column(Enum('pool', 'host'), default=None)
1041 share_group_type = orm.relationship( 1042 share_group_type = orm.relationship(
1042 ShareGroupTypes, 1043 ShareGroupTypes,
1043 backref="share_groups", 1044 backref="share_groups",
diff --git a/manila/tests/db/migrations/alembic/migrations_data_checks.py b/manila/tests/db/migrations/alembic/migrations_data_checks.py
index 2831999..69c62c8 100644
--- a/manila/tests/db/migrations/alembic/migrations_data_checks.py
+++ b/manila/tests/db/migrations/alembic/migrations_data_checks.py
@@ -36,6 +36,7 @@ See BaseMigrationChecks class for more information.
36import abc 36import abc
37import datetime 37import datetime
38 38
39from oslo_db import exception as oslo_db_exc
39from oslo_utils import uuidutils 40from oslo_utils import uuidutils
40import six 41import six
41from sqlalchemy import exc as sa_exc 42from sqlalchemy import exc as sa_exc
@@ -2109,3 +2110,62 @@ class ShareGroupSnapshotMemberNewProviderLocationColumnChecks(
2109 self.test_case.assertEqual(1, db_result.rowcount) 2110 self.test_case.assertEqual(1, db_result.rowcount)
2110 for sgsm in db_result: 2111 for sgsm in db_result:
2111 self.test_case.assertFalse(hasattr(sgsm, 'provider_location')) 2112 self.test_case.assertFalse(hasattr(sgsm, 'provider_location'))
2113
2114
2115@map_to_migration('d5db24264f5c')
2116class ShareGroupNewConsistentSnapshotSupportColumnChecks(BaseMigrationChecks):
2117 table_name = 'share_groups'
2118 new_attr_name = 'consistent_snapshot_support'
2119 share_group_type_id = uuidutils.generate_uuid()
2120 share_group_id = uuidutils.generate_uuid()
2121
2122 def setup_upgrade_data(self, engine):
2123 # Setup share group type
2124 sgt_data = {
2125 'id': self.share_group_type_id,
2126 'name': uuidutils.generate_uuid(),
2127 }
2128 sgt_table = utils.load_table('share_group_types', engine)
2129 engine.execute(sgt_table.insert(sgt_data))
2130
2131 # Setup share group
2132 sg_data = {
2133 'id': self.share_group_id,
2134 'project_id': 'fake_project_id',
2135 'user_id': 'fake_user_id',
2136 'share_group_type_id': self.share_group_type_id,
2137 }
2138 sg_table = utils.load_table('share_groups', engine)
2139 engine.execute(sg_table.insert(sg_data))
2140
2141 def check_upgrade(self, engine, data):
2142 sg_table = utils.load_table(self.table_name, engine)
2143 db_result = engine.execute(sg_table.select().where(
2144 sg_table.c.id == self.share_group_id))
2145 self.test_case.assertEqual(1, db_result.rowcount)
2146 for sg in db_result:
2147 self.test_case.assertTrue(hasattr(sg, self.new_attr_name))
2148
2149 # Check that we can write proper enum data to the new field
2150 for value in (None, 'pool', 'host'):
2151 engine.execute(sg_table.update().where(
2152 sg_table.c.id == self.share_group_id,
2153 ).values({self.new_attr_name: value}))
2154
2155 # Check that we cannot write values that are not allowed by enum.
2156 for value in ('', 'fake', 'pool1', 'host1', '1pool', '1host'):
2157 self.test_case.assertRaises(
2158 oslo_db_exc.DBError,
2159 engine.execute,
2160 sg_table.update().where(
2161 sg_table.c.id == self.share_group_id
2162 ).values({self.new_attr_name: value})
2163 )
2164
2165 def check_downgrade(self, engine):
2166 sg_table = utils.load_table(self.table_name, engine)
2167 db_result = engine.execute(sg_table.select().where(
2168 sg_table.c.id == self.share_group_id))
2169 self.test_case.assertEqual(1, db_result.rowcount)
2170 for sg in db_result:
2171 self.test_case.assertFalse(hasattr(sg, self.new_attr_name))
diff --git a/releasenotes/notes/bug-1661266-add-consistent-snapshot-support-attr-to-share-groups-DB-model-daa1d05129802796.yaml b/releasenotes/notes/bug-1661266-add-consistent-snapshot-support-attr-to-share-groups-DB-model-daa1d05129802796.yaml
new file mode 100644
index 0000000..3947e19
--- /dev/null
+++ b/releasenotes/notes/bug-1661266-add-consistent-snapshot-support-attr-to-share-groups-DB-model-daa1d05129802796.yaml
@@ -0,0 +1,4 @@
1---
2fixes:
3 - Added 'consistent_snapshot_support' attribute to 'share_groups' DB model,
4 to ease possible future backport of bugfixes for 'share groups' feature.