Only call get_engine().pool.dispose if _FACADE
Avoid calling neutron.db.api.get_engine().pool.dispose() if an engine facade has not yet been created since there won't be any connections to get rid of. Calling it on services that do not use the DB (e.g. agents) unnecessarily creates a database connection engine that will never be used. Change-Id: I3dbad1bef5da7b3765898e7d539b4d119b89e73a Closes-Bug: #1433536
This commit is contained in:
parent
9debd891ff
commit
34380df15b
@ -37,7 +37,5 @@ def main():
|
|||||||
config.init(sys.argv[1:])
|
config.init(sys.argv[1:])
|
||||||
config.setup_logging()
|
config.setup_logging()
|
||||||
utils.log_opt_values(LOG)
|
utils.log_opt_values(LOG)
|
||||||
# metadata agent need not connect DB
|
|
||||||
cfg.CONF.set_override("connection", "", "database")
|
|
||||||
proxy = agent.UnixDomainMetadataProxy(cfg.CONF)
|
proxy = agent.UnixDomainMetadataProxy(cfg.CONF)
|
||||||
proxy.run()
|
proxy.run()
|
||||||
|
@ -40,6 +40,12 @@ def get_engine():
|
|||||||
return facade.get_engine()
|
return facade.get_engine()
|
||||||
|
|
||||||
|
|
||||||
|
def dispose():
|
||||||
|
# Don't need to do anything if an enginefacade hasn't been created
|
||||||
|
if _FACADE is not None:
|
||||||
|
get_engine().pool.dispose()
|
||||||
|
|
||||||
|
|
||||||
def get_session(autocommit=True, expire_on_commit=False):
|
def get_session(autocommit=True, expire_on_commit=False):
|
||||||
"""Helper method to grab session."""
|
"""Helper method to grab session."""
|
||||||
facade = _create_facade_lazily()
|
facade = _create_facade_lazily()
|
||||||
|
@ -119,7 +119,7 @@ class RpcWorker(object):
|
|||||||
# We may have just forked from parent process. A quick disposal of the
|
# We may have just forked from parent process. A quick disposal of the
|
||||||
# existing sql connections avoids producing errors later when they are
|
# existing sql connections avoids producing errors later when they are
|
||||||
# discovered to be broken.
|
# discovered to be broken.
|
||||||
session.get_engine().pool.dispose()
|
session.dispose()
|
||||||
self._servers = self._plugin.start_rpc_listeners()
|
self._servers = self._plugin.start_rpc_listeners()
|
||||||
|
|
||||||
def wait(self):
|
def wait(self):
|
||||||
|
@ -587,8 +587,6 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
|
|||||||
mock.call(cfg.CONF),
|
mock.call(cfg.CONF),
|
||||||
mock.call().run()]
|
mock.call().run()]
|
||||||
)
|
)
|
||||||
cfg.CONF.set_override.assert_called_once_with(
|
|
||||||
"connection", "", "database")
|
|
||||||
|
|
||||||
def test_init_state_reporting(self):
|
def test_init_state_reporting(self):
|
||||||
with mock.patch('os.makedirs'):
|
with mock.patch('os.makedirs'):
|
||||||
|
@ -25,6 +25,7 @@ import webob
|
|||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
from neutron.common import exceptions as exception
|
from neutron.common import exceptions as exception
|
||||||
|
from neutron.db import api
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
from neutron import wsgi
|
from neutron import wsgi
|
||||||
|
|
||||||
@ -52,18 +53,17 @@ def open_no_proxy(*args, **kwargs):
|
|||||||
class TestWorkerService(base.BaseTestCase):
|
class TestWorkerService(base.BaseTestCase):
|
||||||
"""WorkerService tests."""
|
"""WorkerService tests."""
|
||||||
|
|
||||||
@mock.patch('neutron.db.api')
|
@mock.patch('neutron.db.api.get_engine')
|
||||||
def test_start_withoutdb_call(self, apimock):
|
def test_start_withoutdb_call(self, apimock):
|
||||||
|
# clear engine from other tests
|
||||||
|
api._FACADE = None
|
||||||
_service = mock.Mock()
|
_service = mock.Mock()
|
||||||
_service.pool = mock.Mock()
|
|
||||||
_service.pool.spawn = mock.Mock()
|
|
||||||
_service.pool.spawn.return_value = None
|
_service.pool.spawn.return_value = None
|
||||||
|
|
||||||
_app = mock.Mock()
|
_app = mock.Mock()
|
||||||
cfg.CONF.set_override("connection", "", "database")
|
|
||||||
workerservice = wsgi.WorkerService(_service, _app)
|
workerservice = wsgi.WorkerService(_service, _app)
|
||||||
workerservice.start()
|
workerservice.start()
|
||||||
self.assertFalse(apimock.get_engine.called)
|
self.assertFalse(apimock.called)
|
||||||
|
|
||||||
|
|
||||||
class TestWSGIServer(base.BaseTestCase):
|
class TestWSGIServer(base.BaseTestCase):
|
||||||
|
@ -101,8 +101,7 @@ class WorkerService(object):
|
|||||||
# We may have just forked from parent process. A quick disposal of the
|
# We may have just forked from parent process. A quick disposal of the
|
||||||
# existing sql connections avoids producing 500 errors later when they
|
# existing sql connections avoids producing 500 errors later when they
|
||||||
# are discovered to be broken.
|
# are discovered to be broken.
|
||||||
if CONF.database.connection:
|
api.dispose()
|
||||||
api.get_engine().pool.dispose()
|
|
||||||
self._server = self._service.pool.spawn(self._service._run,
|
self._server = self._service.pool.spawn(self._service._run,
|
||||||
self._application,
|
self._application,
|
||||||
self._service._socket)
|
self._service._socket)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user