Browse Source

Merge "Add 'consistent_snapshot_support' attr to 'share_groups' DB model"

Jenkins 2 years ago
parent
commit
7579549c31

+ 1
- 0
manila/api/views/share_groups.py View File

@@ -57,6 +57,7 @@ class ShareGroupViewBuilder(common.ViewBuilder):
57 57
             'share_types': [st['share_type_id'] for st in share_group.get(
58 58
                 'share_types')],
59 59
             'links': self._get_links(request, share_group['id']),
60
+            # TODO(vponomaryov): add 'consistent_snapshot_support' key in Pike.
60 61
         }
61 62
         if context.is_admin:
62 63
             share_group_dict['share_server_id'] = share_group.get(

+ 58
- 0
manila/db/migrations/alembic/versions/d5db24264f5c_add_consistent_snapshot_support_attr_to_share_group_model.py View File

@@ -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
+
15
+Revision ID: d5db24264f5c
16
+Revises: 927920b37453
17
+Create Date: 2017-02-03 15:59:31.134166
18
+
19
+"""
20
+
21
+# revision identifiers, used by Alembic.
22
+revision = 'd5db24264f5c'
23
+down_revision = '927920b37453'
24
+
25
+from alembic import op
26
+import sqlalchemy as sa
27
+
28
+
29
+SG_TABLE_NAME = 'share_groups'
30
+ATTR_NAME = 'consistent_snapshot_support'
31
+ENUM_POOL_VALUE = 'pool'
32
+ENUM_HOST_VALUE = 'host'
33
+
34
+
35
+def 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
+
54
+def 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)

+ 1
- 0
manila/db/sqlalchemy/models.py View File

@@ -1038,6 +1038,7 @@ class ShareGroup(BASE, ManilaBase):
1038 1038
         String(36), ForeignKey('share_servers.id'), nullable=True)
1039 1039
     share_group_type_id = Column(
1040 1040
         String(36), ForeignKey('share_group_types.id'), nullable=True)
1041
+    consistent_snapshot_support = Column(Enum('pool', 'host'), default=None)
1041 1042
     share_group_type = orm.relationship(
1042 1043
         ShareGroupTypes,
1043 1044
         backref="share_groups",

+ 60
- 0
manila/tests/db/migrations/alembic/migrations_data_checks.py View File

@@ -36,6 +36,7 @@ See BaseMigrationChecks class for more information.
36 36
 import abc
37 37
 import datetime
38 38
 
39
+from oslo_db import exception as oslo_db_exc
39 40
 from oslo_utils import uuidutils
40 41
 import six
41 42
 from sqlalchemy import exc as sa_exc
@@ -2109,3 +2110,62 @@ class ShareGroupSnapshotMemberNewProviderLocationColumnChecks(
2109 2110
         self.test_case.assertEqual(1, db_result.rowcount)
2110 2111
         for sgsm in db_result:
2111 2112
             self.test_case.assertFalse(hasattr(sgsm, 'provider_location'))
2113
+
2114
+
2115
+@map_to_migration('d5db24264f5c')
2116
+class 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))

+ 4
- 0
releasenotes/notes/bug-1661266-add-consistent-snapshot-support-attr-to-share-groups-DB-model-daa1d05129802796.yaml View File

@@ -0,0 +1,4 @@
1
+---
2
+fixes:
3
+  - Added 'consistent_snapshot_support' attribute to 'share_groups' DB model,
4
+    to ease possible future backport of bugfixes for 'share groups' feature.

Loading…
Cancel
Save