]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Skip external tables for neutron-db-manage --autogenerate
authorHenry Gessau <gessau@cisco.com>
Mon, 25 May 2015 22:00:58 +0000 (18:00 -0400)
committerHenry Gessau <gessau@cisco.com>
Mon, 25 May 2015 22:19:07 +0000 (18:19 -0400)
DB tables that do not have models in the neutron tree cause
neutron-db-manage --autogenerate to create commands to drop the
tables. This fix hooks into alembic's environment with a include_object
callback that ignores external tables.

We already had a list of external tables for use by the migration tests,
so re-use them for --autogenerate.

Partial-bug: #1458682

Change-Id: I2c0bc73f72840c401c578e87d8178a79f05aad82

neutron/db/migration/alembic_migrations/env.py
neutron/db/migration/alembic_migrations/external.py [new file with mode: 0644]
neutron/tests/functional/db/test_migrations.py

index 9966f55e7975ad6af5e4bb9461baa2297778ad42..f90bf43c307c5d09bf6360bc5af2f594f21d62eb 100644 (file)
@@ -20,6 +20,7 @@ from oslo_db.sqlalchemy import session
 import sqlalchemy as sa
 from sqlalchemy import event
 
+from neutron.db.migration.alembic_migrations import external
 from neutron.db.migration.models import head  # noqa
 from neutron.db import model_base
 
@@ -50,6 +51,13 @@ def set_mysql_engine():
                     model_base.BASEV2.__table_args__['mysql_engine'])
 
 
+def include_object(object, name, type_, reflected, compare_to):
+    if type_ == 'table' and name in external.TABLES:
+        return False
+    else:
+        return True
+
+
 def run_migrations_offline():
     """Run migrations in 'offline' mode.
 
@@ -67,6 +75,7 @@ def run_migrations_offline():
         kwargs['url'] = neutron_config.database.connection
     else:
         kwargs['dialect_name'] = neutron_config.database.engine
+    kwargs['include_object'] = include_object
     context.configure(**kwargs)
 
     with context.begin_transaction():
@@ -92,7 +101,8 @@ def run_migrations_online():
     connection = engine.connect()
     context.configure(
         connection=connection,
-        target_metadata=target_metadata
+        target_metadata=target_metadata,
+        include_object=include_object
     )
 
     try:
diff --git a/neutron/db/migration/alembic_migrations/external.py b/neutron/db/migration/alembic_migrations/external.py
new file mode 100644 (file)
index 0000000..412992d
--- /dev/null
@@ -0,0 +1,27 @@
+#    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.
+
+
+# These tables are in the neutron database, but their models have moved
+# to separate repositories. We skip the migration checks for these tables.
+
+VPNAAS_TABLES = ['vpnservices', 'ipsecpolicies', 'ipsecpeercidrs',
+                 'ipsec_site_connections', 'cisco_csr_identifier_map',
+                 'ikepolicies']
+
+LBAAS_TABLES = ['vips', 'sessionpersistences', 'pools', 'healthmonitors',
+                'poolstatisticss', 'members', 'poolloadbalanceragentbindings',
+                'embrane_pool_port', 'poolmonitorassociations']
+
+FWAAS_TABLES = ['firewall_rules', 'firewalls', 'firewall_policies']
+
+TABLES = (FWAAS_TABLES + LBAAS_TABLES + VPNAAS_TABLES)
index 98e178a158b60696ace1dd373f4ca5e6c21906ca..a05bbb215e8a31700d5cc6a95fa8903e00647f0b 100644 (file)
@@ -27,6 +27,7 @@ from oslo_db.sqlalchemy import test_base
 from oslo_db.sqlalchemy import test_migrations
 import sqlalchemy
 
+from neutron.db.migration.alembic_migrations import external
 from neutron.db.migration import cli as migration
 from neutron.db.migration.models import head as head_models
 
@@ -37,26 +38,6 @@ cfg.CONF.import_opt('core_plugin', 'neutron.common.config')
 
 CORE_PLUGIN = 'neutron.plugins.ml2.plugin.Ml2Plugin'
 
-# These tables are still in the neutron database, but their models have moved
-# to the separate advanced services repositories. We skip the migration checks
-# for these tables for now. The checks will be re-instated soon in the tests
-# for each separate repository.
-# TODO(akamyshnikova): delete these lists when the tables are removed from
-# neutron database.
-EXTERNAL_VPNAAS_TABLES = ['vpnservices', 'ipsecpolicies', 'ipsecpeercidrs',
-                          'ipsec_site_connections', 'cisco_csr_identifier_map',
-                          'ikepolicies']
-
-EXTERNAL_LBAAS_TABLES = ['vips', 'sessionpersistences', 'pools',
-                         'healthmonitors', 'poolstatisticss', 'members',
-                         'poolloadbalanceragentbindings', 'embrane_pool_port',
-                         'poolmonitorassociations']
-
-EXTERNAL_FWAAS_TABLES = ['firewall_rules', 'firewalls', 'firewall_policies']
-
-EXTERNAL_TABLES = (EXTERNAL_FWAAS_TABLES + EXTERNAL_LBAAS_TABLES +
-                   EXTERNAL_VPNAAS_TABLES)
-
 
 class _TestModelsMigrations(test_migrations.ModelsMigrationsSync):
     '''Test for checking of equality models state and migrations.
@@ -150,7 +131,7 @@ class _TestModelsMigrations(test_migrations.ModelsMigrationsSync):
 
     def include_object(self, object_, name, type_, reflected, compare_to):
         if type_ == 'table' and (name == 'alembic_version'
-                                 or name in EXTERNAL_TABLES):
+                                 or name in external.TABLES):
                 return False
 
         return super(_TestModelsMigrations, self).include_object(