当前位置: 首页>>代码示例>>Python>>正文


Python enginefacade.transaction_context方法代码示例

本文整理汇总了Python中oslo_db.sqlalchemy.enginefacade.transaction_context方法的典型用法代码示例。如果您正苦于以下问题:Python enginefacade.transaction_context方法的具体用法?Python enginefacade.transaction_context怎么用?Python enginefacade.transaction_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_db.sqlalchemy.enginefacade的用法示例。


在下文中一共展示了enginefacade.transaction_context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_enginefacade

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def get_enginefacade(self):
        """Return an enginefacade._TransactionContextManager.

        This is typically a global variable like "context_manager" declared
        in the db/api.py module and is the object returned by
        enginefacade.transaction_context().

        If left not implemented, the global enginefacade manager is used.

        For the case where a project uses per-object or per-test enginefacades
        like Gnocchi, the get_per_test_enginefacade()
        method should also be implemented.


        """
        return enginefacade._context_manager 
开发者ID:openstack,项目名称:oslo.db,代码行数:18,代码来源:test_fixtures.py

示例2: test_dispose_pool

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_dispose_pool(self):
        facade = enginefacade.transaction_context()

        facade.configure(
            connection=self.engine_uri,
            )

        facade.dispose_pool()
        self.assertFalse(hasattr(facade._factory, '_writer_engine'))

        facade._factory._start()
        facade.dispose_pool()

        self.assertEqual(
            facade._factory._writer_engine.pool.mock_calls,
            [mock.call.dispose()]
        ) 
开发者ID:openstack,项目名称:oslo.db,代码行数:19,代码来源:test_enginefacade.py

示例3: test_dispose_pool_w_reader

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_dispose_pool_w_reader(self):
        facade = enginefacade.transaction_context()

        facade.configure(
            connection=self.engine_uri,
            slave_connection=self.slave_uri
        )

        facade.dispose_pool()
        self.assertFalse(hasattr(facade._factory, '_writer_engine'))
        self.assertFalse(hasattr(facade._factory, '_reader_engine'))

        facade._factory._start()
        facade.dispose_pool()

        self.assertEqual(
            facade._factory._writer_engine.pool.mock_calls,
            [mock.call.dispose()]
        )
        self.assertEqual(
            facade._factory._reader_engine.pool.mock_calls,
            [mock.call.dispose()]
        ) 
开发者ID:openstack,项目名称:oslo.db,代码行数:25,代码来源:test_enginefacade.py

示例4: test_setup_for_connection_called_with_profiler

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_setup_for_connection_called_with_profiler(self):
        context_manager = enginefacade.transaction_context()
        context_manager.configure(connection='sqlite://')
        hook = mock.Mock()
        context_manager.append_on_engine_create(hook)
        self.assertEqual(
            [hook], context_manager._factory._facade_cfg['on_engine_create'])

        @context_manager.reader
        def go(context):
            hook.assert_called_once_with(context.session.bind)

        go(oslo_context.RequestContext())

# TODO(zzzeek): test configuration options, e.g. like
# test_sqlalchemy->test_creation_from_config 
开发者ID:openstack,项目名称:oslo.db,代码行数:18,代码来源:test_enginefacade.py

示例5: __init__

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def __init__(self, conf):
        self.trans = enginefacade.transaction_context()
        self.trans.configure(
            **dict(conf.database.items())
        )
        self._context = threading.local() 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:8,代码来源:sqlalchemy.py

示例6: create_context_manager

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def create_context_manager(connection=None):
    """Create a database context manager object.
    : param connection: The database connection string
    """
    ctxt_mgr = enginefacade.transaction_context()
    ctxt_mgr.configure(**_get_db_conf(CONF.database, connection=connection))
    return ctxt_mgr 
开发者ID:openstack,项目名称:freezer-api,代码行数:9,代码来源:api.py

示例7: create_context_manager

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def create_context_manager(connection=None):
    """Create a database context manager object.

    : param connection: The database connection string
    """
    ctxt_mgr = enginefacade.transaction_context()
    ctxt_mgr.configure(**_get_db_conf(CONF.database, connection=connection))
    return ctxt_mgr 
开发者ID:openstack,项目名称:masakari,代码行数:10,代码来源:api.py

示例8: test_db_fixture

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_db_fixture(self):
        normal_mgr = enginefacade.transaction_context()
        normal_mgr.configure(
            connection="sqlite://",
            sqlite_fk=True,
            mysql_sql_mode="FOOBAR",
            max_overflow=38
        )

        class MyFixture(test_fixtures.OpportunisticDbFixture):
            def get_enginefacade(self):
                return normal_mgr

        test = mock.Mock(SCHEMA_SCOPE=None)
        fixture = MyFixture(test=test)
        resources = fixture._get_resources()

        testresources.setUpResources(test, resources, None)
        self.addCleanup(
            testresources.tearDownResources,
            test, resources, None
        )
        fixture.setUp()
        self.addCleanup(fixture.cleanUp)

        self.assertTrue(normal_mgr._factory._started)

        test.engine = normal_mgr.writer.get_engine()
        self.assertEqual("sqlite://", str(test.engine.url))
        self.assertIs(test.engine, normal_mgr._factory._writer_engine)
        engine_args = normal_mgr._factory._engine_args_for_conf(None)
        self.assertTrue(engine_args['sqlite_fk'])
        self.assertEqual("FOOBAR", engine_args["mysql_sql_mode"])
        self.assertEqual(38, engine_args["max_overflow"])

        fixture.cleanUp()
        fixture._clear_cleanups()  # so the real cleanUp works
        self.assertFalse(normal_mgr._factory._started) 
开发者ID:openstack,项目名称:oslo.db,代码行数:40,代码来源:test_fixtures.py

示例9: test_started_flag

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_started_flag(self):
        facade = enginefacade.transaction_context()

        self.assertFalse(facade.is_started)
        facade.configure(connection=self.engine_uri)
        facade.writer.get_engine()

        self.assertTrue(facade.is_started) 
开发者ID:openstack,项目名称:oslo.db,代码行数:10,代码来源:test_enginefacade.py

示例10: test_multiple_factories

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_multiple_factories(self):
        """Test that the instrumentation applied to a context class is

        independent of a specific _TransactionContextManager
        / _TransactionFactory.

        """
        mgr1 = enginefacade.transaction_context()
        mgr1.configure(
            connection=self.engine_uri,
            slave_connection=self.slave_uri
        )
        mgr2 = enginefacade.transaction_context()
        mgr2.configure(
            connection=self.engine_uri,
            slave_connection=self.slave_uri
        )

        context = oslo_context.RequestContext()

        self.assertRaises(
            exception.NoEngineContextEstablished,
            getattr, context, 'session'
        )
        with mgr1.writer.using(context):
            self.assertIs(context.transaction_ctx.factory, mgr1._factory)
            self.assertIsNot(context.transaction_ctx.factory, mgr2._factory)
            self.assertIsNotNone(context.session)

        self.assertRaises(
            exception.NoEngineContextEstablished,
            getattr, context, 'session'
        )
        with mgr2.writer.using(context):
            self.assertIsNot(context.transaction_ctx.factory, mgr1._factory)
            self.assertIs(context.transaction_ctx.factory, mgr2._factory)
            self.assertIsNotNone(context.session) 
开发者ID:openstack,项目名称:oslo.db,代码行数:39,代码来源:test_enginefacade.py

示例11: test_multiple_factories_nested

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_multiple_factories_nested(self):
        """Test that the instrumentation applied to a context class supports

        nested calls among multiple _TransactionContextManager objects.

        """
        mgr1 = enginefacade.transaction_context()
        mgr1.configure(
            connection=self.engine_uri,
            slave_connection=self.slave_uri
        )
        mgr2 = enginefacade.transaction_context()
        mgr2.configure(
            connection=self.engine_uri,
            slave_connection=self.slave_uri
        )

        context = oslo_context.RequestContext()

        with mgr1.writer.using(context):
            self.assertIs(context.transaction_ctx.factory, mgr1._factory)
            self.assertIsNot(context.transaction_ctx.factory, mgr2._factory)

            with mgr2.writer.using(context):
                self.assertIsNot(
                    context.transaction_ctx.factory, mgr1._factory)
                self.assertIs(context.transaction_ctx.factory, mgr2._factory)
                self.assertIsNotNone(context.session)

            # mgr1 is restored
            self.assertIs(context.transaction_ctx.factory, mgr1._factory)
            self.assertIsNot(context.transaction_ctx.factory, mgr2._factory)
            self.assertIsNotNone(context.session)

        self.assertRaises(
            exception.NoEngineContextEstablished,
            getattr, context, 'transaction_ctx'
        ) 
开发者ID:openstack,项目名称:oslo.db,代码行数:40,代码来源:test_enginefacade.py

示例12: test_patch_manager

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_patch_manager(self):
        normal_mgr = enginefacade.transaction_context()
        normal_mgr.configure(connection="sqlite:///foo.db")
        alt_mgr = enginefacade.transaction_context()
        alt_mgr.configure(connection="sqlite:///bar.db")

        @normal_mgr.writer
        def go1(context):
            s1 = context.session
            self.assertEqual(
                s1.bind.url, "sqlite:///foo.db")
            self.assertIs(
                s1.bind,
                normal_mgr._factory._writer_engine)

        @normal_mgr.writer
        def go2(context):
            s1 = context.session

            self.assertEqual(
                s1.bind.url,
                "sqlite:///bar.db")

            self.assertIs(
                normal_mgr._factory._writer_engine,
                alt_mgr._factory._writer_engine
            )

        def create_engine(sql_connection, **kw):
            return mock.Mock(url=sql_connection)

        with mock.patch(
                "oslo_db.sqlalchemy.engines.create_engine", create_engine):
            context = oslo_context.RequestContext()
            go1(context)
            reset = normal_mgr.patch_factory(alt_mgr)
            go2(context)
            reset()
            go1(context) 
开发者ID:openstack,项目名称:oslo.db,代码行数:41,代码来源:test_enginefacade.py

示例13: test_patch_factory

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_patch_factory(self):
        normal_mgr = enginefacade.transaction_context()
        normal_mgr.configure(connection="sqlite:///foo.db")
        alt_mgr = enginefacade.transaction_context()
        alt_mgr.configure(connection="sqlite:///bar.db")

        @normal_mgr.writer
        def go1(context):
            s1 = context.session
            self.assertEqual(
                s1.bind.url, "sqlite:///foo.db")
            self.assertIs(
                s1.bind,
                normal_mgr._factory._writer_engine)

        @normal_mgr.writer
        def go2(context):
            s1 = context.session

            self.assertEqual(
                s1.bind.url,
                "sqlite:///bar.db")

            self.assertIs(
                normal_mgr._factory._writer_engine,
                alt_mgr._factory._writer_engine
            )

        def create_engine(sql_connection, **kw):
            return mock.Mock(url=sql_connection)

        with mock.patch(
                "oslo_db.sqlalchemy.engines.create_engine", create_engine):
            context = oslo_context.RequestContext()
            go1(context)
            reset = normal_mgr.patch_factory(alt_mgr._factory)
            go2(context)
            reset()
            go1(context) 
开发者ID:openstack,项目名称:oslo.db,代码行数:41,代码来源:test_enginefacade.py

示例14: test_new_manager_from_config

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_new_manager_from_config(self):
        normal_mgr = enginefacade.transaction_context()
        normal_mgr.configure(
            connection="sqlite://",
            sqlite_fk=True,
            mysql_sql_mode="FOOBAR",
            max_overflow=38
        )

        normal_mgr._factory._start()

        copied_mgr = normal_mgr.make_new_manager()

        self.assertTrue(normal_mgr._factory._started)
        self.assertIsNotNone(normal_mgr._factory._writer_engine)

        self.assertIsNot(copied_mgr._factory, normal_mgr._factory)
        self.assertFalse(copied_mgr._factory._started)
        copied_mgr._factory._start()
        self.assertIsNot(
            normal_mgr._factory._writer_engine,
            copied_mgr._factory._writer_engine)

        engine_args = copied_mgr._factory._engine_args_for_conf(None)
        self.assertTrue(engine_args['sqlite_fk'])
        self.assertEqual("FOOBAR", engine_args["mysql_sql_mode"])
        self.assertEqual(38, engine_args["max_overflow"]) 
开发者ID:openstack,项目名称:oslo.db,代码行数:29,代码来源:test_enginefacade.py

示例15: test_legacy_facades_from_different_context_managers

# 需要导入模块: from oslo_db.sqlalchemy import enginefacade [as 别名]
# 或者: from oslo_db.sqlalchemy.enginefacade import transaction_context [as 别名]
def test_legacy_facades_from_different_context_managers(self):
        transaction_context1 = enginefacade.transaction_context()
        transaction_context2 = enginefacade.transaction_context()

        transaction_context1.configure(connection='sqlite:///?conn1')
        transaction_context2.configure(connection='sqlite:///?conn2')

        legacy1 = transaction_context1.get_legacy_facade()
        legacy2 = transaction_context2.get_legacy_facade()

        self.assertNotEqual(legacy1, legacy2) 
开发者ID:openstack,项目名称:oslo.db,代码行数:13,代码来源:test_enginefacade.py


注:本文中的oslo_db.sqlalchemy.enginefacade.transaction_context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。