Merge "NSX|V update router edge when gateway subnet changes"
This commit is contained in:
commit
27a908ef16
@ -131,3 +131,7 @@ class RouterBaseDriver(RouterAbstractDriver):
|
||||
def get_router_az_by_id(self, context, router_id):
|
||||
lrouter = self.plugin.get_router(context, router_id)
|
||||
return self.get_router_az(lrouter)
|
||||
|
||||
def _update_nexthop(self, context, router_id, newnexthop):
|
||||
"""Update the router edge on gateway subnet default gateway change."""
|
||||
self.plugin._update_routes(context, router_id, newnexthop)
|
||||
|
@ -147,6 +147,12 @@ class RouterDistributedDriver(router_driver.RouterBaseDriver):
|
||||
self._update_routes_on_tlr(context, router_id, newnexthop=None,
|
||||
metadata_gateway=metadata_gateway)
|
||||
|
||||
def _update_nexthop(self, context, router_id, newnexthop):
|
||||
plr_id = self.edge_manager.get_plr_by_tlr_id(context, router_id)
|
||||
if plr_id:
|
||||
self._update_routes_on_plr(context, router_id, plr_id,
|
||||
newnexthop)
|
||||
|
||||
def _update_router_gw_info(self, context, router_id, info,
|
||||
is_routes_update=False,
|
||||
force_update=False):
|
||||
|
@ -2031,6 +2031,18 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
update_dhcp_config = True
|
||||
return update_dhcp_config
|
||||
|
||||
def _update_routers_on_gateway_change(self, context, subnet_id,
|
||||
new_gateway):
|
||||
"""Update all relevant router edges that the nexthop changed."""
|
||||
port_filters = {'device_owner': [l3_db.DEVICE_OWNER_ROUTER_GW],
|
||||
'fixed_ips': {'subnet_id': [subnet_id]}}
|
||||
intf_ports = self.get_ports(context.elevated(),
|
||||
filters=port_filters)
|
||||
router_ids = [port['device_id'] for port in intf_ports]
|
||||
for router_id in router_ids:
|
||||
router_driver = self._find_router_driver(context, router_id)
|
||||
router_driver._update_nexthop(context, router_id, new_gateway)
|
||||
|
||||
def update_subnet(self, context, id, subnet):
|
||||
s = subnet['subnet']
|
||||
orig = self._get_subnet(context, id)
|
||||
@ -2054,6 +2066,10 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
# Update the edge
|
||||
network_id = subnet['network_id']
|
||||
self.edge_manager.update_dhcp_edge_bindings(context, network_id)
|
||||
# also update routers that use this subnet as their gateway
|
||||
if gateway_ip != subnet['gateway_ip']:
|
||||
self._update_routers_on_gateway_change(context, id,
|
||||
subnet['gateway_ip'])
|
||||
if enable_dhcp != subnet['enable_dhcp']:
|
||||
self._update_subnet_dhcp_status(subnet, context)
|
||||
return subnet
|
||||
|
@ -64,6 +64,8 @@ from vmware_nsx.extensions import routertype as router_type
|
||||
from vmware_nsx.extensions import securitygrouplogging
|
||||
from vmware_nsx.extensions import vnicindex as ext_vnic_idx
|
||||
from vmware_nsx.plugins.nsx_v import availability_zones as nsx_az
|
||||
from vmware_nsx.plugins.nsx_v.drivers import (
|
||||
distributed_router_driver as dist_router_driver)
|
||||
from vmware_nsx.plugins.nsx_v.drivers import (
|
||||
exclusive_router_driver as ex_router_driver)
|
||||
from vmware_nsx.plugins.nsx_v.drivers import (
|
||||
@ -3144,6 +3146,17 @@ class TestExclusiveRouterTestCase(L3NatTest, L3NatTestCaseBase,
|
||||
def test_router_add_gateway_multiple_subnets_ipv6(self):
|
||||
self.skipTest('not supported')
|
||||
|
||||
def test_update_subnet_gateway_for_external_net(self):
|
||||
plugin = directory.get_plugin()
|
||||
router_obj = ex_router_driver.RouterExclusiveDriver(plugin)
|
||||
with mock.patch.object(plugin, '_find_router_driver',
|
||||
return_value=router_obj):
|
||||
with mock.patch.object(router_obj,
|
||||
'_update_nexthop') as update_nexthop:
|
||||
super(TestExclusiveRouterTestCase,
|
||||
self).test_update_subnet_gateway_for_external_net()
|
||||
self.assertTrue(update_nexthop.called)
|
||||
|
||||
|
||||
class ExtGwModeTestCase(NsxVPluginV2TestCase,
|
||||
test_ext_gw_mode.ExtGwModeIntTestCase):
|
||||
@ -3671,6 +3684,17 @@ class TestVdrTestCase(L3NatTest, L3NatTestCaseBase,
|
||||
def test_floatingip_update_to_same_port_id_twice(self):
|
||||
self.skipTest('Plugin changes floating port status')
|
||||
|
||||
def test_update_subnet_gateway_for_external_net(self):
|
||||
plugin = directory.get_plugin()
|
||||
router_obj = dist_router_driver.RouterDistributedDriver(plugin)
|
||||
with mock.patch.object(plugin, '_find_router_driver',
|
||||
return_value=router_obj):
|
||||
with mock.patch.object(router_obj,
|
||||
'_update_nexthop') as update_nexthop:
|
||||
super(TestVdrTestCase,
|
||||
self).test_update_subnet_gateway_for_external_net()
|
||||
self.assertTrue(update_nexthop.called)
|
||||
|
||||
|
||||
class TestNSXvAllowedAddressPairs(NsxVPluginV2TestCase,
|
||||
test_addr_pair.TestAllowedAddressPairs):
|
||||
|
Loading…
Reference in New Issue
Block a user