~ubuntu-branches/ubuntu/raring/nova/raring-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, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

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 migrate import ForeignKeyConstraint
19
 
from sqlalchemy import Integer
20
 
from sqlalchemy import MetaData, String, Table
21
 
 
22
 
from migrate import ForeignKeyConstraint
23
 
from nova.openstack.common import log as logging
24
 
 
25
 
LOG = logging.getLogger(__name__)
26
 
 
27
 
 
28
 
def upgrade(migrate_engine):
29
 
    """Convert volume and snapshot id columns from int to varchar."""
30
 
    meta = MetaData()
31
 
    meta.bind = migrate_engine
32
 
 
33
 
    volumes = Table('volumes', meta, autoload=True)
34
 
    snapshots = Table('snapshots', meta, autoload=True)
35
 
    iscsi_targets = Table('iscsi_targets', meta, autoload=True)
36
 
    volume_metadata = Table('volume_metadata', meta, autoload=True)
37
 
    sm_volume = Table('sm_volume', meta, autoload=True)
38
 
    block_device_mapping = Table('block_device_mapping', meta, autoload=True)
39
 
 
40
 
    try:
41
 
        fkeys = list(snapshots.c.volume_id.foreign_keys)
42
 
        if fkeys:
43
 
            fkey_name = fkeys[0].constraint.name
44
 
            ForeignKeyConstraint(columns=[snapshots.c.volume_id],
45
 
                    refcolumns=[volumes.c.id],
46
 
                    name=fkey_name).drop()
47
 
 
48
 
        fkeys = list(iscsi_targets.c.volume_id.foreign_keys)
49
 
        if fkeys:
50
 
            fkey_name = fkeys[0].constraint.name
51
 
            ForeignKeyConstraint(columns=[iscsi_targets.c.volume_id],
52
 
                                 refcolumns=[volumes.c.id],
53
 
                                 name=fkey_name).drop()
54
 
 
55
 
        fkeys = list(volume_metadata.c.volume_id.foreign_keys)
56
 
        if fkeys:
57
 
            fkey_name = fkeys[0].constraint.name
58
 
            ForeignKeyConstraint(columns=[volume_metadata.c.volume_id],
59
 
                                 refcolumns=[volumes.c.id],
60
 
                                 name=fkey_name).drop()
61
 
 
62
 
        fkeys = list(sm_volume.c.id.foreign_keys)
63
 
        if fkeys:
64
 
            fkey_name = fkeys[0].constraint.name
65
 
            ForeignKeyConstraint(columns=[sm_volume.c.id],
66
 
                                 refcolumns=[volumes.c.id],
67
 
                                 name=fkey_name).drop()
68
 
 
69
 
        fkeys = list(block_device_mapping.c.volume_id.foreign_keys)
70
 
        if fkeys:
71
 
            fkey_name = fkeys[0].constraint.name
72
 
            ForeignKeyConstraint(columns=[block_device_mapping.c.volume_id],
73
 
                                 refcolumns=[volumes.c.id],
74
 
                                 name=fkey_name).drop()
75
 
 
76
 
        fkeys = list(block_device_mapping.c.snapshot_id.foreign_keys)
77
 
        if fkeys:
78
 
            fkey_name = fkeys[0].constraint.name
79
 
            ForeignKeyConstraint(columns=[block_device_mapping.c.snapshot_id],
80
 
                                 refcolumns=[snapshots.c.id],
81
 
                                 name=fkey_name).drop()
82
 
 
83
 
    except Exception:
84
 
        LOG.error(_("Foreign Key constraint couldn't be removed"))
85
 
        raise
86
 
 
87
 
    volumes.c.id.alter(String(36), primary_key=True)
88
 
    volumes.c.snapshot_id.alter(String(36))
89
 
    volume_metadata.c.volume_id.alter(String(36), nullable=False)
90
 
    snapshots.c.id.alter(String(36), primary_key=True)
91
 
    snapshots.c.volume_id.alter(String(36))
92
 
    sm_volume.c.id.alter(String(36))
93
 
    block_device_mapping.c.volume_id.alter(String(36))
94
 
    block_device_mapping.c.snapshot_id.alter(String(36))
95
 
    iscsi_targets.c.volume_id.alter(String(36), nullable=True)
96
 
 
97
 
    try:
98
 
        fkeys = list(snapshots.c.volume_id.foreign_keys)
99
 
        if fkeys:
100
 
            fkey_name = fkeys[0].constraint.name
101
 
            ForeignKeyConstraint(columns=[snapshots.c.volume_id],
102
 
                    refcolumns=[volumes.c.id],
103
 
                    name=fkey_name).create()
104
 
 
105
 
        fkeys = list(iscsi_targets.c.volume_id.foreign_keys)
106
 
        if fkeys:
107
 
            fkey_name = fkeys[0].constraint.name
108
 
            ForeignKeyConstraint(columns=[iscsi_targets.c.volume_id],
109
 
                                 refcolumns=[volumes.c.id],
110
 
                                 name=fkey_name).create()
111
 
 
112
 
        fkeys = list(volume_metadata.c.volume_id.foreign_keys)
113
 
        if fkeys:
114
 
            fkey_name = fkeys[0].constraint.name
115
 
            ForeignKeyConstraint(columns=[volume_metadata.c.volume_id],
116
 
                                 refcolumns=[volumes.c.id],
117
 
                                 name=fkey_name).create()
118
 
 
119
 
        fkeys = list(sm_volume.c.id.foreign_keys)
120
 
        if fkeys:
121
 
            fkey_name = fkeys[0].constraint.name
122
 
            ForeignKeyConstraint(columns=[sm_volume.c.id],
123
 
                                 refcolumns=[volumes.c.id],
124
 
                                 name=fkey_name).create()
125
 
        # NOTE(jdg) We're intentionally leaving off FK's on BDM
126
 
 
127
 
    except Exception:
128
 
        LOG.error(_("Foreign Key constraint couldn't be removed"))
129
 
        raise
130
 
 
131
 
 
132
 
def downgrade(migrate_engine):
133
 
    """Convert volume and snapshot id columns back to int."""
134
 
    meta = MetaData()
135
 
    meta.bind = migrate_engine
136
 
    dialect = migrate_engine.url.get_dialect().name
137
 
 
138
 
    if dialect.startswith('sqlite'):
139
 
        return
140
 
 
141
 
    volumes = Table('volumes', meta, autoload=True)
142
 
    snapshots = Table('snapshots', meta, autoload=True)
143
 
    iscsi_targets = Table('iscsi_targets', meta, autoload=True)
144
 
    volume_metadata = Table('volume_metadata', meta, autoload=True)
145
 
    sm_volume = Table('sm_volume', meta, autoload=True)
146
 
    block_device_mapping = Table('block_device_mapping', meta, autoload=True)
147
 
 
148
 
    try:
149
 
        fkeys = list(snapshots.c.volume_id.foreign_keys)
150
 
        if fkeys:
151
 
            fkey_name = fkeys[0].constraint.name
152
 
            ForeignKeyConstraint(columns=[snapshots.c.volume_id],
153
 
                    refcolumns=[volumes.c.id],
154
 
                    name=fkey_name).drop()
155
 
 
156
 
        fkeys = list(iscsi_targets.c.volume_id.foreign_keys)
157
 
        if fkeys:
158
 
            fkey_name = fkeys[0].constraint.name
159
 
            ForeignKeyConstraint(columns=[iscsi_targets.c.volume_id],
160
 
                                 refcolumns=[volumes.c.id],
161
 
                                 name=fkey_name).drop()
162
 
 
163
 
        fkeys = list(volume_metadata.c.volume_id.foreign_keys)
164
 
        if fkeys:
165
 
            fkey_name = fkeys[0].constraint.name
166
 
            ForeignKeyConstraint(columns=[volume_metadata.c.volume_id],
167
 
                                 refcolumns=[volumes.c.id],
168
 
                                 name=fkey_name).drop()
169
 
 
170
 
        fkeys = list(sm_volume.c.id.foreign_keys)
171
 
        if fkeys:
172
 
            fkey_name = fkeys[0].constraint.name
173
 
            ForeignKeyConstraint(columns=[sm_volume.c.id],
174
 
                                 refcolumns=[volumes.c.id],
175
 
                                 name=fkey_name).drop()
176
 
 
177
 
    except Exception:
178
 
        LOG.error(_("Foreign Key constraint couldn't be removed"))
179
 
        raise
180
 
 
181
 
    volumes.c.id.alter(Integer, primary_key=True, autoincrement=True)
182
 
    volumes.c.snapshot_id.alter(Integer)
183
 
    volume_metadata.c.volume_id.alter(Integer, nullable=False)
184
 
    snapshots.c.id.alter(Integer, primary_key=True, autoincrement=True)
185
 
    snapshots.c.volume_id.alter(Integer)
186
 
    sm_volume.c.id.alter(Integer)
187
 
    block_device_mapping.c.volume_id.alter(Integer)
188
 
    block_device_mapping.c.snapshot_id.alter(Integer)
189
 
    iscsi_targets.c.volume_id.alter(Integer, nullable=True)
190
 
 
191
 
    try:
192
 
        fkeys = list(snapshots.c.volume_id.foreign_keys)
193
 
        if fkeys:
194
 
            fkey_name = fkeys[0].constraint.name
195
 
            ForeignKeyConstraint(columns=[snapshots.c.volume_id],
196
 
                    refcolumns=[volumes.c.id],
197
 
                    name=fkey_name).create()
198
 
 
199
 
        fkeys = list(iscsi_targets.c.volume_id.foreign_keys)
200
 
        if fkeys:
201
 
            fkey_name = fkeys[0].constraint.name
202
 
            ForeignKeyConstraint(columns=[iscsi_targets.c.volume_id],
203
 
                                 refcolumns=[volumes.c.id],
204
 
                                 name=fkey_name).create()
205
 
 
206
 
        fkeys = list(volume_metadata.c.volume_id.foreign_keys)
207
 
        if fkeys:
208
 
            fkey_name = fkeys[0].constraint.name
209
 
            ForeignKeyConstraint(columns=[volume_metadata.c.volume_id],
210
 
                                 refcolumns=[volumes.c.id],
211
 
                                 name=fkey_name).create()
212
 
 
213
 
        fkeys = list(sm_volume.c.id.foreign_keys)
214
 
        if fkeys:
215
 
            fkey_name = fkeys[0].constraint.name
216
 
            ForeignKeyConstraint(columns=[sm_volume.c.id],
217
 
                                 refcolumns=[volumes.c.id],
218
 
                                 name=fkey_name).create()
219
 
 
220
 
        # NOTE(jdg) Put the BDM foreign keys back in place
221
 
        fkeys = list(block_device_mapping.c.volume_id.foreign_keys)
222
 
        if fkeys:
223
 
            fkey_name = fkeys[0].constraint.name
224
 
            ForeignKeyConstraint(columns=[block_device_mapping.c.volume_id],
225
 
                                 refcolumns=[volumes.c.id],
226
 
                                 name=fkey_name).drop()
227
 
 
228
 
        fkeys = list(block_device_mapping.c.snapshot_id.foreign_keys)
229
 
        if fkeys:
230
 
            fkey_name = fkeys[0].constraint.name
231
 
            ForeignKeyConstraint(columns=[block_device_mapping.c.snapshot_id],
232
 
                                 refcolumns=[snapshots.c.id],
233
 
                                 name=fkey_name).drop()
234
 
 
235
 
    except Exception:
236
 
        LOG.error(_("Foreign Key constraint couldn't be removed"))
237
 
        raise