~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/migrate_repo/versions/090_modify_volume_id_datatype.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 OpenStack LLC.
 
4
# All Rights Reserved.
 
5
#
 
6
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
7
#    not use this file except in compliance with the License. You may obtain
 
8
#    a copy of the License at
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
12
#    Unless required by applicable law or agreed to in writing, software
 
13
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
14
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
15
#    License for the specific language governing permissions and limitations
 
16
#    under the License.
 
17
 
 
18
from sqlalchemy import Integer
 
19
from sqlalchemy import MetaData, String, Table
 
20
from migrate import ForeignKeyConstraint
 
21
from nova import log as logging
 
22
 
 
23
LOG = logging.getLogger(__name__)
 
24
 
 
25
 
 
26
def upgrade(migrate_engine):
 
27
    """Convert volume and snapshot id columns from int to varchar."""
 
28
    meta = MetaData()
 
29
    meta.bind = migrate_engine
 
30
    dialect = migrate_engine.url.get_dialect().name
 
31
 
 
32
    volumes = Table('volumes', meta, autoload=True)
 
33
    snapshots = Table('snapshots', meta, autoload=True)
 
34
    iscsi_targets = Table('iscsi_targets', meta, autoload=True)
 
35
    volume_metadata = Table('volume_metadata', meta, autoload=True)
 
36
    sm_volume = Table('sm_volume', meta, autoload=True)
 
37
    block_device_mapping = Table('block_device_mapping', meta, autoload=True)
 
38
 
 
39
    try:
 
40
        fkeys = list(snapshots.c.volume_id.foreign_keys)
 
41
        if fkeys:
 
42
            fkey_name = fkeys[0].constraint.name
 
43
            ForeignKeyConstraint(columns=[snapshots.c.volume_id],
 
44
                    refcolumns=[volumes.c.id],
 
45
                    name=fkey_name).drop()
 
46
 
 
47
        fkeys = list(iscsi_targets.c.volume_id.foreign_keys)
 
48
        if fkeys:
 
49
            fkey_name = fkeys[0].constraint.name
 
50
            ForeignKeyConstraint(columns=[iscsi_targets.c.volume_id],
 
51
                                 refcolumns=[volumes.c.id],
 
52
                                 name=fkey_name).drop()
 
53
 
 
54
        fkeys = list(volume_metadata.c.volume_id.foreign_keys)
 
55
        if fkeys:
 
56
            fkey_name = fkeys[0].constraint.name
 
57
            ForeignKeyConstraint(columns=[volume_metadata.c.volume_id],
 
58
                                 refcolumns=[volumes.c.id],
 
59
                                 name=fkey_name).drop()
 
60
 
 
61
        fkeys = list(sm_volume.c.id.foreign_keys)
 
62
        if fkeys:
 
63
            fkey_name = fkeys[0].constraint.name
 
64
            ForeignKeyConstraint(columns=[sm_volume.c.id],
 
65
                                 refcolumns=[volumes.c.id],
 
66
                                 name=fkey_name).drop()
 
67
 
 
68
        fkeys = list(block_device_mapping.c.volume_id.foreign_keys)
 
69
        if fkeys:
 
70
            fkey_name = fkeys[0].constraint.name
 
71
            ForeignKeyConstraint(columns=[block_device_mapping.c.volume_id],
 
72
                                 refcolumns=[volumes.c.id],
 
73
                                 name=fkey_name).drop()
 
74
 
 
75
        fkeys = list(block_device_mapping.c.snapshot_id.foreign_keys)
 
76
        if fkeys:
 
77
            fkey_name = fkeys[0].constraint.name
 
78
            ForeignKeyConstraint(columns=[block_device_mapping.c.snapshot_id],
 
79
                                 refcolumns=[snapshots.c.id],
 
80
                                 name=fkey_name).drop()
 
81
 
 
82
    except Exception:
 
83
        LOG.error(_("Foreign Key constraint couldn't be removed"))
 
84
        raise
 
85
 
 
86
    volumes.c.id.alter(String(36), primary_key=True)
 
87
    volumes.c.snapshot_id.alter(String(36))
 
88
    volume_metadata.c.volume_id.alter(String(36), nullable=False)
 
89
    snapshots.c.id.alter(String(36), primary_key=True)
 
90
    snapshots.c.volume_id.alter(String(36))
 
91
    sm_volume.c.id.alter(String(36))
 
92
    block_device_mapping.c.volume_id.alter(String(36))
 
93
    block_device_mapping.c.snapshot_id.alter(String(36))
 
94
    iscsi_targets.c.volume_id.alter(String(36), nullable=True)
 
95
 
 
96
    try:
 
97
        fkeys = list(snapshots.c.volume_id.foreign_keys)
 
98
        if fkeys:
 
99
            fkey_name = fkeys[0].constraint.name
 
100
            ForeignKeyConstraint(columns=[snapshots.c.volume_id],
 
101
                    refcolumns=[volumes.c.id],
 
102
                    name=fkey_name).create()
 
103
 
 
104
        fkeys = list(iscsi_targets.c.volume_id.foreign_keys)
 
105
        if fkeys:
 
106
            fkey_name = fkeys[0].constraint.name
 
107
            ForeignKeyConstraint(columns=[iscsi_targets.c.volume_id],
 
108
                                 refcolumns=[volumes.c.id],
 
109
                                 name=fkey_name).create()
 
110
 
 
111
        fkeys = list(volume_metadata.c.volume_id.foreign_keys)
 
112
        if fkeys:
 
113
            fkey_name = fkeys[0].constraint.name
 
114
            ForeignKeyConstraint(columns=[volume_metadata.c.volume_id],
 
115
                                 refcolumns=[volumes.c.id],
 
116
                                 name=fkey_name).create()
 
117
 
 
118
        fkeys = list(sm_volume.c.id.foreign_keys)
 
119
        if fkeys:
 
120
            fkey_name = fkeys[0].constraint.name
 
121
            ForeignKeyConstraint(columns=[sm_volume.c.id],
 
122
                                 refcolumns=[volumes.c.id],
 
123
                                 name=fkey_name).create()
 
124
        # NOTE(jdg) We're intentionally leaving off FK's on BDM
 
125
 
 
126
    except Exception:
 
127
        LOG.error(_("Foreign Key constraint couldn't be removed"))
 
128
        raise
 
129
 
 
130
 
 
131
def downgrade(migrate_engine):
 
132
    """Convert volume and snapshot id columns back to int."""
 
133
    meta = MetaData()
 
134
    meta.bind = migrate_engine
 
135
    dialect = migrate_engine.url.get_dialect().name
 
136
 
 
137
    if dialect.startswith('sqlite'):
 
138
        return
 
139
 
 
140
    volumes = Table('volumes', meta, autoload=True)
 
141
    snapshots = Table('snapshots', meta, autoload=True)
 
142
    iscsi_targets = Table('iscsi_targets', meta, autoload=True)
 
143
    volume_metadata = Table('volume_metadata', meta, autoload=True)
 
144
    sm_volume = Table('sm_volume', meta, autoload=True)
 
145
    block_device_mapping = Table('block_device_mapping', meta, autoload=True)
 
146
 
 
147
    try:
 
148
        fkeys = list(snapshots.c.volume_id.foreign_keys)
 
149
        if fkeys:
 
150
            fkey_name = fkeys[0].constraint.name
 
151
            ForeignKeyConstraint(columns=[snapshots.c.volume_id],
 
152
                    refcolumns=[volumes.c.id],
 
153
                    name=fkey_name).drop()
 
154
 
 
155
        fkeys = list(iscsi_targets.c.volume_id.foreign_keys)
 
156
        if fkeys:
 
157
            fkey_name = fkeys[0].constraint.name
 
158
            ForeignKeyConstraint(columns=[iscsi_targets.c.volume_id],
 
159
                                 refcolumns=[volumes.c.id],
 
160
                                 name=fkey_name).drop()
 
161
 
 
162
        fkeys = list(volume_metadata.c.volume_id.foreign_keys)
 
163
        if fkeys:
 
164
            fkey_name = fkeys[0].constraint.name
 
165
            ForeignKeyConstraint(columns=[volume_metadata.c.volume_id],
 
166
                                 refcolumns=[volumes.c.id],
 
167
                                 name=fkey_name).drop()
 
168
 
 
169
        fkeys = list(sm_volume.c.id.foreign_keys)
 
170
        if fkeys:
 
171
            fkey_name = fkeys[0].constraint.name
 
172
            ForeignKeyConstraint(columns=[sm_volume.c.id],
 
173
                                 refcolumns=[volumes.c.id],
 
174
                                 name=fkey_name).drop()
 
175
 
 
176
    except Exception:
 
177
        LOG.error(_("Foreign Key constraint couldn't be removed"))
 
178
        raise
 
179
 
 
180
    volumes.c.id.alter(Integer, primary_key=True, autoincrement=True)
 
181
    volumes.c.snapshot_id.alter(Integer)
 
182
    volume_metadata.c.volume_id.alter(Integer, nullable=False)
 
183
    snapshots.c.id.alter(Integer, primary_key=True, autoincrement=True)
 
184
    snapshots.c.volume_id.alter(Integer)
 
185
    sm_volume.c.id.alter(Integer)
 
186
    block_device_mapping.c.volume_id.alter(Integer)
 
187
    block_device_mapping.c.snapshot_id.alter(Integer)
 
188
    iscsi_targets.c.volume_id.alter(Integer, nullable=True)
 
189
 
 
190
    try:
 
191
        fkeys = list(snapshots.c.volume_id.foreign_keys)
 
192
        if fkeys:
 
193
            fkey_name = fkeys[0].constraint.name
 
194
            ForeignKeyConstraint(columns=[snapshots.c.volume_id],
 
195
                    refcolumns=[volumes.c.id],
 
196
                    name=fkey_name).create()
 
197
 
 
198
        fkeys = list(iscsi_targets.c.volume_id.foreign_keys)
 
199
        if fkeys:
 
200
            fkey_name = fkeys[0].constraint.name
 
201
            ForeignKeyConstraint(columns=[iscsi_targets.c.volume_id],
 
202
                                 refcolumns=[volumes.c.id],
 
203
                                 name=fkey_name).create()
 
204
 
 
205
        fkeys = list(volume_metadata.c.volume_id.foreign_keys)
 
206
        if fkeys:
 
207
            fkey_name = fkeys[0].constraint.name
 
208
            ForeignKeyConstraint(columns=[volume_metadata.c.volume_id],
 
209
                                 refcolumns=[volumes.c.id],
 
210
                                 name=fkey_name).create()
 
211
 
 
212
        fkeys = list(sm_volume.c.id.foreign_keys)
 
213
        if fkeys:
 
214
            fkey_name = fkeys[0].constraint.name
 
215
            ForeignKeyConstraint(columns=[sm_volume.c.id],
 
216
                                 refcolumns=[volumes.c.id],
 
217
                                 name=fkey_name).create()
 
218
 
 
219
        # NOTE(jdg) Put the BDM foreign keys back in place
 
220
        fkeys = list(block_device_mapping.c.volume_id.foreign_keys)
 
221
        if fkeys:
 
222
            fkey_name = fkeys[0].constraint.name
 
223
            ForeignKeyConstraint(columns=[block_device_mapping.c.volume_id],
 
224
                                 refcolumns=[volumes.c.id],
 
225
                                 name=fkey_name).drop()
 
226
 
 
227
        fkeys = list(block_device_mapping.c.snapshot_id.foreign_keys)
 
228
        if fkeys:
 
229
            fkey_name = fkeys[0].constraint.name
 
230
            ForeignKeyConstraint(columns=[block_device_mapping.c.snapshot_id],
 
231
                                 refcolumns=[snapshots.c.id],
 
232
                                 name=fkey_name).drop()
 
233
 
 
234
    except Exception:
 
235
        LOG.error(_("Foreign Key constraint couldn't be removed"))
 
236
        raise