Fix error code for deletion of router which is in use by vpnservice

In this commit, we check router is in use by a vpnservice or not when
we delete router.

Fixes bug 1224174

Change-Id: I55a4b9b93715fbb36816c69729d88eb494bcf15e
This commit is contained in:
Nachi Ueno 2013-09-11 16:24:13 -07:00
parent 494c97a413
commit df1d4ca3d5
4 changed files with 28 additions and 0 deletions

View 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]}

View 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):

View 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")

View 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]