Skip external tables for neutron-db-manage --autogenerate

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
This commit is contained in:
Henry Gessau 2015-05-25 18:00:58 -04:00
parent 6ba78cec1a
commit 9fc7f56565
3 changed files with 40 additions and 22 deletions

View 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:

View File

@ -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)

View 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(