Get rid of get_engine() in db/api.py

get_engine() can be called directly with
context_manager.get_legacy_facade().get_engine()

Related-bug: #1520719

Change-Id: Id38c06aee428200a061c59a984b59b81b24056e3
This commit is contained in:
AKamyshnikova 2016-07-08 20:33:04 +03:00 committed by Ann Kamyshnikova
parent ac69b228b0
commit d8d3c193b2
5 changed files with 6 additions and 9 deletions

View File

@ -16,6 +16,7 @@
import contextlib
from debtcollector import moves
from debtcollector import removals
from oslo_config import cfg
from oslo_db import api as oslo_db_api
from oslo_db import exception as db_exc
@ -95,8 +96,7 @@ def exc_to_retry(exceptions):
raise db_exc.RetryRequest(e)
#TODO(akamyshnikova): when all places in the code, which use sessions/
# connections will be updated, this won't be needed
@removals.remove(version='Newton', removal_version='Ocata')
def get_engine():
"""Helper method to grab engine."""
return context_manager.get_legacy_facade().get_engine()

View File

@ -6383,7 +6383,7 @@ class DbOperationBoundMixin(object):
def _event_incrementer(*args, **kwargs):
self._db_execute_count += 1
engine = db_api.get_engine()
engine = db_api.context_manager.get_legacy_facade().get_engine()
event.listen(engine, 'after_execute', _event_incrementer)
self.addCleanup(event.remove, engine, 'after_execute',
_event_incrementer)

View File

@ -461,7 +461,7 @@ class FlavorPluginTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
self.service_manager.add_provider_configuration(
provider.split(':')[0], provconf.ProviderConfiguration())
dbapi.get_engine()
dbapi.context_manager.get_legacy_facade().get_engine()
def _create_flavor(self, description=None):
flavor = {'flavor': {'name': 'GOLD',

View File

@ -940,7 +940,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
raise db_exc.DBDuplicateEntry()
listener = IPAllocationsGrenade()
engine = db_api.get_engine()
engine = db_api.context_manager.get_legacy_facade().get_engine()
event.listen(engine, 'before_cursor_execute', listener.execute)
event.listen(engine, 'commit', listener.commit)
self.addCleanup(event.remove, engine, 'before_cursor_execute',

View File

@ -26,7 +26,6 @@ import webob
import webob.exc
from neutron.common import exceptions as n_exc
from neutron.db import api
from neutron.tests import base
from neutron.tests.common import helpers
from neutron import wsgi
@ -67,10 +66,8 @@ class TestServiceBase(base.BaseTestCase):
class TestWorkerService(TestServiceBase):
"""WorkerService tests."""
@mock.patch('neutron.db.api.get_engine')
@mock.patch('neutron.db.api.context_manager.get_legacy_facade')
def test_start_withoutdb_call(self, apimock):
# clear engine from other tests
api._FACADE = None
_service = mock.Mock()
_service.pool.spawn.return_value = None