From 61d0082f9ae9f9a935b5c3517c0b9036c40dbb00 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Tue, 4 Apr 2017 00:39:00 -0700 Subject: [PATCH] Fix SQL fixture to preserve engine facade settings This adjusts the SqlFixture class to preserve the settings we configure on the enginefacade transaction factory and to actually pass our enginefacade into to the test DatabaseResource we create. This is necessary for unit tests to be able to use configuration options we set on the enginefacade like the flush_on_subtransaction flag added in I71e274d0f0199896f28daae6db71241d9b43a2f3. Related-Bug: #1664643 Partially-Implements: blueprint enginefacade-switch Change-Id: Idabc7b6b4174575c89c8010886c2b440de6a8e05 --- neutron/tests/unit/testlib_api.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/neutron/tests/unit/testlib_api.py b/neutron/tests/unit/testlib_api.py index a49124fb475..7815a62c9da 100644 --- a/neutron/tests/unit/testlib_api.py +++ b/neutron/tests/unit/testlib_api.py @@ -99,11 +99,12 @@ class SqlFixture(fixtures.Fixture): self.sessionmaker = session.get_maker(engine) - self.enginefacade_factory = enginefacade._TestTransactionFactory( - self.engine, self.sessionmaker, apply_global=False) - _restore_factory = db_api.context_manager._root_factory + self.enginefacade_factory = enginefacade._TestTransactionFactory( + self.engine, self.sessionmaker, from_factory=_restore_factory, + apply_global=False) + db_api.context_manager._root_factory = self.enginefacade_factory engine = db_api.context_manager.writer.get_engine() @@ -160,7 +161,7 @@ class StaticSqlFixture(SqlFixture): else: cls._GLOBAL_RESOURCES = True cls.schema_resource = provision.SchemaResource( - provision.DatabaseResource("sqlite"), + provision.DatabaseResource("sqlite", db_api.context_manager), cls._generate_schema, teardown=False) dependency_resources = {} for name, resource in cls.schema_resource.resources: @@ -183,7 +184,8 @@ class StaticSqlFixtureNoSchema(SqlFixture): return else: cls._GLOBAL_RESOURCES = True - cls.database_resource = provision.DatabaseResource("sqlite") + cls.database_resource = provision.DatabaseResource( + "sqlite", db_api.context_manager) dependency_resources = {} for name, resource in cls.database_resource.resources: dependency_resources[name] = resource.getResource()