In this commit, we check router is in use by a vpnservice or not when
we delete router.
Fixes bug
1224174
Change-Id: I55a4b9b93715fbb36816c69729d88eb494bcf15e
from neutron.openstack.common import log as logging
from neutron.openstack.common.notifier import api as notifier_api
from neutron.openstack.common import uuidutils
+from neutron.plugins.common import constants
LOG = logging.getLogger(__name__)
if ports:
raise l3.RouterInUse(router_id=id)
+ #TODO(nati) Refactor here when we have router insertion model
+ vpnservice = manager.NeutronManager.get_service_plugins().get(
+ constants.VPN)
+ if vpnservice:
+ vpnservice.check_router_in_use(context, id)
+
# delete any gw port
device_filter = {'device_id': [id],
'device_owner': [DEVICE_OWNER_ROUTER_GW]}
self._make_vpnservice_dict,
filters=filters, fields=fields)
+ def check_router_in_use(self, context, router_id):
+ vpnservices = self.get_vpnservices(
+ context, filters={'router_id': [router_id]})
+ if vpnservices:
+ raise vpnaas.RouterInUseByVPNService(
+ router_id=router_id,
+ vpnservice_id=vpnservices[0]['id'])
+
class VPNPluginRpcDbMixin():
def _get_agent_hosting_vpn_services(self, context, host):
message = _("VPNService %(vpnservice_id)s is still in use")
+class RouterInUseByVPNService(qexception.InUse):
+ message = _("Router %(router_id)s is used by VPNService %(vpnservice_id)s")
+
+
class VPNStateInvalid(qexception.BadRequest):
message = _("Invalid state %(state)s of vpnaas resource %(id)s")
expected)
return vpnservice
+ def test_delete_router_in_use_by_vpnservice(self):
+ """Test delete router in use by vpn service."""
+ with self.subnet(cidr='10.2.0.0/24') as subnet:
+ with self.router() as router:
+ with self.vpnservice(subnet=subnet,
+ router=router):
+ self._delete('routers', router['router']['id'],
+ expected_code=webob.exc.HTTPConflict.code)
+
def _set_active(self, model, resource_id):
service_plugin = manager.NeutronManager.get_service_plugins()[
constants.VPN]