]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix error code for deletion of router which is in use by vpnservice
authorNachi Ueno <nachi@ntti3.com>
Wed, 11 Sep 2013 23:24:13 +0000 (16:24 -0700)
committerNachi Ueno <nachi@ntti3.com>
Thu, 12 Sep 2013 18:05:56 +0000 (11:05 -0700)
In this commit, we check router is in use by a vpnservice or not when
we delete router.

Fixes bug 1224174

Change-Id: I55a4b9b93715fbb36816c69729d88eb494bcf15e

neutron/db/l3_db.py
neutron/db/vpn/vpn_db.py
neutron/extensions/vpnaas.py
neutron/tests/unit/db/vpn/test_db_vpnaas.py

index 454691e5b72a26bf02f20f4e1c57404d2f99f927..ab6017f5c2cd83afeb5fedb4687fba7737299006 100644 (file)
@@ -33,6 +33,7 @@ from neutron import manager
 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__)
 
@@ -230,6 +231,12 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
             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]}
index f82f4ee5fbfc58d0ae23dc1bd66a5622058ce6de..1daaa64f1e1723454fe8cc98cca55c4083ff319c 100644 (file)
@@ -583,6 +583,14 @@ class VPNPluginDb(VPNPluginBase, base_db.CommonDbMixin):
                                     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):
index e85174bbd277553895880deee23a43c21b1faf4f..dc89752a4f96cbd1c8c6caf70aedb7a9f6850d60 100644 (file)
@@ -65,6 +65,10 @@ class VPNServiceInUse(qexception.InUse):
     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")
 
index ced5cf2c775232e2dd3ad575c8c1b462fcd2fc43..f4f4b525b31400b462d1fd5b04fc1854e07a9d1f 100644 (file)
@@ -770,6 +770,15 @@ class TestVpnaas(VPNPluginDbTestCase):
                                      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]