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)
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'): element = clauseelement.element if (element.name in external.TABLES or (hasattr(clauseelement, 'table') and element.table.name in external.TABLES)): # Table 'nsxv_vdr_dhcp_bindings' was created in liberty, # before NSXV has moved to separate repo. if ((isinstance(clauseelement, sqlalchemy.sql.ddl.CreateTable) and element.name == 'nsxv_vdr_dhcp_bindings')): return self.fail("External table referenced by neutron core " "migration.") engine = self.get_engine() cfg.CONF.set_override('connection', engine.url, group='database') with engine.begin() as connection: self.alembic_config.attributes['connection'] = connection migration.do_alembic_command(self.alembic_config, 'upgrade', 'kilo') with self._listener(engine, block_external_tables): migration.do_alembic_command(self.alembic_config, 'upgrade', 'heads')
def test_branches(self): def check_expand_branch(conn, clauseelement, multiparams, params): if isinstance(clauseelement, migration_help.DROP_OPERATIONS): self.fail("Migration from expand branch contains drop command") def check_contract_branch(conn, clauseelement, multiparams, params): if isinstance(clauseelement, migration_help.CREATION_OPERATIONS): # Skip tables that were created by mistake in contract branch if hasattr(clauseelement, 'element'): element = clauseelement.element if any([ isinstance(element, sqlalchemy.Table) and element.name in [ 'ml2_geneve_allocations', 'ml2_geneve_endpoints' ], isinstance(element, sqlalchemy.ForeignKeyConstraint) and element.table.name == 'flavorserviceprofilebindings', isinstance(element, sqlalchemy.Index) and element.table.name == 'ml2_geneve_allocations' ]): return self.fail("Migration from contract branch contains create " "command") engine = self.get_engine() cfg.CONF.set_override('connection', engine.url, group='database') with engine.begin() as connection: self.alembic_config.attributes['connection'] = connection migration.do_alembic_command(self.alembic_config, 'upgrade', 'kilo') with self._listener(engine, check_expand_branch): migration.do_alembic_command( self.alembic_config, 'upgrade', '%s@head' % migration.EXPAND_BRANCH) with self._listener(engine, check_contract_branch): migration.do_alembic_command( self.alembic_config, 'upgrade', '%s@head' % migration.CONTRACT_BRANCH)
def db_sync(self, engine): cfg.CONF.set_override('connection', engine.url, group='database') migration.do_alembic_command(self.alembic_config, 'upgrade', 'head') cfg.CONF.clear_override('connection', group='database')
def db_sync(self, engine): cfg.CONF.set_override('connection', engine.url, group='database') migration.do_alembic_command(self.alembic_config, 'upgrade', 'heads')