summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-07-11 23:00:50 +0000
committerGerrit Code Review <review@openstack.org>2018-07-11 23:00:50 +0000
commit300e93c70e9c8fe610e4c805ec6c1e0c4ea3017f (patch)
tree26b1f042d061038de0c9860e290c5d890691ca05
parent1c0090793faff72ed821b64d7d105ee15a9bca8f (diff)
parent6fe35c803934acafff8a6ead8abcdf246a801b6c (diff)
Merge "use get reader/writer session from neutron-lib"
-rw-r--r--neutron/db/api.py10
-rw-r--r--neutron/plugins/ml2/drivers/type_tunnel.py13
-rw-r--r--neutron/plugins/ml2/plugin.py3
-rw-r--r--neutron/tests/unit/extensions/test_l3_ext_gw_mode.py2
-rw-r--r--neutron/tests/unit/quota/test_resource.py2
-rw-r--r--neutron/tests/unit/services/metering/test_metering_plugin.py2
6 files changed, 12 insertions, 20 deletions
diff --git a/neutron/db/api.py b/neutron/db/api.py
index c05820e..43497b0 100644
--- a/neutron/db/api.py
+++ b/neutron/db/api.py
@@ -175,16 +175,6 @@ def _is_nested_instance(e, etypes):
175 return False 175 return False
176 176
177 177
178def get_reader_session():
179 """Helper to get reader session"""
180 return context_manager.reader.get_sessionmaker()()
181
182
183def get_writer_session():
184 """Helper to get writer session"""
185 return context_manager.writer.get_sessionmaker()()
186
187
188@contextlib.contextmanager 178@contextlib.contextmanager
189def autonested_transaction(sess): 179def autonested_transaction(sess):
190 """This is a convenience method to not bother with 'nested' parameter.""" 180 """This is a convenience method to not bother with 'nested' parameter."""
diff --git a/neutron/plugins/ml2/drivers/type_tunnel.py b/neutron/plugins/ml2/drivers/type_tunnel.py
index b8bd920..be9e9fd 100644
--- a/neutron/plugins/ml2/drivers/type_tunnel.py
+++ b/neutron/plugins/ml2/drivers/type_tunnel.py
@@ -20,6 +20,7 @@ import netaddr
20from neutron_lib.agent import topics 20from neutron_lib.agent import topics
21from neutron_lib import constants as p_const 21from neutron_lib import constants as p_const
22from neutron_lib import context 22from neutron_lib import context
23from neutron_lib.db import api as lib_db_api
23from neutron_lib import exceptions as exc 24from neutron_lib import exceptions as exc
24from neutron_lib.plugins.ml2 import api 25from neutron_lib.plugins.ml2 import api
25from neutron_lib.plugins import utils as plugin_utils 26from neutron_lib.plugins import utils as plugin_utils
@@ -348,37 +349,37 @@ class EndpointTunnelTypeDriver(ML2TunnelTypeDriver):
348 349
349 def get_endpoint_by_host(self, host): 350 def get_endpoint_by_host(self, host):
350 LOG.debug("get_endpoint_by_host() called for host %s", host) 351 LOG.debug("get_endpoint_by_host() called for host %s", host)
351 session = db_api.get_reader_session() 352 session = lib_db_api.get_reader_session()
352 return (session.query(self.endpoint_model). 353 return (session.query(self.endpoint_model).
353 filter_by(host=host).first()) 354 filter_by(host=host).first())
354 355
355 def get_endpoint_by_ip(self, ip): 356 def get_endpoint_by_ip(self, ip):
356 LOG.debug("get_endpoint_by_ip() called for ip %s", ip) 357 LOG.debug("get_endpoint_by_ip() called for ip %s", ip)
357 session = db_api.get_reader_session() 358 session = lib_db_api.get_reader_session()
358 return (session.query(self.endpoint_model). 359 return (session.query(self.endpoint_model).
359 filter_by(ip_address=ip).first()) 360 filter_by(ip_address=ip).first())
360 361
361 def delete_endpoint(self, ip): 362 def delete_endpoint(self, ip):
362 LOG.debug("delete_endpoint() called for ip %s", ip) 363 LOG.debug("delete_endpoint() called for ip %s", ip)
363 session = db_api.get_writer_session() 364 session = lib_db_api.get_writer_session()
364 session.query(self.endpoint_model).filter_by(ip_address=ip).delete() 365 session.query(self.endpoint_model).filter_by(ip_address=ip).delete()
365 366
366 def delete_endpoint_by_host_or_ip(self, host, ip): 367 def delete_endpoint_by_host_or_ip(self, host, ip):
367 LOG.debug("delete_endpoint_by_host_or_ip() called for " 368 LOG.debug("delete_endpoint_by_host_or_ip() called for "
368 "host %(host)s or %(ip)s", {'host': host, 'ip': ip}) 369 "host %(host)s or %(ip)s", {'host': host, 'ip': ip})
369 session = db_api.get_writer_session() 370 session = lib_db_api.get_writer_session()
370 session.query(self.endpoint_model).filter( 371 session.query(self.endpoint_model).filter(
371 or_(self.endpoint_model.host == host, 372 or_(self.endpoint_model.host == host,
372 self.endpoint_model.ip_address == ip)).delete() 373 self.endpoint_model.ip_address == ip)).delete()
373 374
374 def _get_endpoints(self): 375 def _get_endpoints(self):
375 LOG.debug("_get_endpoints() called") 376 LOG.debug("_get_endpoints() called")
376 session = db_api.get_reader_session() 377 session = lib_db_api.get_reader_session()
377 return session.query(self.endpoint_model) 378 return session.query(self.endpoint_model)
378 379
379 def _add_endpoint(self, ip, host, **kwargs): 380 def _add_endpoint(self, ip, host, **kwargs):
380 LOG.debug("_add_endpoint() called for ip %s", ip) 381 LOG.debug("_add_endpoint() called for ip %s", ip)
381 session = db_api.get_writer_session() 382 session = lib_db_api.get_writer_session()
382 try: 383 try:
383 endpoint = self.endpoint_model(ip_address=ip, host=host, **kwargs) 384 endpoint = self.endpoint_model(ip_address=ip, host=host, **kwargs)
384 endpoint.save(session) 385 endpoint.save(session)
diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py
index e1b407d..e3c5054 100644
--- a/neutron/plugins/ml2/plugin.py
+++ b/neutron/plugins/ml2/plugin.py
@@ -33,6 +33,7 @@ from neutron_lib.callbacks import exceptions
33from neutron_lib.callbacks import registry 33from neutron_lib.callbacks import registry
34from neutron_lib.callbacks import resources 34from neutron_lib.callbacks import resources
35from neutron_lib import constants as const 35from neutron_lib import constants as const
36from neutron_lib.db import api as lib_db_api
36from neutron_lib.db import utils as db_utils 37from neutron_lib.db import utils as db_utils
37from neutron_lib import exceptions as exc 38from neutron_lib import exceptions as exc
38from neutron_lib.exceptions import allowedaddresspairs as addr_exc 39from neutron_lib.exceptions import allowedaddresspairs as addr_exc
@@ -663,7 +664,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
663 def _object_session_or_new_session(sql_obj): 664 def _object_session_or_new_session(sql_obj):
664 session = sqlalchemy.inspect(sql_obj).session 665 session = sqlalchemy.inspect(sql_obj).session
665 if not session: 666 if not session:
666 session = db_api.get_reader_session() 667 session = lib_db_api.get_reader_session()
667 return session 668 return session
668 669
669 def _notify_port_updated(self, mech_context): 670 def _notify_port_updated(self, mech_context):
diff --git a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py
index 8503c53..1c2c4a5 100644
--- a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py
+++ b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py
@@ -19,6 +19,7 @@ import netaddr
19from neutron_lib.api.definitions import l3 as l3_apidef 19from neutron_lib.api.definitions import l3 as l3_apidef
20from neutron_lib import constants 20from neutron_lib import constants
21from neutron_lib import context as nctx 21from neutron_lib import context as nctx
22from neutron_lib.db import api as db_api
22from neutron_lib.plugins import directory 23from neutron_lib.plugins import directory
23from oslo_config import cfg 24from oslo_config import cfg
24from oslo_db import exception as db_exc 25from oslo_db import exception as db_exc
@@ -28,7 +29,6 @@ import testscenarios
28from webob import exc 29from webob import exc
29 30
30from neutron.common import utils 31from neutron.common import utils
31from neutron.db import api as db_api
32from neutron.db import l3_db 32from neutron.db import l3_db
33from neutron.db import l3_gwmode_db 33from neutron.db import l3_gwmode_db
34from neutron.db.models import l3 as l3_models 34from neutron.db.models import l3 as l3_models
diff --git a/neutron/tests/unit/quota/test_resource.py b/neutron/tests/unit/quota/test_resource.py
index 93dfd35..e4c80f1 100644
--- a/neutron/tests/unit/quota/test_resource.py
+++ b/neutron/tests/unit/quota/test_resource.py
@@ -14,13 +14,13 @@
14 14
15import mock 15import mock
16from neutron_lib import context 16from neutron_lib import context
17from neutron_lib.db import api as db_api
17from neutron_lib.plugins import constants 18from neutron_lib.plugins import constants
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19from oslo_config import cfg 20from oslo_config import cfg
20from oslo_utils import uuidutils 21from oslo_utils import uuidutils
21import testtools 22import testtools
22 23
23from neutron.db import api as db_api
24from neutron.db.quota import api as quota_api 24from neutron.db.quota import api as quota_api
25from neutron.quota import resource 25from neutron.quota import resource
26from neutron.tests import base 26from neutron.tests import base
diff --git a/neutron/tests/unit/services/metering/test_metering_plugin.py b/neutron/tests/unit/services/metering/test_metering_plugin.py
index 84f5077..0447de4 100644
--- a/neutron/tests/unit/services/metering/test_metering_plugin.py
+++ b/neutron/tests/unit/services/metering/test_metering_plugin.py
@@ -15,13 +15,13 @@
15import mock 15import mock
16from neutron_lib.api.definitions import metering as metering_apidef 16from neutron_lib.api.definitions import metering as metering_apidef
17from neutron_lib import context 17from neutron_lib import context
18from neutron_lib.db import api as db_api
18from neutron_lib.plugins import constants 19from neutron_lib.plugins import constants
19from neutron_lib.plugins import directory 20from neutron_lib.plugins import directory
20from oslo_utils import uuidutils 21from oslo_utils import uuidutils
21 22
22from neutron.api.rpc.agentnotifiers import metering_rpc_agent_api 23from neutron.api.rpc.agentnotifiers import metering_rpc_agent_api
23from neutron.common import utils 24from neutron.common import utils
24from neutron.db import api as db_api
25from neutron.db.metering import metering_rpc 25from neutron.db.metering import metering_rpc
26from neutron.extensions import l3 as ext_l3 26from neutron.extensions import l3 as ext_l3
27from neutron.extensions import metering as ext_metering 27from neutron.extensions import metering as ext_metering