From 90abfc6b04f1acf61e8a8b3413a90d2a12de68b8 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Mon, 11 Mar 2013 19:33:01 +0100 Subject: [PATCH] Add l3 db migration for plugins which did not support in folsom Bug 1153585 Several plugins added l3 support in the grizzly release. This means that when upgrading from the folsom data model, the relevant data model changes should be applied. In order to do so this patch refactors the initial migration in order to be able to reuse the upgrade_l3 and downgrade_l3 routines. Change-Id: I876f6d637665e10fb09d2084bb8a545ce469fbf3 --- .../alembic_migrations/common_ext_ops.py | 85 +++++++++++++++++++ .../versions/2c4af419145b_l3_support.py | 52 ++++++++++++ .../versions/5a875d0e5c_ryu.py | 4 +- .../versions/folsom_initial.py | 70 ++------------- 4 files changed, 144 insertions(+), 67 deletions(-) create mode 100644 quantum/db/migration/alembic_migrations/common_ext_ops.py create mode 100644 quantum/db/migration/alembic_migrations/versions/2c4af419145b_l3_support.py diff --git a/quantum/db/migration/alembic_migrations/common_ext_ops.py b/quantum/db/migration/alembic_migrations/common_ext_ops.py new file mode 100644 index 000000000..197711341 --- /dev/null +++ b/quantum/db/migration/alembic_migrations/common_ext_ops.py @@ -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') diff --git a/quantum/db/migration/alembic_migrations/versions/2c4af419145b_l3_support.py b/quantum/db/migration/alembic_migrations/versions/2c4af419145b_l3_support.py new file mode 100644 index 000000000..97a7afc5b --- /dev/null +++ b/quantum/db/migration/alembic_migrations/versions/2c4af419145b_l3_support.py @@ -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() diff --git a/quantum/db/migration/alembic_migrations/versions/5a875d0e5c_ryu.py b/quantum/db/migration/alembic_migrations/versions/5a875d0e5c_ryu.py index 651ce569f..3d07bad31 100644 --- a/quantum/db/migration/alembic_migrations/versions/5a875d0e5c_ryu.py +++ b/quantum/db/migration/alembic_migrations/versions/5a875d0e5c_ryu.py @@ -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 diff --git a/quantum/db/migration/alembic_migrations/versions/folsom_initial.py b/quantum/db/migration/alembic_migrations/versions/folsom_initial.py index ee85e2f11..fb1d01529 100644 --- a/quantum/db/migration/alembic_migrations/versions/folsom_initial.py +++ b/quantum/db/migration/alembic_migrations/versions/folsom_initial.py @@ -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') -- 2.45.2