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
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()
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()
# 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):
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'):
import webob.exc
from neutron.common import exceptions as exception
+from neutron.db import api
from neutron.tests import base
from neutron import wsgi
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):
# 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)