Fixing a bug with multithreading support with the SQLite backend

This change fixes a bug that could occur when accessing the server
with multiple threads or processes. The SQLite backend by default
does not support multithreading. This change updates how the
SQLite backend is instantiated, preventing error generation when
using multiple clients simultaenously. The server unit test suite
has been updated to cover the change.
This commit is contained in:
Peter Hamilton 2016-12-17 14:57:38 -05:00
parent 3d3c162533
commit b1f73d811c
2 changed files with 16 additions and 1 deletions

View File

@ -98,7 +98,8 @@ class KmipEngine(object):
self._data_store = sqlalchemy.create_engine(
'sqlite:////tmp/pykmip.database',
echo=False
echo=False,
connect_args={'check_same_thread': False}
)
sqltypes.Base.metadata.create_all(self._data_store)
self._data_store_session_factory = sqlalchemy.orm.sessionmaker(

View File

@ -140,6 +140,20 @@ class TestKmipEngine(testtools.TestCase):
"""
engine.KmipEngine()
@mock.patch('sqlalchemy.create_engine')
def test_init_create_engine(self, create_engine_mock):
"""
Test that the right arguments are used to create the engine's SQLite
backend.
"""
engine.KmipEngine()
args = ("sqlite:////tmp/pykmip.database",)
fargs = {
'echo': False,
'connect_args': {'check_same_thread': False}
}
create_engine_mock.assert_called_once_with(*args, **fargs)
def test_load_operation_policies(self):
"""
Test that the KmipEngine can correctly load operation policies.