Coverage for manila/db/migrations/alembic/versions/e975ea83b712_add_share_server_encryption.py: 58%
50 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
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.
13"""Add share server encryption
15Revision ID: e975ea83b712
16Revises: 0d8c8f6d54a4
17Create Date: 2025-01-20 14:25:29.141460
19"""
21# revision identifiers, used by Alembic.
22revision = 'e975ea83b712'
23down_revision = '0d8c8f6d54a4'
25from alembic import op
26from oslo_log import log
27import sqlalchemy as sa
30LOG = log.getLogger(__name__)
33encryption_refs_table = 'encryption_refs'
34share_servers_table = 'share_servers'
35share_instances_table = 'share_instances'
38def upgrade():
39 try:
40 op.add_column(
41 share_servers_table,
42 sa.Column('encryption_key_ref', sa.String(36), nullable=True))
43 except Exception:
44 LOG.error("Column 'encryption_key_ref' can not be added to the "
45 "'share_servers' table!")
46 raise
48 try:
49 op.add_column(
50 share_servers_table,
51 sa.Column('application_credential_id',
52 sa.String(36), nullable=True))
53 except Exception:
54 LOG.error("Column 'application_credential_id' can not be added to the "
55 "'share_servers' table!")
56 raise
58 try:
59 op.add_column(
60 share_instances_table,
61 sa.Column('encryption_key_ref', sa.String(36), nullable=True))
62 except Exception:
63 LOG.error("Column can not be added to the 'share_instances' table!")
64 raise
66 context = op.get_context()
67 mysql_dl = context.bind.dialect.name == 'mysql'
68 datetime_type = (sa.dialects.mysql.DATETIME(fsp=6)
69 if mysql_dl else sa.DateTime)
71 try:
72 op.create_table(
73 encryption_refs_table,
74 sa.Column('id', sa.String(36), primary_key=True, nullable=False),
75 sa.Column('share_server_id', sa.String(length=36),
76 sa.ForeignKey('share_servers.id'), unique=True),
77 sa.Column('share_instance_id', sa.String(length=36),
78 sa.ForeignKey('share_instances.id'), unique=True),
79 sa.Column('encryption_key_ref', sa.String(36), nullable=True),
80 sa.Column('project_id', sa.String(length=255), nullable=False),
81 sa.Column('deleted', sa.String(36), default='False'),
82 sa.Column('created_at', datetime_type),
83 sa.Column('updated_at', datetime_type),
84 sa.Column('deleted_at', datetime_type),
85 mysql_engine='InnoDB',
86 mysql_charset='utf8'
87 )
88 except Exception:
89 LOG.error("Table |%s| not created!", encryption_refs_table)
90 raise
93def downgrade():
94 try:
95 op.drop_table(encryption_refs_table)
96 except Exception:
97 LOG.error("%s table not dropped", encryption_refs_table)
98 raise
100 try:
101 op.drop_column(share_servers_table, 'encryption_key_ref')
102 op.drop_column(share_servers_table, 'application_credential_id')
103 except Exception:
104 LOG.error("Column can not be dropped for 'share_servers' table!")
105 raise
107 try:
108 op.drop_column(share_instances_table, 'encryption_key_ref')
109 except Exception:
110 LOG.error("Column can not be dropped for 'share_instances' table!")
111 raise