Python oslo_db.sqlalchemy.session.create_engine() Examples
The following are 22
code examples of oslo_db.sqlalchemy.session.create_engine().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_db.sqlalchemy.session
, or try the search function
.
Example #1
Source File: env.py From neutron-dynamic-routing with Apache License 2.0 | 6 votes |
def run_migrations_online(): set_mysql_engine() engine = session.create_engine(neutron_config.database.connection) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata, version_table=DR_VERSION_TABLE ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close() engine.dispose()
Example #2
Source File: env.py From networking-l2gw with Apache License 2.0 | 6 votes |
def run_migrations_online(): set_mysql_engine() engine = session.create_engine(neutron_config.database.connection) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata, include_object=include_object, version_table=L2GW_VERSION_TABLE ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close() engine.dispose()
Example #3
Source File: env.py From networking-odl with Apache License 2.0 | 6 votes |
def run_migrations_online(): set_mysql_engine() engine = session.create_engine(neutron_config.database.connection) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata, include_object=include_object, version_table=ODL_VERSION_TABLE ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close() engine.dispose()
Example #4
Source File: env.py From networking-midonet with Apache License 2.0 | 6 votes |
def run_migrations_online(): set_mysql_engine() engine = session.create_engine(neutron_config.database.connection) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata, include_object=include_object, version_table=MIDONET_VERSION_TABLE ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close() engine.dispose()
Example #5
Source File: env.py From networking-bgpvpn with Apache License 2.0 | 6 votes |
def run_migrations_online(): set_mysql_engine() engine = session.create_engine(neutron_config.database.connection) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata, version_table=BGPVPN_VERSION_TABLE ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close() engine.dispose()
Example #6
Source File: env.py From dragonflow with Apache License 2.0 | 6 votes |
def run_migrations_online(): set_mysql_engine() engine = session.create_engine(neutron_config.database.connection) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata, include_object=include_object, version_table=DF_VERSION_TABLE ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close() engine.dispose()
Example #7
Source File: env.py From barbican with Apache License 2.0 | 6 votes |
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ engine = session.create_engine( get_sqlalchemy_url()) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close()
Example #8
Source File: env.py From neutron-vpnaas with Apache License 2.0 | 6 votes |
def run_migrations_online(): set_mysql_engine() engine = session.create_engine(neutron_config.database.connection) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata, version_table=alembic_migrations.VPNAAS_VERSION_TABLE ) try: with context.begin_transaction(): context.run_migrations() finally: connection.close() engine.dispose()
Example #9
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 6 votes |
def test_combine_multi_params(self): with self._fixture() as ce: engines.create_engine( "mysql+pymysql://foo:bar@bat/" "?charset=utf8¶m_file=tripleo.cnf&plugin=connmon", connection_parameters="plugin=sqlalchemy_collectd&" "collectd_host=127.0.0.1&" "bind_host=192.168.1.5") self.assertEqual( ce.mock_calls[0][1][0].query, { 'bind_host': '192.168.1.5', 'charset': 'utf8', 'collectd_host': '127.0.0.1', 'param_file': 'tripleo.cnf', 'plugin': ['connmon', 'sqlalchemy_collectd'] } )
Example #10
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 6 votes |
def test_combine_params(self): with self._fixture() as ce: engines.create_engine( "mysql+pymysql://foo:bar@bat/" "?charset=utf8¶m_file=tripleo.cnf", connection_parameters="plugin=sqlalchemy_collectd&" "collectd_host=127.0.0.1&" "bind_host=192.168.1.5") self.assertEqual( ce.mock_calls[0][1][0].query, { 'bind_host': '192.168.1.5', 'charset': 'utf8', 'collectd_host': '127.0.0.1', 'param_file': 'tripleo.cnf', 'plugin': 'sqlalchemy_collectd' } )
Example #11
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 5 votes |
def test_fail_detect_mode(self): # If "SHOW VARIABLES LIKE 'sql_mode'" results in no row, then # we get a log indicating can't detect the mode. log = self.useFixture(fixtures.FakeLogger(level=logging.WARN)) mysql_conn = self.engine.raw_connection() self.addCleanup(mysql_conn.close) mysql_conn.detach() mysql_cursor = mysql_conn.cursor() def execute(statement, parameters=()): if "SHOW VARIABLES LIKE 'sql_mode'" in statement: statement = "SHOW VARIABLES LIKE 'i_dont_exist'" return mysql_cursor.execute(statement, parameters) test_engine = sqlalchemy.create_engine(self.engine.url, _initialize=False) with mock.patch.object( test_engine.pool, '_creator', mock.Mock( return_value=mock.Mock( cursor=mock.Mock( return_value=mock.Mock( execute=execute, fetchone=mysql_cursor.fetchone, fetchall=mysql_cursor.fetchall ) ) ) ) ): engines._init_events.dispatch_on_drivername("mysql")(test_engine) test_engine.raw_connection() self.assertIn('Unable to detect effective SQL mode', log.output)
Example #12
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 5 votes |
def test_set_mode_no_mode(self): # If _mysql_set_mode_callback is called with sql_mode=None, then # the SQL mode is NOT set on the connection. # get the GLOBAL sql_mode, not the @@SESSION, so that # we get what is configured for the MySQL database, as opposed # to what our own session.create_engine() has set it to. expected = self.engine.execute( "SELECT @@GLOBAL.sql_mode").scalar() engine = self._fixture(sql_mode=None) self._assert_sql_mode(engine, expected, None)
Example #13
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 5 votes |
def _fixture(self, sql_mode): return session.create_engine(self.engine.url, mysql_sql_mode=sql_mode)
Example #14
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 5 votes |
def _fixture(self, **kw): return session.create_engine("sqlite://", **kw)
Example #15
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 5 votes |
def test_creation_from_config(self, create_engine, get_maker): conf = cfg.ConfigOpts() conf.register_opts(db_options.database_opts, group='database') overrides = { 'connection': 'sqlite:///:memory:', 'slave_connection': None, 'connection_debug': 100, 'max_pool_size': 10, 'mysql_sql_mode': 'TRADITIONAL', } for optname, optvalue in overrides.items(): conf.set_override(optname, optvalue, group='database') session.EngineFacade.from_config(conf, autocommit=False, expire_on_commit=True) create_engine.assert_called_once_with( sql_connection='sqlite:///:memory:', connection_debug=100, max_pool_size=10, mysql_sql_mode='TRADITIONAL', mysql_enable_ndb=False, sqlite_fk=False, connection_recycle_time=mock.ANY, retry_interval=mock.ANY, max_retries=mock.ANY, max_overflow=mock.ANY, connection_trace=mock.ANY, sqlite_synchronous=mock.ANY, pool_timeout=mock.ANY, thread_checkin=mock.ANY, json_serializer=None, json_deserializer=None, connection_parameters='', logging_name=mock.ANY, ) get_maker.assert_called_once_with(engine=create_engine(), autocommit=False, expire_on_commit=True)
Example #16
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 5 votes |
def test_add_no_params(self): with self._fixture() as ce: engines.create_engine( "mysql+pymysql://foo:bar@bat") self.assertEqual( ce.mock_calls[0][1][0].query, {} )
Example #17
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 5 votes |
def test_add_assorted_params(self): with self._fixture() as ce: engines.create_engine( "mysql+pymysql://foo:bar@bat", connection_parameters="foo=bar&bat=hoho&bat=param2") self.assertEqual( ce.mock_calls[0][1][0].query, {'bat': ['hoho', 'param2'], 'foo': 'bar'} )
Example #18
Source File: test_sqlalchemy.py From oslo.db with Apache License 2.0 | 5 votes |
def _fixture(self): from sqlalchemy import create_engine def _mock_create_engine(*arg, **kw): return create_engine("sqlite://") return mock.patch( "oslo_db.sqlalchemy.engines.sqlalchemy.create_engine", side_effect=_mock_create_engine)
Example #19
Source File: pkcs11_migrate_kek_signatures.py From barbican with Apache License 2.0 | 5 votes |
def __init__(self, db_connection, library_path, login, slot_id): self.dry_run = False self.db_engine = session.create_engine(db_connection) self._session_creator = scoping.scoped_session( orm.sessionmaker( bind=self.db_engine, autocommit=True ) ) self.crypto_plugin = p11_crypto.P11CryptoPlugin(CONF) self.plugin_name = utils.generate_fullname_for(self.crypto_plugin) self.pkcs11 = self.crypto_plugin.pkcs11 self.session = self.pkcs11.get_session()
Example #20
Source File: test_db_manage.py From barbican with Apache License 2.0 | 5 votes |
def setUp(self): super(DBManageTestCase, self).setUp() self.sbehaviors = secret_behaviors.SecretBehaviors(self.client) self.cbehaviors = container_behaviors.ContainerBehaviors(self.client) db_url = BCONF.sql_connection time.sleep(5) # Setup session for tests to query DB engine = session.create_engine(db_url) self.conn = engine.connect()
Example #21
Source File: fixture.py From barbican with Apache License 2.0 | 5 votes |
def _setUp(self): self._engine = session.create_engine('sqlite:///:memory:') self.Session = sa.orm.sessionmaker(bind=self._engine) self.external_id = 'EXTERNAL_ID' models.BASE.metadata.create_all(self._engine) self._load_sample_data()
Example #22
Source File: repositories.py From barbican with Apache License 2.0 | 5 votes |
def _create_engine(connection, **engine_args): LOG.debug('Sql connection: please check "sql_connection" property in ' 'barbican configuration file; Args: %s', engine_args) engine = session.create_engine(connection, **engine_args) # TODO(jfwood): if 'mysql' in connection_dict.drivername: # TODO(jfwood): sqlalchemy.event.listen(_ENGINE, 'checkout', # TODO(jfwood): ping_listener) # Wrap the engine's connect method with a retry decorator. engine.connect = wrap_db_error(engine.connect) return engine