22878181 Neutron database tables not upgraded properly from Juno to Kilo schema
authorPadma Dakoju <padma.dakoju@oracle.com>
Sat, 23 Apr 2016 02:37:28 -0700
changeset 5840 ed8b04bef26e
parent 5839 8f8f9a2b0d84
child 5841 97e8c4dc6a82
22878181 Neutron database tables not upgraded properly from Juno to Kilo schema
components/openstack/neutron/Makefile
components/openstack/neutron/files/evs/migrate/neutron-kilo-migration.py
components/openstack/neutron/files/evs/plugin.py
components/openstack/neutron/files/neutron-server
components/openstack/neutron/files/neutron-upgrade
components/openstack/neutron/neutron.p5m
components/openstack/neutron/patches/05-alembic-migrations.patch
--- a/components/openstack/neutron/Makefile	Wed Apr 20 16:48:33 2016 -0700
+++ b/components/openstack/neutron/Makefile	Sat Apr 23 02:37:28 2016 -0700
@@ -96,8 +96,6 @@
     $(MKDIR) $(PROTO_DIR)/usr/lib/neutron; \
     $(CP) files/evs/migrate/evs-neutron-migration.py \
 	 $(PROTO_DIR)/usr/lib/neutron/evs-neutron-migration; \
-    $(CP) files/evs/migrate/neutron-kilo-migration.py \
-	 $(PROTO_DIR)/usr/lib/neutron/neutron-kilo-migration; \
     $(MKDIR) $(PROTO_DIR)/$(PYTHON_LIB)/neutron/agent; \
     $(CP) files/agent/evs_l3_agent.py \
 	 $(PROTO_DIR)/$(PYTHON_LIB)/neutron/agent; \
--- a/components/openstack/neutron/files/evs/migrate/neutron-kilo-migration.py	Wed Apr 20 16:48:33 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-#!/usr/bin/python2.7
-#
-# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
-#
-# 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.
-
-#
-# This script updates the schema for networks, subnets and agents table.
-# This is needed since we do not run Juno to Kilo alembic migrations.
-#
-
-from alembic.migration import MigrationContext
-from alembic.operations import Operations
-import ConfigParser
-import sqlalchemy as sa
-
-
-def main():
-    print "Start Kilo migrations."
-    print "Add new parameters to networks, subnets and agents table."
-
-    config = ConfigParser.RawConfigParser()
-    config.readfp(open("/etc/neutron/neutron.conf"))
-    if config.has_option("database", 'connection'):
-        SQL_CONNECTION = config.get("database", 'connection')
-        neutron_engine = sa.create_engine(SQL_CONNECTION)
-        conn = neutron_engine.connect()
-        ctx = MigrationContext.configure(conn)
-        op = Operations(ctx)
-
-        op.add_column('networks', sa.Column('mtu', sa.Integer(),
-                      nullable=True))
-        op.add_column('networks', sa.Column('vlan_transparent', sa.Boolean(),
-                      nullable=True))
-        op.add_column('agents', sa.Column('load', sa.Integer(),
-                      server_default='0', nullable=False))
-        op.add_column('subnets',
-                      sa.Column('subnetpool_id',
-                                sa.String(length=36),
-                                nullable=True,
-                                index=True))
-    else:
-        print "\nNo database connection found."
-
-    print "\nEnd Migration."
-
-
-if __name__ == '__main__':
-    main()
--- a/components/openstack/neutron/files/evs/plugin.py	Wed Apr 20 16:48:33 2016 -0700
+++ b/components/openstack/neutron/files/evs/plugin.py	Sat Apr 23 02:37:28 2016 -0700
@@ -44,7 +44,6 @@
 from neutron.db import l3_agentschedulers_db
 from neutron.db import l3_attrs_db
 from neutron.db import l3_gwmode_db
-from neutron.db import model_base
 from neutron.db import models_v2
 from neutron.db import portbindings_db
 from neutron.db import quota_db
@@ -168,9 +167,6 @@
                                     "dhcp_agent_scheduler"]
 
     def __init__(self):
-        engine = db.get_engine()
-        model_base.BASEV2.metadata.create_all(engine)
-
         self.network_scheduler = importutils.import_object(
             cfg.CONF.network_scheduler_driver
         )
--- a/components/openstack/neutron/files/neutron-server	Wed Apr 20 16:48:33 2016 -0700
+++ b/components/openstack/neutron/files/neutron-server	Sat Apr 23 02:37:28 2016 -0700
@@ -1,6 +1,6 @@
 #!/usr/bin/python2.7
 
-# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
 #
 #    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
@@ -18,9 +18,20 @@
 import sys
 
 import smf_include
+from subprocess import CalledProcessError, check_call
 
 
 def start():
+    # sync the database to have the Kilo schema
+    cmd = ["/usr/bin/neutron-db-manage", "--config-file",
+           "/etc/neutron/neutron.conf", "--config-file",
+           "/etc/neutron/plugins/evs/evs_plugin.ini", "upgrade", "head"]
+    try:
+        check_call(cmd)
+    except CalledProcessError as err:
+        print "Unable to create database for Neutron: %s" % err
+        sys.exit(smf_include.SMF_EXIT_ERR_CONFIG)
+
     # verify paths are valid
     for f in sys.argv[2:4]:
         if not os.path.exists(f) or not os.access(f, os.R_OK):
--- a/components/openstack/neutron/files/neutron-upgrade	Wed Apr 20 16:48:33 2016 -0700
+++ b/components/openstack/neutron/files/neutron-upgrade	Sat Apr 23 02:37:28 2016 -0700
@@ -104,8 +104,10 @@
         engine = sqlalchemy.create_engine(db_connection)
         if engine.url.username != '%SERVICE_USER%':
             check_call(['/usr/bin/neutron-db-manage', '--config-file',
-                        '/etc/neutron/neutron.conf', 'stamp', 'kilo'])
-            check_call(['/usr/lib/neutron/neutron-kilo-migration'])
+                        '/etc/neutron/neutron.conf', 'upgrade', 'juno'])
+            check_call(['/usr/bin/neutron-db-manage', '--config-file',
+                        '/etc/neutron/neutron.conf', 'upgrade', 'kilo'])
+
 
     # update the current version
     check_call(['/usr/sbin/svccfg', '-s', os.environ['SMF_FMRI'], 'setprop',
--- a/components/openstack/neutron/neutron.p5m	Wed Apr 20 16:48:33 2016 -0700
+++ b/components/openstack/neutron/neutron.p5m	Sat Apr 23 02:37:28 2016 -0700
@@ -154,7 +154,6 @@
 file path=usr/lib/neutron/evs-neutron-migration mode=0555
 file usr/bin/neutron-dhcp-agent path=usr/lib/neutron/neutron-dhcp-agent \
     mode=0555
-file path=usr/lib/neutron/neutron-kilo-migration mode=0555
 file usr/bin/neutron-l3-agent path=usr/lib/neutron/neutron-l3-agent mode=0555
 file usr/bin/neutron-metadata-agent \
     path=usr/lib/neutron/neutron-metadata-agent mode=0555
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/openstack/neutron/patches/05-alembic-migrations.patch	Sat Apr 23 02:37:28 2016 -0700
@@ -0,0 +1,252 @@
+--- 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_name_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),