Fix creating ipsec site connection

Fixes a RuntimeError "Method remove_reservation cannot be called
within a transaction" while creating an ipsec site connection.
To avoid the error the service driver now gets the vpnservice
(to get the router_id) inside a CONTEXT_READER wrapper.

Closes-Bug: #1978571
Change-Id: I6552816db8a596a933365dc9de481d8c32371f1c
This commit is contained in:
Bodo Petermann 2022-06-14 15:44:32 +02:00
parent 6a226281bb
commit 740bf12dfa
3 changed files with 13 additions and 9 deletions

View File

@ -668,6 +668,11 @@ class VPNPluginDb(vpnaas.VPNPluginBase,
if query.first():
raise vpn_exception.EndpointGroupInUse(group_id=group_id)
def get_vpnservice_router_id(self, context, vpnservice_id):
with db_api.CONTEXT_READER.using(context):
vpnservice = self._get_vpnservice(context, vpnservice_id)
return vpnservice['router_id']
class VPNPluginRpcDbMixin(object):
def _build_local_subnet_cidr_map(self, context):

View File

@ -112,20 +112,20 @@ class BaseIPsecVPNDriver(service_drivers.VpnDriver, metaclass=abc.ABCMeta):
pass
def create_ipsec_site_connection(self, context, ipsec_site_connection):
vpnservice = self.service_plugin._get_vpnservice(
router_id = self.service_plugin.get_vpnservice_router_id(
context, ipsec_site_connection['vpnservice_id'])
self.agent_rpc.vpnservice_updated(context, vpnservice['router_id'])
self.agent_rpc.vpnservice_updated(context, router_id)
def update_ipsec_site_connection(
self, context, old_ipsec_site_connection, ipsec_site_connection):
vpnservice = self.service_plugin._get_vpnservice(
router_id = self.service_plugin.get_vpnservice_router_id(
context, ipsec_site_connection['vpnservice_id'])
self.agent_rpc.vpnservice_updated(context, vpnservice['router_id'])
self.agent_rpc.vpnservice_updated(context, router_id)
def delete_ipsec_site_connection(self, context, ipsec_site_connection):
vpnservice = self.service_plugin._get_vpnservice(
router_id = self.service_plugin.get_vpnservice_router_id(
context, ipsec_site_connection['vpnservice_id'])
self.agent_rpc.vpnservice_updated(context, vpnservice['router_id'])
self.agent_rpc.vpnservice_updated(context, router_id)
def create_ikepolicy(self, context, ikepolicy):
pass

View File

@ -98,9 +98,8 @@ class TestIPsecDriver(base.BaseTestCase):
self.svc_plugin = mock.Mock()
self.svc_plugin.get_l3_agents_hosting_routers.return_value = [l3_agent]
self._fake_vpn_router_id = _uuid()
self.svc_plugin._get_vpnservice.return_value = {
'router_id': self._fake_vpn_router_id
}
self.svc_plugin.get_vpnservice_router_id.return_value = \
self._fake_vpn_router_id
self.driver = ipsec_driver.IPsecVPNDriver(self.svc_plugin)
self.validator = ipsec_validator.IpsecVpnValidator(self.driver)
self.context = n_ctx.get_admin_context()