From 251159c90a69dfb61d9927093d5eae41cd99e2a7 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Thu, 9 Jan 2014 13:49:10 -0800 Subject: [PATCH] Fix Migration 50e86cb2637a and 38335592a0dc When the rename of quantum->neutron occurred here ee3fe4e8 it also renamed the the table creation from quantum_nvp_port_mapping to neutron_nvp_port_mapping. This went undetected for a long time because when neutron-server starts up it pushes down the scheme for tables that are not there so the table would be created. Because of this the following migration 50e86cb2637a called op.rename_table('neutron_nvp_port_mapping', 'neutron_nsx_port_mappings') though the table name being used was quantum_nvp_port_mapping. Because of this the quantum_id->nvp_id mapping was never migrated over to the new table and you would be left with a quantum_nvp_port_mapping table hanging around. In addition, the downgrade would rename the table to neutron_nvp_port_mapping instead of quantum_nvp_port_mapping. This patch addresses this issues. Change-Id: I4f80b7b9dc56996ecd83826ee65918f5311c7c4f Closes-bug: #1267619 --- .../versions/38335592a0dc_nvp_portmap.py | 10 ++--- .../versions/50e86cb2637a_nsx_mappings.py | 45 ++++++++++++------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/neutron/db/migration/alembic_migrations/versions/38335592a0dc_nvp_portmap.py b/neutron/db/migration/alembic_migrations/versions/38335592a0dc_nvp_portmap.py index fd9de4d30..a514d36c3 100644 --- a/neutron/db/migration/alembic_migrations/versions/38335592a0dc_nvp_portmap.py +++ b/neutron/db/migration/alembic_migrations/versions/38335592a0dc_nvp_portmap.py @@ -44,16 +44,16 @@ def upgrade(active_plugins=None, options=None): return op.create_table( - 'neutron_nvp_port_mapping', - sa.Column('neutron_id', sa.String(length=36), nullable=False), + 'quantum_nvp_port_mapping', + sa.Column('quantum_id', sa.String(length=36), nullable=False), sa.Column('nvp_id', sa.String(length=36), nullable=True), - sa.ForeignKeyConstraint(['neutron_id'], ['ports.id'], + sa.ForeignKeyConstraint(['quantum_id'], ['ports.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('neutron_id')) + sa.PrimaryKeyConstraint('quantum_id')) def downgrade(active_plugins=None, options=None): if not migration.should_run(active_plugins, migration_for_plugins): return - op.drop_table('neutron_nvp_port_mapping') + op.drop_table('quantum_nvp_port_mapping') diff --git a/neutron/db/migration/alembic_migrations/versions/50e86cb2637a_nsx_mappings.py b/neutron/db/migration/alembic_migrations/versions/50e86cb2637a_nsx_mappings.py index 85e72f074..7ecc46070 100644 --- a/neutron/db/migration/alembic_migrations/versions/50e86cb2637a_nsx_mappings.py +++ b/neutron/db/migration/alembic_migrations/versions/50e86cb2637a_nsx_mappings.py @@ -44,26 +44,37 @@ def upgrade(active_plugins=None, options=None): if not migration.should_run(active_plugins, migration_for_plugins): return - # Update table for port/lswitchport mappings - op.rename_table('neutron_nvp_port_mapping', 'neutron_nsx_port_mappings') - op.add_column( - 'neutron_nsx_port_mappings', - sa.Column('nsx_switch_id', sa.String(length=36), nullable=True)) - op.alter_column( - 'neutron_nsx_port_mappings', 'nvp_id', - new_column_name='nsx_port_id', - existing_nullable=True, - existing_type=sa.String(length=36)) + op.create_table('neutron_nsx_port_mappings', + sa.Column('neutron_id', sa.String(length=36), + nullable=False), + sa.Column('nsx_port_id', sa.String(length=36), + nullable=False), + sa.Column('nsx_switch_id', sa.String(length=36), + nullable=True), + sa.ForeignKeyConstraint(['neutron_id'], ['ports.id'], + ondelete='CASCADE'), + sa.PrimaryKeyConstraint('neutron_id')) + + op.execute("INSERT INTO neutron_nsx_port_mappings SELECT quantum_id as " + "neutron_id, nvp_id as nsx_port_id, null as nsx_switch_id from" + " quantum_nvp_port_mapping") + op.drop_table('quantum_nvp_port_mapping') def downgrade(active_plugins=None, options=None): if not migration.should_run(active_plugins, migration_for_plugins): return + # Restore table to pre-icehouse version - op.drop_column('neutron_nsx_port_mappings', 'nsx_switch_id') - op.alter_column( - 'neutron_nsx_port_mappings', 'nsx_port_id', - new_column_name='nvp_id', - existing_nullable=True, - existing_type=sa.String(length=36)) - op.rename_table('neutron_nsx_port_mappings', 'neutron_nvp_port_mapping') + op.create_table('quantum_nvp_port_mapping', + sa.Column('quantum_id', sa.String(length=36), + nullable=False), + sa.Column('nvp_id', sa.String(length=36), + nullable=False), + sa.ForeignKeyConstraint(['quantum_id'], ['ports.id'], + ondelete='CASCADE'), + sa.PrimaryKeyConstraint('quantum_id')) + op.execute("INSERT INTO quantum_nvp_port_mapping SELECT neutron_id as " + "quantum_id, nsx_port_id as nvp_id from" + " neutron_nsx_port_mappings") + op.drop_table('neutron_nsx_port_mappings') -- 2.45.2