Merge "Only call get_engine().pool.dispose if _FACADE"

This commit is contained in:
Jenkins 2015-04-21 16:43:54 +00:00 committed by Gerrit Code Review
commit a2d75740dc
6 changed files with 13 additions and 12 deletions

View File

@ -37,7 +37,5 @@ def main():
config.init(sys.argv[1:])
config.setup_logging()
utils.log_opt_values(LOG)
# metadata agent need not connect DB
cfg.CONF.set_override("connection", "", "database")
proxy = agent.UnixDomainMetadataProxy(cfg.CONF)
proxy.run()

View File

@ -40,6 +40,12 @@ def 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):
"""Helper method to grab session."""
facade = _create_facade_lazily()

View File

@ -119,7 +119,7 @@ class RpcWorker(object):
# We may have just forked from parent process. A quick disposal of the
# existing sql connections avoids producing errors later when they are
# discovered to be broken.
session.get_engine().pool.dispose()
session.dispose()
self._servers = self._plugin.start_rpc_listeners()
def wait(self):

View File

@ -587,8 +587,6 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
mock.call(cfg.CONF),
mock.call().run()]
)
cfg.CONF.set_override.assert_called_once_with(
"connection", "", "database")
def test_init_state_reporting(self):
with mock.patch('os.makedirs'):

View File

@ -25,6 +25,7 @@ import webob
import webob.exc
from neutron.common import exceptions as exception
from neutron.db import api
from neutron.tests import base
from neutron import wsgi
@ -52,18 +53,17 @@ def open_no_proxy(*args, **kwargs):
class TestWorkerService(base.BaseTestCase):
"""WorkerService tests."""
@mock.patch('neutron.db.api')
@mock.patch('neutron.db.api.get_engine')
def test_start_withoutdb_call(self, apimock):
# clear engine from other tests
api._FACADE = None
_service = mock.Mock()
_service.pool = mock.Mock()
_service.pool.spawn = mock.Mock()
_service.pool.spawn.return_value = None
_app = mock.Mock()
cfg.CONF.set_override("connection", "", "database")
workerservice = wsgi.WorkerService(_service, _app)
workerservice.start()
self.assertFalse(apimock.get_engine.called)
self.assertFalse(apimock.called)
class TestWSGIServer(base.BaseTestCase):

View File

@ -101,8 +101,7 @@ class WorkerService(object):
# We may have just forked from parent process. A quick disposal of the
# existing sql connections avoids producing 500 errors later when they
# are discovered to be broken.
if CONF.database.connection:
api.get_engine().pool.dispose()
api.dispose()
self._server = self._service.pool.spawn(self._service._run,
self._application,
self._service._socket)