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
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
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.
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():
connection = engine.connect()
context.configure(
connection=connection,
- target_metadata=target_metadata
+ target_metadata=target_metadata,
+ include_object=include_object
)
try:
--- /dev/null
+# 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)
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
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.
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(