components/openstack/neutron/patches/05-alembic-migrations.patch
author Padma Dakoju <padma.dakoju@oracle.com>
Tue, 03 May 2016 09:54:00 -0700
changeset 5907 e91f569899b8
parent 5865 3e9949415308
permissions -rw-r--r--
23205460 Fix for 23192887 breaks Juno to Kilo upgrade with instances and floating IPs

In-house patch to skip over unnecessary database migrations for Neutron.
Juno database tables for Neutron do not need these migrations when upgrading
to Kilo.

--- neutron-2015.1.2/neutron/db/migration/alembic_migrations/agent_init_ops.py.orig	2016-04-22 23:23:15.523526779 -0700
+++ neutron-2015.1.2/neutron/db/migration/alembic_migrations/agent_init_ops.py	2016-04-22 23:25:39.337181119 -0700
@@ -23,7 +23,10 @@
 
 
 def upgrade():
-    op.create_table(
+    bind = op.get_bind()
+    insp = sa.engine.reflection.Inspector.from_engine(bind)
+    if 'agents' not in insp.get_table_names():
+        op.create_table(
         'agents',
         sa.Column('id', sa.String(length=36), nullable=False),
         sa.Column('agent_type', sa.String(length=255), nullable=False),
--- neutron-2015.1.2/neutron/db/migration/alembic_migrations/core_init_ops.py.orig	2016-04-22 23:25:50.350653015 -0700
+++ neutron-2015.1.2/neutron/db/migration/alembic_migrations/core_init_ops.py	2016-04-22 23:30:15.715403373 -0700
@@ -19,7 +19,11 @@
 
 
 def upgrade():
-    op.create_table(
+    bind = op.get_bind()
+    insp = sa.engine.reflection.Inspector.from_engine(bind)
+    table_names = insp.get_table_names()
+    if 'networks' not in table_names:
+        op.create_table(
         'networks',
         sa.Column('tenant_id', sa.String(length=255), nullable=True),
         sa.Column('id', sa.String(length=36), nullable=False),
@@ -29,7 +33,8 @@
         sa.Column('shared', sa.Boolean(), nullable=True),
         sa.PrimaryKeyConstraint('id'))
 
-    op.create_table(
+    if 'ports' not in table_names:
+        op.create_table(
         'ports',
         sa.Column('tenant_id', sa.String(length=255), nullable=True),
         sa.Column('id', sa.String(length=36), nullable=False),
@@ -43,7 +48,8 @@
         sa.ForeignKeyConstraint(['network_id'], ['networks.id'], ),
         sa.PrimaryKeyConstraint('id'))
 
-    op.create_table(
+    if 'subnets' not in table_names:
+        op.create_table(
         'subnets',
         sa.Column('tenant_id', sa.String(length=255), nullable=True),
         sa.Column('id', sa.String(length=36), nullable=False),
@@ -57,7 +63,8 @@
         sa.ForeignKeyConstraint(['network_id'], ['networks.id'], ),
         sa.PrimaryKeyConstraint('id'))
 
-    op.create_table(
+    if 'dnsnameservers' not in table_names:
+        op.create_table(
         'dnsnameservers',
         sa.Column('address', sa.String(length=128), nullable=False),
         sa.Column('subnet_id', sa.String(length=36), nullable=False),
@@ -65,7 +72,8 @@
                                 ondelete='CASCADE'),
         sa.PrimaryKeyConstraint('address', 'subnet_id'))
 
-    op.create_table(
+    if 'ipallocationpools' not in table_names:
+        op.create_table(
         'ipallocationpools',
         sa.Column('id', sa.String(length=36), nullable=False),
         sa.Column('subnet_id', sa.String(length=36), nullable=True),
@@ -75,7 +83,8 @@
                                 ondelete='CASCADE'),
         sa.PrimaryKeyConstraint('id'))
 
-    op.create_table(
+    if 'subnetroutes' not in table_names:
+        op.create_table(
         'subnetroutes',
         sa.Column('destination', sa.String(length=64), nullable=False),
         sa.Column('nexthop', sa.String(length=64), nullable=False),
@@ -84,7 +93,8 @@
                                 ondelete='CASCADE'),
         sa.PrimaryKeyConstraint('destination', 'nexthop', 'subnet_id'))
 
-    op.create_table(
+    if 'ipallocations' not in table_names:
+        op.create_table(
         'ipallocations',
         sa.Column('port_id', sa.String(length=36), nullable=True),
         sa.Column('ip_address', sa.String(length=64), nullable=False),
@@ -97,7 +107,8 @@
                                 ondelete='CASCADE'),
         sa.PrimaryKeyConstraint('ip_address', 'subnet_id', 'network_id'))
 
-    op.create_table(
+    if 'ipavailabilityranges' not in table_names:
+        op.create_table(
         'ipavailabilityranges',
         sa.Column('allocation_pool_id', sa.String(length=36), nullable=False),
         sa.Column('first_ip', sa.String(length=64), nullable=False),
@@ -106,7 +117,8 @@
                                 ['ipallocationpools.id'], ondelete='CASCADE'),
         sa.PrimaryKeyConstraint('allocation_pool_id', 'first_ip', 'last_ip'))
 
-    op.create_table(
+    if 'networkdhcpagentbindings' not in table_names:
+        op.create_table(
         'networkdhcpagentbindings',
         sa.Column('network_id', sa.String(length=36), nullable=False),
         sa.Column('dhcp_agent_id', sa.String(length=36), nullable=False),
--- neutron-2015.1.2/neutron/db/migration/alembic_migrations/l3_init_ops.py.orig	2016-04-22 23:35:15.205163303 -0700
+++ neutron-2015.1.2/neutron/db/migration/alembic_migrations/l3_init_ops.py	2016-04-22 23:33:36.741262443 -0700
@@ -31,14 +31,20 @@
 
 
 def upgrade():
-    op.create_table(
+    bind = op.get_bind()
+    insp = sa.engine.reflection.Inspector.from_engine(bind)
+    table_names = insp.get_table_names()
+
+    if 'externalnetworks' not in table_names:
+        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(
+    if 'routers' not in table_names:
+        op.create_table(
         'routers',
         sa.Column('tenant_id', sa.String(length=255), nullable=True),
         sa.Column('id', sa.String(length=36), nullable=False),
@@ -51,7 +57,8 @@
         sa.ForeignKeyConstraint(['gw_port_id'], ['ports.id'], ),
         sa.PrimaryKeyConstraint('id'))
 
-    op.create_table(
+    if 'floatingips' not in table_names:
+        op.create_table(
         'floatingips',
         sa.Column('tenant_id', sa.String(length=255), nullable=True),
         sa.Column('id', sa.String(length=36), nullable=False),
--- neutron-2015.1.2/neutron/db/migration/alembic_migrations/other_extensions_init_ops.py.orig	2016-04-22 23:35:35.724592904 -0700
+++ neutron-2015.1.2/neutron/db/migration/alembic_migrations/other_extensions_init_ops.py	2016-04-22 23:37:11.709485583 -0700
@@ -34,7 +34,10 @@
         sa.PrimaryKeyConstraint('provider_name', 'resource_id'),
         sa.UniqueConstraint('resource_id'))
 
-    op.create_table(
+    bind = op.get_bind()
+    insp = sa.engine.reflection.Inspector.from_engine(bind)
+    if 'quotas' not in insp.get_table_names():
+        op.create_table(
         'quotas',
         sa.Column('id', sa.String(length=36), nullable=False),
         sa.Column('tenant_id', sa.String(length=255), nullable=True),
--- neutron-2015.1.2/neutron/db/migration/alembic_migrations/versions/1fcfc149aca4_agents_unique_by_type_and_host.py.orig 2016-04-23 01:59:50.554268246 -0700
+++ neutron-2015.1.2/neutron/db/migration/alembic_migrations/versions/1fcfc149aca4_agents_unique_by_type_and_host.py      2016-04-23 02:01:10.767910540 -0700
@@ -26,6 +26,7 @@
 down_revision = 'e197124d4b9'

 from alembic import op
+import sqlalchemy as sa

 from neutron.db import migration

@@ -41,7 +42,14 @@
         # configured plugin did not create the agents table.
         return

-    op.create_unique_constraint(
+    bind = op.get_bind()
+    insp = sa.engine.reflection.Inspector.from_engine(bind)
+    u_cons_list = insp.get_unique_constraints(TABLE_NAME)
+    u_cons = []
+    for c in u_cons_list:
+        u_cons.append(c['name'])
+    if UC_NAME not in u_cons:
+        op.create_unique_constraint(
         name=UC_NAME,
         source=TABLE_NAME,
         local_cols=['agent_type', 'host']
--- neutron-2015.1.2/neutron/db/migration/alembic_migrations/versions/2eeaf963a447_floatingip_status.py.orig	2016-04-22 23:41:17.060181778 -0700
+++ neutron-2015.1.2/neutron/db/migration/alembic_migrations/versions/2eeaf963a447_floatingip_status.py	2016-04-22 23:57:26.134124564 -0700
@@ -38,11 +38,20 @@
         # did not create the floatingips table.
         return
 
-    op.add_column('floatingips',
+    bind = op.get_bind()
+    insp = sa.engine.reflection.Inspector.from_engine(bind)
+    col_names_list = insp.get_columns('floatingips')
+    col_names = []
+    for c in col_names_list:
+        col_names.append(c['name'])
+
+    if 'last_known_router_id' not in col_names:
+        op.add_column('floatingips',
                   sa.Column('last_known_router_id',
                             sa.String(length=36),
                             nullable=True))
-    op.add_column('floatingips',
+    if 'status' not in col_names:
+        op.add_column('floatingips',
                   sa.Column('status',
                             sa.String(length=16),
                             nullable=True))
--- neutron-2015.1.2/neutron/db/migration/alembic_migrations/versions/2447ad0e9585_add_ipv6_mode_props.py.orig	2016-04-22 23:42:16.956052992 -0700
+++ neutron-2015.1.2/neutron/db/migration/alembic_migrations/versions/2447ad0e9585_add_ipv6_mode_props.py	2016-04-22 23:54:33.628120696 -0700
@@ -37,7 +37,15 @@
                    % ('slaac', 'dhcpv6-stateful', 'dhcpv6-stateless'))
         op.execute("CREATE TYPE ipv6_address_modes AS ENUM ('%s', '%s', '%s')"
                    % ('slaac', 'dhcpv6-stateful', 'dhcpv6-stateless'))
-    op.add_column('subnets',
+    bind = op.get_bind()
+    insp = sa.engine.reflection.Inspector.from_engine(bind)
+    col_names_list = insp.get_columns('subnets')
+    col_names = []
+    for c in col_names_list:
+        col_names.append(c['name'])
+
+    if 'ipv6_ra_mode' not in col_names:
+        op.add_column('subnets',
                   sa.Column('ipv6_ra_mode',
                             sa.Enum('slaac',
                                     'dhcpv6-stateful',
@@ -45,7 +53,8 @@
                                     name='ipv6_ra_modes'),
                             nullable=True)
                   )
-    op.add_column('subnets',
+    if 'ipv6_address_mode' not in col_names:
+        op.add_column('subnets',
                   sa.Column('ipv6_address_mode',
                             sa.Enum('slaac',
                                     'dhcpv6-stateful',
--- neutron-2015.1.2/neutron/db/migration/alembic_migrations/versions/544673ac99ab_add_router_port_table.py.orig	2016-04-22 23:43:11.770727387 -0700
+++ neutron-2015.1.2/neutron/db/migration/alembic_migrations/versions/544673ac99ab_add_router_port_table.py	2016-04-22 23:45:53.016161819 -0700
@@ -40,7 +40,10 @@
 
 
 def upgrade():
-    op.create_table(
+    bind = op.get_bind()
+    insp = sa.engine.reflection.Inspector.from_engine(bind)
+    if 'routerports' not in insp.get_table_names():
+        op.create_table(
         'routerports',
         sa.Column('router_id', sa.String(length=36), nullable=False),
         sa.Column('port_id', sa.String(length=36), nullable=False),
@@ -59,6 +59,6 @@
             ['ports.id'],
             ondelete='CASCADE'
         ),
-    )
+        )

-    op.execute(SQL_STATEMENT)
+        op.execute(SQL_STATEMENT)