Takes hosting information into account when determining updated routers

In some (rare) cases a vrf is removed because the cfg agent is not taking
hosting device into account when determining routers that have been deleted
by the user. This patch fixes this issue.

AKA: DE3934

Change-Id: I34b2883f322bdf492db18c155fff635281f7bfdb
Closes-Bug: #1694674
This commit is contained in:
Bob Melander 2017-05-31 14:14:48 +02:00
parent 977f5217ba
commit 38e2ffaf6d
2 changed files with 24 additions and 3 deletions

View File

@ -597,11 +597,16 @@ class RoutingServiceHelper(object):
:return: None
"""
try:
ids_previously_hosted_routers = (
set(r_id for r_id, rdata in self.router_info.items()
if rdata.router.get('hosting_device',
{}).get('id') == device_id))
if all_routers:
prev_router_ids = set(self.router_info)
prev_router_ids = ids_previously_hosted_routers
else:
prev_router_ids = set(self.router_info) & set(
[router['id'] for router in routers])
prev_router_ids = (ids_previously_hosted_routers &
set([router['id'] for router in routers]))
cur_router_ids = set()
deleted_routerids_list = []

View File

@ -871,6 +871,22 @@ class TestBasicRoutingOperations(base.BaseTestCase):
self.routing_helper._router_removed.assert_any_call(router2['id'])
self.routing_helper._process_router.assert_called_with(ri1)
def test_process_routers_skips_routers_on_other_hosting_devices(self):
router1, port1 = prepare_router_data()
r1_id = router1['id']
r1_info = routing_svc_helper.RouterInfo(r1_id, router1)
router2, port2 = prepare_router_data()
r2_id = router2['id']
self.routing_helper.router_info = {
r1_id: r1_info,
r2_id: routing_svc_helper.RouterInfo(r2_id, router2)}
self.routing_helper._process_router = mock.Mock()
self.routing_helper._router_removed = mock.Mock()
self.routing_helper._process_routers([router1], [],
router1['hosting_device']['id'])
self.routing_helper._process_router.assert_called_once_with(r1_info)
self.assertEqual(0, self.routing_helper._router_removed.call_count)
class TestDeviceSyncOperations(base.BaseTestCase):