import functools
import logging
import pprint
+import six
import alembic
import alembic.autogenerate
from oslo_db.sqlalchemy import test_base
from oslo_db.sqlalchemy import test_migrations
import sqlalchemy
+from sqlalchemy import event
from neutron.db.migration.alembic_migrations import external
from neutron.db.migration import cli as migration
def db_sync(self, engine):
cfg.CONF.set_override('connection', engine.url, group='database')
migration.do_alembic_command(self.alembic_config, 'upgrade', 'heads')
- cfg.CONF.clear_override('connection', group='database')
def get_engine(self):
return self.engine
class TestModelsMigrationsMysql(_TestModelsMigrations,
base.MySQLTestCase):
- pass
+
+ # There is no use to run this against both dialects, so add this test just
+ # for MySQL tests
+ def test_external_tables_not_changed(self):
+
+ def block_external_tables(conn, clauseelement, multiparams, params):
+ if isinstance(clauseelement, sqlalchemy.sql.selectable.Select):
+ return
+
+ if (isinstance(clauseelement, six.string_types) and
+ any(name in clauseelement for name in external.TABLES)):
+ self.fail("External table referenced by neutron core "
+ "migration.")
+
+ if hasattr(clauseelement, 'element'):
+ if (clauseelement.element.name in external.TABLES or
+ (hasattr(clauseelement, 'table') and
+ clauseelement.element.table.name in external.TABLES)):
+ self.fail("External table referenced by neutron core "
+ "migration.")
+
+ engine = self.get_engine()
+ cfg.CONF.set_override('connection', engine.url, group='database')
+ migration.do_alembic_command(self.alembic_config, 'upgrade', 'kilo')
+
+ event.listen(engine, 'before_execute', block_external_tables)
+ migration.do_alembic_command(self.alembic_config, 'upgrade', 'heads')
+
+ event.remove(engine, 'before_execute', block_external_tables)
class TestModelsMigrationsPsql(_TestModelsMigrations,