summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Nikitin <snikitin@mirantis.com>2015-11-11 11:45:49 +0300
committerSergey Nikitin <snikitin@mirantis.com>2015-11-11 12:18:28 +0300
commit7cc914fc1d7cb63439361b8323bafb3ba8fcd61c (patch)
tree57863738532a96f010baf60096f9ffa98f626259
parentdcbf7b81a889a86d62d36b61dd7035ac91ce5822 (diff)
downloadoslo-db-7cc914fc1d7cb63439361b8323bafb3ba8fcd61c.tar.gz
Added method get_legacy_facade() to the _TransactionContextManager
This public method was added to be able to create several legacy facades from several transaction context managers. It could be used in Nova where we have two DBs. There we need some legal way to create two legacy facades because right now in Nova we create facades by using private field _factory. It is not quite right. Change-Id: I96b3dbcbc5a05ac025c247ae6d8abfc988d0295e
-rw-r--r--oslo_db/sqlalchemy/enginefacade.py13
-rw-r--r--oslo_db/tests/sqlalchemy/test_enginefacade.py12
2 files changed, 24 insertions, 1 deletions
diff --git a/oslo_db/sqlalchemy/enginefacade.py b/oslo_db/sqlalchemy/enginefacade.py
index 0985ea8..111f033 100644
--- a/oslo_db/sqlalchemy/enginefacade.py
+++ b/oslo_db/sqlalchemy/enginefacade.py
@@ -622,6 +622,17 @@ class _TransactionContextManager(object):
"""
self._factory.configure(**kw)
+ def get_legacy_facade(self):
+ """Return a :class:`.LegacyEngineFacade` for factory from this context.
+
+ This facade will make use of the same engine and sessionmaker
+ as this factory, however will not share the same transaction context;
+ the legacy facade continues to work the old way of returning
+ a new Session each time get_session() is called.
+ """
+
+ return self._factory.get_legacy_facade()
+
@property
def replace(self):
"""Modifier to replace the global transaction factory with this one."""
@@ -827,7 +838,7 @@ def get_legacy_facade():
a new Session each time get_session() is called.
"""
- return _context_manager._factory.get_legacy_facade()
+ return _context_manager.get_legacy_facade()
reader = _context_manager.reader
diff --git a/oslo_db/tests/sqlalchemy/test_enginefacade.py b/oslo_db/tests/sqlalchemy/test_enginefacade.py
index 4a2517e..62e3fa9 100644
--- a/oslo_db/tests/sqlalchemy/test_enginefacade.py
+++ b/oslo_db/tests/sqlalchemy/test_enginefacade.py
@@ -985,6 +985,18 @@ class LegacyIntegrationtest(test_base.DbTestCase):
enginefacade._context_manager._factory._writer_maker
)
+ 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)
+
class ThreadingTest(test_base.DbTestCase):
"""Test copy/pickle on new threads using real connections and sessions."""