summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Mills <joseph.mills@bigswitch.com>2017-05-22 16:42:58 +0900
committerAditya Vaja <wolverine.av@gmail.com>2017-06-14 13:50:42 -0700
commit4cc32adf1138d12964d686eaa9e088f24639932d (patch)
tree7eddede2a95b63ff89b642bdae81baa39ce4d5ee
parentde7e52ffe9730f66687e330493e1b61eb32f99c5 (diff)
use context_manager for more transactions
There are a few places that are missing the new way of creating transactions, and this was causing a number of UT to fail. NOTE: This patch does not complete all of the work that is required for the enginefacade switch. This patch is just enough to get the failing UT to pass. Change-Id: I52616f43c3b08d910784bbf003b22f0b2ab693d7
Notes
Notes (review): Code-Review+2: Aditya Vaja <wolverine.av@gmail.com> Workflow+1: Aditya Vaja <wolverine.av@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 14 Jun 2017 21:14:10 +0000 Reviewed-on: https://review.openstack.org/474349 Project: openstack/networking-bigswitch Branch: refs/heads/stable/ocata
-rw-r--r--networking_bigswitch/plugins/bigswitch/l3_router_plugin.py20
-rw-r--r--networking_bigswitch/plugins/bigswitch/plugin.py30
2 files changed, 23 insertions, 27 deletions
diff --git a/networking_bigswitch/plugins/bigswitch/l3_router_plugin.py b/networking_bigswitch/plugins/bigswitch/l3_router_plugin.py
index c174b77..3459c40 100644
--- a/networking_bigswitch/plugins/bigswitch/l3_router_plugin.py
+++ b/networking_bigswitch/plugins/bigswitch/l3_router_plugin.py
@@ -26,6 +26,7 @@ from oslo_log import log as logging
26from oslo_utils import excutils 26from oslo_utils import excutils
27 27
28from neutron.api import extensions as neutron_extensions 28from neutron.api import extensions as neutron_extensions
29from neutron.db import api as db
29from neutron.extensions import l3 30from neutron.extensions import l3
30 31
31from neutron_lib import constants as lib_constants 32from neutron_lib import constants as lib_constants
@@ -78,7 +79,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
78 rules = self._get_tenant_default_router_rule(tenant_id) 79 rules = self._get_tenant_default_router_rule(tenant_id)
79 router['router']['router_rules'] = [rules] 80 router['router']['router_rules'] = [rules]
80 81
81 with context.session.begin(subtransactions=True): 82 with db.context_manager.writer.using(context):
82 # create router in DB 83 # create router in DB
83 # TODO(wolverineav): hack until fixed at right place 84 # TODO(wolverineav): hack until fixed at right place
84 setattr(context, 'GUARD_TRANSACTION', False) 85 setattr(context, 'GUARD_TRANSACTION', False)
@@ -114,10 +115,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
114 115
115 orig_router = super(L3RestProxy, self).get_router(context, router_id) 116 orig_router = super(L3RestProxy, self).get_router(context, router_id)
116 tenant_id = orig_router["tenant_id"] 117 tenant_id = orig_router["tenant_id"]
117 with context.session.begin(subtransactions=True): 118 with db.context_manager.writer.using(context):
118 # TODO(wolverineav): hack until fixed at right place
119 setattr(context, 'GUARD_TRANSACTION', False)
120
121 new_router = super(L3RestProxy, 119 new_router = super(L3RestProxy,
122 self).update_router(context, router_id, router) 120 self).update_router(context, router_id, router)
123 router = self._update_ext_gateway_info(context, new_router) 121 router = self._update_ext_gateway_info(context, new_router)
@@ -133,7 +131,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
133 @put_context_in_serverpool 131 @put_context_in_serverpool
134 @log_helper.log_method_call 132 @log_helper.log_method_call
135 def delete_router(self, context, router_id): 133 def delete_router(self, context, router_id):
136 with context.session.begin(subtransactions=True): 134 with db.context_manager.writer.using(context):
137 orig_router = self._get_router(context, router_id) 135 orig_router = self._get_router(context, router_id)
138 tenant_id = orig_router["tenant_id"] 136 tenant_id = orig_router["tenant_id"]
139 137
@@ -177,7 +175,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
177 router = self._get_router(context, router_id) 175 router = self._get_router(context, router_id)
178 tenant_id = router['tenant_id'] 176 tenant_id = router['tenant_id']
179 177
180 with context.session.begin(subtransactions=True): 178 with db.context_manager.writer.using(context):
181 # create interface in DB 179 # create interface in DB
182 # TODO(wolverineav): hack until fixed at right place 180 # TODO(wolverineav): hack until fixed at right place
183 setattr(context, 'GUARD_TRANSACTION', False) 181 setattr(context, 'GUARD_TRANSACTION', False)
@@ -223,7 +221,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
223 msg = _("Either subnet_id or port_id must be specified") 221 msg = _("Either subnet_id or port_id must be specified")
224 raise exceptions.BadRequest(resource='router', msg=msg) 222 raise exceptions.BadRequest(resource='router', msg=msg)
225 223
226 with context.session.begin(subtransactions=True): 224 with db.context_manager.writer.using(context):
227 # remove router in DB 225 # remove router in DB
228 # TODO(wolverineav): hack until fixed at right place 226 # TODO(wolverineav): hack until fixed at right place
229 setattr(context, 'GUARD_TRANSACTION', False) 227 setattr(context, 'GUARD_TRANSACTION', False)
@@ -249,7 +247,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
249 @put_context_in_serverpool 247 @put_context_in_serverpool
250 @log_helper.log_method_call 248 @log_helper.log_method_call
251 def create_floatingip(self, context, floatingip): 249 def create_floatingip(self, context, floatingip):
252 with context.session.begin(subtransactions=True): 250 with db.context_manager.writer.using(context):
253 # create floatingip in DB 251 # create floatingip in DB
254 # TODO(wolverineav): hack until fixed at right place 252 # TODO(wolverineav): hack until fixed at right place
255 setattr(context, 'GUARD_TRANSACTION', False) 253 setattr(context, 'GUARD_TRANSACTION', False)
@@ -275,7 +273,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
275 @put_context_in_serverpool 273 @put_context_in_serverpool
276 @log_helper.log_method_call 274 @log_helper.log_method_call
277 def update_floatingip(self, context, id, floatingip): 275 def update_floatingip(self, context, id, floatingip):
278 with context.session.begin(subtransactions=True): 276 with db.context_manager.writer.using(context):
279 # update floatingip in DB 277 # update floatingip in DB
280 # TODO(wolverineav): hack until fixed at right place 278 # TODO(wolverineav): hack until fixed at right place
281 setattr(context, 'GUARD_TRANSACTION', False) 279 setattr(context, 'GUARD_TRANSACTION', False)
@@ -299,7 +297,7 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
299 @put_context_in_serverpool 297 @put_context_in_serverpool
300 @log_helper.log_method_call 298 @log_helper.log_method_call
301 def delete_floatingip(self, context, id): 299 def delete_floatingip(self, context, id):
302 with context.session.begin(subtransactions=True): 300 with db.context_manager.writer.using(context):
303 # delete floating IP in DB 301 # delete floating IP in DB
304 # TODO(wolverineav): hack until fixed at right place 302 # TODO(wolverineav): hack until fixed at right place
305 setattr(context, 'GUARD_TRANSACTION', False) 303 setattr(context, 'GUARD_TRANSACTION', False)
diff --git a/networking_bigswitch/plugins/bigswitch/plugin.py b/networking_bigswitch/plugins/bigswitch/plugin.py
index a5206f7..833dcb9 100644
--- a/networking_bigswitch/plugins/bigswitch/plugin.py
+++ b/networking_bigswitch/plugins/bigswitch/plugin.py
@@ -128,11 +128,10 @@ class SecurityGroupServerRpcMixin(sg_db_rpc.SecurityGroupServerRpcMixin):
128 """Get port from database with security group info.""" 128 """Get port from database with security group info."""
129 129
130 LOG.debug("get_port_and_sgs() called for port_id %s", port_id) 130 LOG.debug("get_port_and_sgs() called for port_id %s", port_id)
131 session = context.session
132 sg_binding_port = sg_db.SecurityGroupPortBinding.port_id 131 sg_binding_port = sg_db.SecurityGroupPortBinding.port_id
133 132
134 with session.begin(subtransactions=True): 133 with db.context_manager.reader.using(context):
135 query = session.query( 134 query = context.session.query(
136 models_v2.Port, 135 models_v2.Port,
137 sg_db.SecurityGroupPortBinding.security_group_id 136 sg_db.SecurityGroupPortBinding.security_group_id
138 ) 137 )
@@ -424,7 +423,7 @@ class NeutronRestProxyV2Base(db_base_plugin_v2.NeutronDbPluginV2,
424 if context is None: 423 if context is None:
425 context = qcontext.get_admin_context() 424 context = qcontext.get_admin_context()
426 # start a sub-transaction to avoid breaking parent transactions 425 # start a sub-transaction to avoid breaking parent transactions
427 with context.session.begin(subtransactions=True): 426 with db.context_manager.writer.using(context):
428 subnets = self._get_subnets_by_network(context, 427 subnets = self._get_subnets_by_network(context,
429 net_id) 428 net_id)
430 subnets_details = [] 429 subnets_details = []
@@ -849,7 +848,7 @@ class NeutronRestProxyV2Base(db_base_plugin_v2.NeutronDbPluginV2,
849 # NOTE(kevinbenton): workaround for eventlet/mysql deadlock 848 # NOTE(kevinbenton): workaround for eventlet/mysql deadlock
850 @utils.synchronized('bsn-port-barrier') 849 @utils.synchronized('bsn-port-barrier')
851 def _set_port_status(self, port_id, status): 850 def _set_port_status(self, port_id, status):
852 session = db.get_session() 851 session = db.get_writer_session()
853 try: 852 try:
854 port = session.query(models_v2.Port).filter_by(id=port_id).one() 853 port = session.query(models_v2.Port).filter_by(id=port_id).one()
855 port['status'] = status 854 port['status'] = status
@@ -965,7 +964,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
965 """ 964 """
966 self._warn_on_state_status(network['network']) 965 self._warn_on_state_status(network['network'])
967 966
968 with context.session.begin(subtransactions=True): 967 with db.context_manager.writer.using(context):
969 self._ensure_default_security_group( 968 self._ensure_default_security_group(
970 context, 969 context,
971 network['network']["tenant_id"] 970 network['network']["tenant_id"]
@@ -1006,8 +1005,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1006 """ 1005 """
1007 self._warn_on_state_status(network['network']) 1006 self._warn_on_state_status(network['network'])
1008 1007
1009 session = context.session 1008 with db.context_manager.writer.using(context):
1010 with session.begin(subtransactions=True):
1011 new_net = super(NeutronRestProxyV2, self).update_network( 1009 new_net = super(NeutronRestProxyV2, self).update_network(
1012 context, net_id, network) 1010 context, net_id, network)
1013 self._process_l3_update(context, new_net, network['network']) 1011 self._process_l3_update(context, new_net, network['network'])
@@ -1032,7 +1030,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1032 """ 1030 """
1033 # Validate args 1031 # Validate args
1034 orig_net = super(NeutronRestProxyV2, self).get_network(context, net_id) 1032 orig_net = super(NeutronRestProxyV2, self).get_network(context, net_id)
1035 with context.session.begin(subtransactions=True): 1033 with db.context_manager.writer.using(context):
1036 self._process_l3_delete(context, net_id) 1034 self._process_l3_delete(context, net_id)
1037 ret_val = super(NeutronRestProxyV2, self).delete_network(context, 1035 ret_val = super(NeutronRestProxyV2, self).delete_network(context,
1038 net_id) 1036 net_id)
@@ -1067,7 +1065,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1067 :raises: RemoteRestError 1065 :raises: RemoteRestError
1068 """ 1066 """
1069 # Update DB in new session so exceptions rollback changes 1067 # Update DB in new session so exceptions rollback changes
1070 with context.session.begin(subtransactions=True): 1068 with db.context_manager.writer.using(context):
1071 self._ensure_default_security_group_on_port(context, port) 1069 self._ensure_default_security_group_on_port(context, port)
1072 sgids = self._get_security_groups_on_port(context, port) 1070 sgids = self._get_security_groups_on_port(context, port)
1073 # non-router port status is set to pending. it is then updated 1071 # non-router port status is set to pending. it is then updated
@@ -1115,14 +1113,14 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1115 return new_port 1113 return new_port
1116 1114
1117 def get_port(self, context, id, fields=None): 1115 def get_port(self, context, id, fields=None):
1118 with context.session.begin(subtransactions=True): 1116 with db.context_manager.reader.using(context):
1119 port = super(NeutronRestProxyV2, self).get_port(context, id, 1117 port = super(NeutronRestProxyV2, self).get_port(context, id,
1120 fields) 1118 fields)
1121 self._extend_port_dict_binding(context, port) 1119 self._extend_port_dict_binding(context, port)
1122 return self._fields(port, fields) 1120 return self._fields(port, fields)
1123 1121
1124 def get_ports(self, context, filters=None, fields=None): 1122 def get_ports(self, context, filters=None, fields=None):
1125 with context.session.begin(subtransactions=True): 1123 with db.context_manager.reader.using(context):
1126 ports = super(NeutronRestProxyV2, self).get_ports(context, filters, 1124 ports = super(NeutronRestProxyV2, self).get_ports(context, filters,
1127 fields) 1125 fields)
1128 for port in ports: 1126 for port in ports:
@@ -1161,7 +1159,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1161 1159
1162 # Validate Args 1160 # Validate Args
1163 orig_port = super(NeutronRestProxyV2, self).get_port(context, port_id) 1161 orig_port = super(NeutronRestProxyV2, self).get_port(context, port_id)
1164 with context.session.begin(subtransactions=True): 1162 with db.context_manager.writer.using(context):
1165 # Update DB 1163 # Update DB
1166 new_port = super(NeutronRestProxyV2, 1164 new_port = super(NeutronRestProxyV2,
1167 self).update_port(context, port_id, port) 1165 self).update_port(context, port_id, port)
@@ -1223,7 +1221,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1223 # and l3-router. If so, we should prevent deletion. 1221 # and l3-router. If so, we should prevent deletion.
1224 if l3_port_check and self.l3_plugin: 1222 if l3_port_check and self.l3_plugin:
1225 self.l3_plugin.prevent_l3_port_deletion(context, port_id) 1223 self.l3_plugin.prevent_l3_port_deletion(context, port_id)
1226 with context.session.begin(subtransactions=True): 1224 with db.context_manager.writer.using(context):
1227 if self.l3_plugin: 1225 if self.l3_plugin:
1228 router_ids = self.l3_plugin.disassociate_floatingips( 1226 router_ids = self.l3_plugin.disassociate_floatingips(
1229 context, port_id, do_notify=False) 1227 context, port_id, do_notify=False)
@@ -1257,7 +1255,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1257 def update_subnet(self, context, id, subnet): 1255 def update_subnet(self, context, id, subnet):
1258 self._warn_on_state_status(subnet['subnet']) 1256 self._warn_on_state_status(subnet['subnet'])
1259 1257
1260 with context.session.begin(subtransactions=True): 1258 with db.context_manager.writer.using(context):
1261 # update subnet in DB 1259 # update subnet in DB
1262 new_subnet = super(NeutronRestProxyV2, 1260 new_subnet = super(NeutronRestProxyV2,
1263 self).update_subnet(context, id, subnet) 1261 self).update_subnet(context, id, subnet)
@@ -1272,7 +1270,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
1272 def delete_subnet(self, context, id): 1270 def delete_subnet(self, context, id):
1273 orig_subnet = super(NeutronRestProxyV2, self).get_subnet(context, id) 1271 orig_subnet = super(NeutronRestProxyV2, self).get_subnet(context, id)
1274 net_id = orig_subnet['network_id'] 1272 net_id = orig_subnet['network_id']
1275 with context.session.begin(subtransactions=True): 1273 with db.context_manager.writer.using(context):
1276 # delete subnet in DB 1274 # delete subnet in DB
1277 super(NeutronRestProxyV2, self).delete_subnet(context, id) 1275 super(NeutronRestProxyV2, self).delete_subnet(context, id)
1278 orig_net = super(NeutronRestProxyV2, self).get_network(context, 1276 orig_net = super(NeutronRestProxyV2, self).get_network(context,