use get reader/writer session from neutron-lib

The get_reader_session and get_writer_session functions are available
in neutron-lib. This patch consumes them by removing the functions
from neutron and using lib's instead.

NeutronLibImpact

Change-Id: I4055172799a0d9a0ceb387b6d47e421e1c270ada
changes/03/570603/4
Boden R 4 years ago
parent 430d2afd25
commit 6fe35c8039
  1. 10
      neutron/db/api.py
  2. 13
      neutron/plugins/ml2/drivers/type_tunnel.py
  3. 3
      neutron/plugins/ml2/plugin.py
  4. 2
      neutron/tests/unit/extensions/test_l3_ext_gw_mode.py
  5. 2
      neutron/tests/unit/quota/test_resource.py
  6. 2
      neutron/tests/unit/services/metering/test_metering_plugin.py

@ -175,16 +175,6 @@ def _is_nested_instance(e, etypes):
return False
def get_reader_session():
"""Helper to get reader session"""
return context_manager.reader.get_sessionmaker()()
def get_writer_session():
"""Helper to get writer session"""
return context_manager.writer.get_sessionmaker()()
@contextlib.contextmanager
def autonested_transaction(sess):
"""This is a convenience method to not bother with 'nested' parameter."""

@ -20,6 +20,7 @@ import netaddr
from neutron_lib.agent import topics
from neutron_lib import constants as p_const
from neutron_lib import context
from neutron_lib.db import api as lib_db_api
from neutron_lib import exceptions as exc
from neutron_lib.plugins.ml2 import api
from neutron_lib.plugins import utils as plugin_utils
@ -348,37 +349,37 @@ class EndpointTunnelTypeDriver(ML2TunnelTypeDriver):
def get_endpoint_by_host(self, host):
LOG.debug("get_endpoint_by_host() called for host %s", host)
session = db_api.get_reader_session()
session = lib_db_api.get_reader_session()
return (session.query(self.endpoint_model).
filter_by(host=host).first())
def get_endpoint_by_ip(self, ip):
LOG.debug("get_endpoint_by_ip() called for ip %s", ip)
session = db_api.get_reader_session()
session = lib_db_api.get_reader_session()
return (session.query(self.endpoint_model).
filter_by(ip_address=ip).first())
def delete_endpoint(self, ip):
LOG.debug("delete_endpoint() called for ip %s", ip)
session = db_api.get_writer_session()
session = lib_db_api.get_writer_session()
session.query(self.endpoint_model).filter_by(ip_address=ip).delete()
def delete_endpoint_by_host_or_ip(self, host, ip):
LOG.debug("delete_endpoint_by_host_or_ip() called for "
"host %(host)s or %(ip)s", {'host': host, 'ip': ip})
session = db_api.get_writer_session()
session = lib_db_api.get_writer_session()
session.query(self.endpoint_model).filter(
or_(self.endpoint_model.host == host,
self.endpoint_model.ip_address == ip)).delete()
def _get_endpoints(self):
LOG.debug("_get_endpoints() called")
session = db_api.get_reader_session()
session = lib_db_api.get_reader_session()
return session.query(self.endpoint_model)
def _add_endpoint(self, ip, host, **kwargs):
LOG.debug("_add_endpoint() called for ip %s", ip)
session = db_api.get_writer_session()
session = lib_db_api.get_writer_session()
try:
endpoint = self.endpoint_model(ip_address=ip, host=host, **kwargs)
endpoint.save(session)

@ -33,6 +33,7 @@ from neutron_lib.callbacks import exceptions
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import constants as const
from neutron_lib.db import api as lib_db_api
from neutron_lib.db import utils as db_utils
from neutron_lib import exceptions as exc
from neutron_lib.exceptions import allowedaddresspairs as addr_exc
@ -663,7 +664,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
def _object_session_or_new_session(sql_obj):
session = sqlalchemy.inspect(sql_obj).session
if not session:
session = db_api.get_reader_session()
session = lib_db_api.get_reader_session()
return session
def _notify_port_updated(self, mech_context):

@ -19,6 +19,7 @@ import netaddr
from neutron_lib.api.definitions import l3 as l3_apidef
from neutron_lib import constants
from neutron_lib import context as nctx
from neutron_lib.db import api as db_api
from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_db import exception as db_exc
@ -28,7 +29,6 @@ import testscenarios
from webob import exc
from neutron.common import utils
from neutron.db import api as db_api
from neutron.db import l3_db
from neutron.db import l3_gwmode_db
from neutron.db.models import l3 as l3_models

@ -14,13 +14,13 @@
import mock
from neutron_lib import context
from neutron_lib.db import api as db_api
from neutron_lib.plugins import constants
from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_utils import uuidutils
import testtools
from neutron.db import api as db_api
from neutron.db.quota import api as quota_api
from neutron.quota import resource
from neutron.tests import base

@ -15,13 +15,13 @@
import mock
from neutron_lib.api.definitions import metering as metering_apidef
from neutron_lib import context
from neutron_lib.db import api as db_api
from neutron_lib.plugins import constants
from neutron_lib.plugins import directory
from oslo_utils import uuidutils
from neutron.api.rpc.agentnotifiers import metering_rpc_agent_api
from neutron.common import utils
from neutron.db import api as db_api
from neutron.db.metering import metering_rpc
from neutron.extensions import l3 as ext_l3
from neutron.extensions import metering as ext_metering

Loading…
Cancel
Save