Fix add same network on different type routers failed

This critical error is introduced from commit
336431d016d163f3e46cb2aeff68fcca7caf68e7, which failed to filter out
non-distributed routers and instead get all routers leading to adding
network on different type routers failed.

Change-Id: Iff44d96db80016277c0ee87d2a2d11a687738e4c
This commit is contained in:
linb 2016-06-15 09:42:46 +08:00 committed by Kobi Samoray
parent b2467e9889
commit 721307fea1
2 changed files with 49 additions and 4 deletions

View File

@ -222,9 +222,10 @@ class RouterDistributedDriver(router_driver.RouterBaseDriver):
intf_ports = _nsxv_plugin.get_ports(context.elevated(),
filters=port_filters)
router_ids = [port['device_id'] for port in intf_ports]
dist_router_filters = {'id': router_ids,
'distributed': [True]}
dist_routers = _nsxv_plugin.get_routers(context, dist_router_filters)
all_routers = _nsxv_plugin.get_routers(context,
filters={'id': router_ids})
dist_routers = [router for router in all_routers
if router.get('distributed') is True]
if len(dist_routers) > 0:
err_msg = _("network can only be attached to just one distributed "
"router, the network is already attached to router "

View File

@ -3223,6 +3223,14 @@ class TestVdrTestCase(L3NatTest, L3NatTestCaseBase,
IPv6ExpectedFailuresTestMixin,
NsxVPluginV2TestCase):
def setUp(self, plugin=PLUGIN_NAME, ext_mgr=None, service_plugins=None):
super(TestVdrTestCase, self).setUp(
plugin=plugin, ext_mgr=ext_mgr, service_plugins=service_plugins)
self.plugin_instance.nsx_v.is_subnet_in_use = mock.Mock()
self.plugin_instance.nsx_v.is_subnet_in_use.return_value = False
self._default_tenant_id = self._tenant_id
self._router_tenant_id = 'test-router-tenant'
@mock.patch.object(edge_utils.EdgeManager,
'update_interface_addr')
def test_router_update_gateway_with_different_external_subnet(self, mock):
@ -3273,10 +3281,13 @@ class TestVdrTestCase(L3NatTest, L3NatTestCaseBase,
data['router'][arg] = kwargs[arg]
if 'distributed' in kwargs:
data['router']['distributed'] = kwargs[arg]
data['router']['distributed'] = kwargs['distributed']
else:
data['router']['distributed'] = True
if kwargs.get('router_type'):
data['router']['router_type'] = kwargs.get('router_type')
router_req = self.new_create_request('routers', data, fmt)
if set_context and tenant_id:
# create a specific auth context for this request
@ -3408,6 +3419,39 @@ class TestVdrTestCase(L3NatTest, L3NatTestCaseBase,
None,
err_code)
def test_different_type_routers_add_interfaces_on_same_network_pass(self):
with self.router() as dist, \
self.router(distributed=False, router_type='shared') as shared, \
self.router(distributed=False, router_type='exclusive') as excl:
with self.network() as n:
with self.subnet(network=n) as s1, \
self.subnet(network=n, cidr='11.0.0.0/24') as s2, \
self.subnet(network=n, cidr='12.0.0.0/24') as s3:
self._router_interface_action('add',
shared['router']['id'],
s1['subnet']['id'],
None)
self._router_interface_action('add',
excl['router']['id'],
s2['subnet']['id'],
None)
self._router_interface_action('add',
dist['router']['id'],
s3['subnet']['id'],
None)
self._router_interface_action('remove',
dist['router']['id'],
s3['subnet']['id'],
None)
self._router_interface_action('remove',
excl['router']['id'],
s2['subnet']['id'],
None)
self._router_interface_action('remove',
shared['router']['id'],
s1['subnet']['id'],
None)
def test_delete_ext_net_with_disassociated_floating_ips(self):
with self.network() as net:
net_id = net['network']['id']