Merge "Checking load balancer before removing router interface"

This commit is contained in:
Jenkins 2016-03-29 16:21:55 +00:00 committed by Gerrit Code Review
commit 83addfaa77
2 changed files with 25 additions and 1 deletions

View File

@ -15,6 +15,7 @@
from oslo_log import log as logging
from neutron.api.v2 import attributes as attr
from neutron.plugins.common import constants
from vmware_nsx._i18n import _
from vmware_nsx.common import exceptions as nsxv_exc
@ -214,7 +215,7 @@ class RouterExclusiveDriver(router_driver.RouterBaseDriver):
'fixed_ips', [])]
subnet = port_subnets[0]
if subnet and self.nsx_v.is_subnet_in_use(context, subnet):
if subnet and self._check_lb_on_subnet(context, subnet):
error = _('Cannot delete router interface while loadbalancers are '
'provisioned on attached subnet')
raise nsxv_exc.NsxPluginException(err_msg=error)
@ -246,6 +247,16 @@ class RouterExclusiveDriver(router_driver.RouterBaseDriver):
address_groups)
return info
def _check_lb_on_subnet(self, context, subnet_id):
# Check lbaas
dev_owner_v1 = 'neutron:' + constants.LOADBALANCER
dev_owner_v2 = 'neutron:' + constants.LOADBALANCERV2
filters = {'device_owner': [dev_owner_v1, dev_owner_v2],
'fixed_ips': {'subnet_id': [subnet_id]}}
ports = super(nsx_v.NsxVPluginV2, self.plugin).get_ports(
context, filters=filters)
return (len(ports) >= 1)
def _update_edge_router(self, context, router_id):
router = self.plugin._get_router(context.elevated(), router_id)
with locking.LockManager.get_lock(

View File

@ -2356,6 +2356,19 @@ class TestExclusiveRouterTestCase(L3NatTest, L3NatTestCaseBase,
body = self._show('routers', router_id)
self.assertEqual('shared', body['router']['router_type'])
def test_router_remove_interface_with_load_balancer(self):
with self.router() as router, self.subnet() as subnet:
fixed_ips = [{'subnet_id': subnet['subnet']['id']}]
with self.port(subnet,
device_owner='neutron:LOADBALANCER',
fixed_ips=fixed_ips):
expected_code = webob.exc.HTTPInternalServerError.code
self._router_interface_action('remove',
router['router']['id'],
subnet['subnet']['id'],
None,
expected_code=expected_code)
class ExtGwModeTestCase(NsxVPluginV2TestCase,
test_ext_gw_mode.ExtGwModeIntTestCase):