~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/migrate_repo/versions/096_recreate_dns_domains.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 (c) 2012 Red Hat, Inc.
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 Boolean, Column, DateTime, ForeignKey
20
 
from sqlalchemy import MetaData, String, Table
21
 
 
22
 
 
23
 
def upgrade(migrate_engine):
24
 
    meta = MetaData()
25
 
    meta.bind = migrate_engine
26
 
 
27
 
    # NOTE(dprince): The old dns_domains table is in the 'latin1'
28
 
    # charset and had its primary key length set to 512.
29
 
    # This is too long to be a valid pkey in the 'utf8' table charset
30
 
    # and is the root cause of errors like:
31
 
    #
32
 
    # 1) Dumping a database with mysqldump and trying to import it fails
33
 
    #    because this table is latin1 but fkeys to utf8 tables (projects).
34
 
    #
35
 
    # 2) Trying to alter the old dns_domains table fails with errors like:
36
 
    #    mysql> ALTER TABLE dns_domains DROP PRIMARY KEY;
37
 
    #    ERROR 1025 (HY000): Error on rename of './nova/#sql-6cf_855'....
38
 
    #
39
 
    # In short this table is just in a bad state. So... lets create a new one
40
 
    # with a shorter 'domain' column which is valid for the utf8 charset.
41
 
    # https://bugs.launchpad.net/nova/+bug/993663
42
 
 
43
 
    #rename old table
44
 
    dns_domains_old = Table('dns_domains', meta, autoload=True)
45
 
    dns_domains_old.rename(name='dns_domains_old')
46
 
 
47
 
    # NOTE(dprince): manually remove pkey/fkey for postgres
48
 
    if migrate_engine.name == "postgresql":
49
 
        sql = """ALTER TABLE ONLY dns_domains_old DROP CONSTRAINT
50
 
              dns_domains_pkey;
51
 
              ALTER TABLE ONLY dns_domains_old DROP CONSTRAINT
52
 
              dns_domains_project_id_fkey;"""
53
 
        migrate_engine.execute(sql)
54
 
 
55
 
    #Bind new metadata to avoid issues after the rename
56
 
    meta = MetaData()
57
 
    meta.bind = migrate_engine
58
 
    projects = Table('projects', meta, autoload=True)  # Required for fkey
59
 
 
60
 
    dns_domains_new = Table('dns_domains', meta,
61
 
        Column('created_at', DateTime),
62
 
        Column('updated_at', DateTime),
63
 
        Column('deleted_at', DateTime),
64
 
        Column('deleted', Boolean),
65
 
        Column('domain', String(length=255), nullable=False, primary_key=True),
66
 
        Column('scope', String(length=255)),
67
 
        Column('availability_zone', String(length=255)),
68
 
        Column('project_id', String(length=255), ForeignKey('projects.id')),
69
 
        mysql_engine='InnoDB',
70
 
        mysql_charset='utf8',
71
 
    )
72
 
    dns_domains_new.create()
73
 
 
74
 
    dns_domains_old = Table('dns_domains_old', meta, autoload=True)
75
 
    record_list = list(dns_domains_old.select().execute())
76
 
    for rec in record_list:
77
 
        row = dns_domains_new.insert()
78
 
        row.execute({'created_at': rec['created_at'],
79
 
                    'updated_at': rec['updated_at'],
80
 
                    'deleted_at': rec['deleted_at'],
81
 
                    'deleted': rec['deleted'],
82
 
                    'domain': rec['domain'],
83
 
                    'scope': rec['scope'],
84
 
                    'availability_zone': rec['availability_zone'],
85
 
                    'project_id': rec['project_id'],
86
 
                    })
87
 
 
88
 
    dns_domains_old.drop()
89
 
 
90
 
 
91
 
def downgrade(migrate_engine):
92
 
    meta = MetaData()
93
 
    meta.bind = migrate_engine
94
 
    dns_domains_old = Table('dns_domains', meta, autoload=True)
95
 
    dns_domains_old.rename(name='dns_domains_old')
96
 
 
97
 
    # NOTE(dprince): manually remove pkey/fkey for postgres
98
 
    if migrate_engine.name == "postgresql":
99
 
        sql = """ALTER TABLE ONLY dns_domains_old DROP CONSTRAINT
100
 
              dns_domains_pkey;
101
 
              ALTER TABLE ONLY dns_domains_old DROP CONSTRAINT
102
 
              dns_domains_project_id_fkey;"""
103
 
        migrate_engine.execute(sql)
104
 
 
105
 
    #Bind new metadata to avoid issues after the rename
106
 
    meta = MetaData()
107
 
    meta.bind = migrate_engine
108
 
 
109
 
    dns_domains_new = Table('dns_domains', meta,
110
 
        Column('created_at', DateTime),
111
 
        Column('updated_at', DateTime),
112
 
        Column('deleted_at', DateTime),
113
 
        Column('deleted', Boolean),
114
 
        Column('domain', String(length=512), primary_key=True, nullable=False),
115
 
        Column('scope', String(length=255)),
116
 
        Column('availability_zone', String(length=255)),
117
 
        Column('project_id', String(length=255)),
118
 
        mysql_engine='InnoDB',
119
 
        mysql_charset='latin1',
120
 
    )
121
 
    dns_domains_new.create()
122
 
 
123
 
    dns_domains_old = Table('dns_domains_old', meta, autoload=True)
124
 
    record_list = list(dns_domains_old.select().execute())
125
 
    for rec in record_list:
126
 
        row = dns_domains_new.insert()
127
 
        row.execute({'created_at': rec['created_at'],
128
 
                    'updated_at': rec['updated_at'],
129
 
                    'deleted_at': rec['deleted_at'],
130
 
                    'deleted': rec['deleted'],
131
 
                    'domain': rec['domain'],
132
 
                    'scope': rec['scope'],
133
 
                    'availability_zone': rec['availability_zone'],
134
 
                    'project_id': rec['project_id'],
135
 
                    })
136
 
 
137
 
    dns_domains_old.drop()
138
 
 
139
 
    # NOTE(dprince): We can't easily add the MySQL Fkey on the downgrade
140
 
    # because projects is 'utf8' where dns_domains is 'latin1'.
141
 
    if migrate_engine.name != "mysql":
142
 
        projects = Table('projects', meta, autoload=True)
143
 
        fkey = ForeignKeyConstraint(columns=[dns_domains_new.c.project_id],
144
 
                               refcolumns=[projects.c.id])
145
 
        fkey.create()