]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix Migration 50e86cb2637a and 38335592a0dc
authorAaron Rosen <aaronorosen@gmail.com>
Thu, 9 Jan 2014 21:49:10 +0000 (13:49 -0800)
committerAaron Rosen <aaronorosen@gmail.com>
Thu, 9 Jan 2014 23:19:38 +0000 (15:19 -0800)
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

neutron/db/migration/alembic_migrations/versions/38335592a0dc_nvp_portmap.py
neutron/db/migration/alembic_migrations/versions/50e86cb2637a_nsx_mappings.py

index fd9de4d308125b2ddb15cba7bfa701bec578f1a5..a514d36c39d197f54e10a77ccf0f929ff6c18dee 100644 (file)
@@ -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')
index 85e72f0743a266524e05f443438e2249b788ddc3..7ecc460700cd7ea11dfc98baaccc6d0b8a900696 100644 (file)
@@ -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')