Python oslo_db.sqlalchemy.session.EngineFacade() Examples

The following are 13 code examples of oslo_db.sqlalchemy.session.EngineFacade(). 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: base.py    From snippet with MIT License 6 votes vote down vote up
def _create_facade(conf_group):
    # This fragment is copied from oslo.db
    return db_session.EngineFacade(
        sql_connection=conf_group.connection,
        slave_connection=conf_group.slave_connection,
        sqlite_fk=False,
        autocommit=True,
        expire_on_commit=False,
        mysql_sql_mode=conf_group.mysql_sql_mode,
        idle_timeout=conf_group.idle_timeout,
        connection_debug=conf_group.connection_debug,
        max_pool_size=conf_group.max_pool_size,
        max_overflow=conf_group.max_overflow,
        pool_timeout=conf_group.pool_timeout,
        sqlite_synchronous=conf_group.sqlite_synchronous,
        connection_trace=conf_group.connection_trace,
        max_retries=conf_group.max_retries,
        retry_interval=conf_group.retry_interval) 
Example #2
Source File: impl_sqlalchemy.py    From vitrage with Apache License 2.0 6 votes vote down vote up
def __init__(self, url):
        options = dict(CONF.database.items())
        # set retries to 0 , since reconnection is already implemented
        # in storage.__init__.get_connection_from_config function
        options['max_retries'] = 0
        # add vitrage opts to database group
        for opt in storage.OPTS:
            options.pop(opt.name, None)
        self._engine_facade = db_session.EngineFacade(self._dress_url(url),
                                                      **options)
        self._active_actions = ActiveActionsConnection(self._engine_facade)
        self._events = EventsConnection(self._engine_facade)
        self._templates = TemplatesConnection(self._engine_facade)
        self._graph_snapshots = GraphSnapshotsConnection(self._engine_facade)
        self._webhooks = WebhooksConnection(
            self._engine_facade)
        self._alarms = AlarmsConnection(
            self._engine_facade)
        self._edges = EdgesConnection(
            self._engine_facade)
        self._changes = ChangesConnection(
            self._engine_facade)
        self._history_facade = HistoryFacadeConnection(
            self._engine_facade, self._alarms, self._edges, self._changes) 
Example #3
Source File: test_sqlalchemy.py    From oslo.db with Apache License 2.0 6 votes vote down vote up
def test_slave_connection(self):
        paths = self.create_tempfiles([('db.master', ''), ('db.slave', '')],
                                      ext='')
        master_path = 'sqlite:///' + paths[0]
        slave_path = 'sqlite:///' + paths[1]

        facade = session.EngineFacade(
            sql_connection=master_path,
            slave_connection=slave_path
        )

        master = facade.get_engine()
        self.assertEqual(master_path, str(master.url))
        slave = facade.get_engine(use_slave=True)
        self.assertEqual(slave_path, str(slave.url))

        master_session = facade.get_session()
        self.assertEqual(master_path, str(master_session.bind.url))
        slave_session = facade.get_session(use_slave=True)
        self.assertEqual(slave_path, str(slave_session.bind.url)) 
Example #4
Source File: impl_sqlalchemy.py    From aodh with Apache License 2.0 6 votes vote down vote up
def __init__(self, conf, url):
        # Set max_retries to 0, since oslo.db in certain cases may attempt
        # to retry making the db connection retried max_retries ^ 2 times
        # in failure case and db reconnection has already been implemented
        # in storage.__init__.get_connection_from_config function
        options = dict(conf.database.items())
        options['max_retries'] = 0
        # oslo.db doesn't support options defined by Aodh
        for opt in storage.OPTS:
            options.pop(opt.name, None)
        self._engine_facade = db_session.EngineFacade(self.dress_url(url),
                                                      **options)

        if osprofiler_sqlalchemy:
            osprofiler_sqlalchemy.add_tracing(sqlalchemy,
                                              self._engine_facade.get_engine(),
                                              'db')
        self.conf = conf 
Example #5
Source File: session.py    From designate with Apache License 2.0 5 votes vote down vote up
def _create_facade_lazily(cfg_group, connection=None, discriminator=None):
    connection = connection or cfg.CONF[cfg_group].connection
    cache_name = "%s:%s" % (cfg_group, discriminator)

    if cache_name not in _FACADES:
        conf = dict(cfg.CONF[cfg_group].items())
        _FACADES[cache_name] = session.EngineFacade(
            connection,
            **conf
        )

    return _FACADES[cache_name] 
Example #6
Source File: api.py    From vdi-broker with Apache License 2.0 5 votes vote down vote up
def get_facade():
    global _facade
    if not _facade:
        # TODO: investigate why the CONF.database.connection is None!
        # _facade = db_session.EngineFacade(CONF.database.connection)
        # _facade = db_session.EngineFacade.from_config(CONF)
        _facade = db_session.EngineFacade(
            "mysql://vdibroker:Passw0rd@localhost/vdibroker")
    return _facade 
Example #7
Source File: api.py    From JmilkFan-s-Blog with Apache License 2.0 5 votes vote down vote up
def _create_facade_lazily():
    global _FACADE
    if _FACADE is None:
        _FACADE = db_session.EngineFacade(
            CONF.database.connection,
            **dict(CONF.database))
    return _FACADE 
Example #8
Source File: test_sqlalchemy.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(EngineFacadeTestCase, self).setUp()

        self.facade = session.EngineFacade('sqlite://') 
Example #9
Source File: test_sqlalchemy.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
def test_direct_invocation_deprecated_args(self):
        facade = session.EngineFacade("sqlite://", idle_timeout=59)
        self.assertEqual(59, facade.get_engine().pool._recycle) 
Example #10
Source File: test_sqlalchemy.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: test_sqlalchemy.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
def test_slave_connection_string_not_provided(self):
        master_path = 'sqlite:///' + self.create_tempfiles(
            [('db.master', '')], ext='')[0]

        facade = session.EngineFacade(sql_connection=master_path)

        master = facade.get_engine()
        slave = facade.get_engine(use_slave=True)
        self.assertIs(master, slave)
        self.assertEqual(master_path, str(master.url))

        master_session = facade.get_session()
        self.assertEqual(master_path, str(master_session.bind.url))
        slave_session = facade.get_session(use_slave=True)
        self.assertEqual(master_path, str(slave_session.bind.url)) 
Example #12
Source File: api.py    From coriolis with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_facade():
    global _facade
    if not _facade:
        _facade = db_session.EngineFacade(CONF.database.connection)
    return _facade 
Example #13
Source File: api.py    From karbor with Apache License 2.0 5 votes vote down vote up
def _create_facade_lazily():
    global _LOCK
    with _LOCK:
        global _FACADE
        if _FACADE is None:
            _FACADE = db_session.EngineFacade(
                CONF.database.connection,
                **dict(CONF.database)
            )

        return _FACADE