Merge "Add l3 db migration for plugins which did not support in folsom"

This commit is contained in:
Jenkins 2013-03-13 00:08:27 +00:00 committed by Gerrit Code Review
commit 45d197d7b1
4 changed files with 144 additions and 67 deletions

View File

@ -0,0 +1,85 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2013 Openstack LLC
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""
Upgrade/downgrade operations for 'community' extensions
"""
from alembic import op
import sqlalchemy as sa
def upgrade_l3():
op.create_table(
'routers',
sa.Column('tenant_id', sa.String(length=255), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('name', sa.String(length=255), nullable=True),
sa.Column('status', sa.String(length=16), nullable=True),
sa.Column('admin_state_up', sa.Boolean(), nullable=True),
sa.Column('gw_port_id', sa.String(length=36), nullable=True),
sa.ForeignKeyConstraint(['gw_port_id'], ['ports.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table(
'externalnetworks',
sa.Column('network_id', sa.String(length=36), nullable=False),
sa.ForeignKeyConstraint(['network_id'], ['networks.id'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('network_id')
)
op.create_table(
'floatingips',
sa.Column('tenant_id', sa.String(length=255), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('floating_ip_address', sa.String(length=64), nullable=False),
sa.Column('floating_network_id', sa.String(length=36), nullable=False),
sa.Column('floating_port_id', sa.String(length=36), nullable=False),
sa.Column('fixed_port_id', sa.String(length=36), nullable=True),
sa.Column('fixed_ip_address', sa.String(length=64), nullable=True),
sa.Column('router_id', sa.String(length=36), nullable=True),
sa.ForeignKeyConstraint(['fixed_port_id'], ['ports.id'], ),
sa.ForeignKeyConstraint(['floating_port_id'], ['ports.id'], ),
sa.ForeignKeyConstraint(['router_id'], ['routers.id'], ),
sa.PrimaryKeyConstraint('id')
)
def upgrade_quota(options=None):
if not (options or {}).get('folsom_quota_db_enabled'):
return
op.create_table(
'quotas',
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(255), index=True),
sa.Column('resource', sa.String(255)),
sa.Column('limit', sa.Integer()),
sa.PrimaryKeyConstraint('id')
)
def downgrade_l3():
for table in ('floatingips', 'routers', 'externalnetworks'):
op.drop_table(table)
def downgrade_quota(options=None):
if (options or {}).get('folsom_quota_db_enabled'):
op.drop_table('quotas')

View File

@ -0,0 +1,52 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2013 OpenStack LLC
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""l3_support
Revision ID: 2c4af419145b
Revises: folsom
Create Date: 2013-03-11 19:26:45.697774
"""
# revision identifiers, used by Alembic.
revision = '2c4af419145b'
down_revision = 'folsom'
# Change to ['*'] if this migration applies to all plugins
migration_for_plugins = [
'quantum.plugins.bigswitch.plugin.QuantumRestProxyV2',
'quantum.plugins.hyperv.hyperv_quantum_plugin.HyperVQuantumPlugin',
'quantum.plugins.midonet.plugin.MidonetPluginV2',
'quantum.plugins.nicira.nicira_nvp_plugin.QuantumPlugin.NvpPluginV2'
]
from quantum.db import migration
from quantum.db.migration.alembic_migrations import common_ext_ops
def upgrade(active_plugin=None, options=None):
if not migration.should_run(active_plugin, migration_for_plugins):
return
common_ext_ops.upgrade_l3()
def downgrade(active_plugin=None, options=None):
if not migration.should_run(active_plugin, migration_for_plugins):
return
common_ext_ops.downgrade_l3()

View File

@ -22,7 +22,7 @@ This retroactively provides migration support for
https://review.openstack.org/#/c/11204/
Revision ID: 5a875d0e5c
Revises: folsom
Revises: 2c4af419145b
Create Date: 2012-12-18 12:32:04.482477
"""
@ -30,7 +30,7 @@ Create Date: 2012-12-18 12:32:04.482477
# revision identifiers, used by Alembic.
revision = '5a875d0e5c'
down_revision = 'folsom'
down_revision = '2c4af419145b'
# Change to ['*'] if this migration applies to all plugins

View File

@ -57,6 +57,7 @@ down_revision = None
from alembic import op
import sqlalchemy as sa
from quantum.db.migration.alembic_migrations import common_ext_ops
# NOTE: This is a special migration that creates a Folsom compatible database.
@ -65,10 +66,10 @@ def upgrade(active_plugin=None, options=None):
upgrade_base()
if active_plugin in L3_CAPABLE:
upgrade_l3()
common_ext_ops.upgrade_l3()
if active_plugin in FOLSOM_QUOTA:
upgrade_quota(options)
common_ext_ops.upgrade_quota(options)
if active_plugin == PLUGINS['lbr']:
upgrade_linuxbridge()
@ -186,58 +187,6 @@ def upgrade_base():
)
def upgrade_l3():
op.create_table(
'routers',
sa.Column('tenant_id', sa.String(length=255), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('name', sa.String(length=255), nullable=True),
sa.Column('status', sa.String(length=16), nullable=True),
sa.Column('admin_state_up', sa.Boolean(), nullable=True),
sa.Column('gw_port_id', sa.String(length=36), nullable=True),
sa.ForeignKeyConstraint(['gw_port_id'], ['ports.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table(
'externalnetworks',
sa.Column('network_id', sa.String(length=36), nullable=False),
sa.ForeignKeyConstraint(['network_id'], ['networks.id'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('network_id')
)
op.create_table(
'floatingips',
sa.Column('tenant_id', sa.String(length=255), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('floating_ip_address', sa.String(length=64), nullable=False),
sa.Column('floating_network_id', sa.String(length=36), nullable=False),
sa.Column('floating_port_id', sa.String(length=36), nullable=False),
sa.Column('fixed_port_id', sa.String(length=36), nullable=True),
sa.Column('fixed_ip_address', sa.String(length=64), nullable=True),
sa.Column('router_id', sa.String(length=36), nullable=True),
sa.ForeignKeyConstraint(['fixed_port_id'], ['ports.id'], ),
sa.ForeignKeyConstraint(['floating_port_id'], ['ports.id'], ),
sa.ForeignKeyConstraint(['router_id'], ['routers.id'], ),
sa.PrimaryKeyConstraint('id')
)
def upgrade_quota(options=None):
if not (options or {}).get('folsom_quota_db_enabled'):
return
op.create_table(
'quotas',
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(255), index=True),
sa.Column('resource', sa.String(255)),
sa.Column('limit', sa.Integer()),
sa.PrimaryKeyConstraint('id')
)
def upgrade_linuxbridge():
op.create_table(
'network_states',
@ -493,10 +442,10 @@ def downgrade(active_plugin=None, options=None):
downgrade_ryu()
if active_plugin in FOLSOM_QUOTA:
downgrade_quota(options)
common_ext_ops.downgrade_quota(options)
if active_plugin in L3_CAPABLE:
downgrade_l3()
common_ext_ops.downgrade_l3()
downgrade_base()
@ -514,15 +463,6 @@ def downgrade_base():
)
def downgrade_l3():
drop_tables('floatingips', 'routers', 'externalnetworks')
def downgrade_quota(options=None):
if (options or {}).get('folsom_quota_db_enabled'):
drop_tables('quotas')
def downgrade_linuxbridge():
drop_tables('network_bindings', 'network_states')