diff --git a/neutron_dynamic_routing/services/bgp/bgp_plugin.py b/neutron_dynamic_routing/services/bgp/bgp_plugin.py index f959b7c9..57b4e073 100644 --- a/neutron_dynamic_routing/services/bgp/bgp_plugin.py +++ b/neutron_dynamic_routing/services/bgp/bgp_plugin.py @@ -231,15 +231,18 @@ class BgpPlugin(service_base.ServicePluginBase, if event not in [events.AFTER_CREATE, events.AFTER_UPDATE]: return ctx = context.get_admin_context() - fip = payload.latest_state - new_router_id = fip['router_id'] - last_router_id = fip.get('last_known_router_id') - floating_ip_address = fip['floating_ip_address'] + new_fip = payload.latest_state + new_router_id = new_fip['router_id'] + floating_ip_address = new_fip['floating_ip_address'] dest = str(floating_ip_address) + '/32' bgp_speakers = self._bgp_speakers_for_gw_network_by_family( ctx, - fip['floating_network_id'], + new_fip['floating_network_id'], n_const.IP_VERSION_4) + last_router_id = None + if event == events.AFTER_UPDATE: + old_fip = payload.states[0] + last_router_id = old_fip['router_id'] if last_router_id and new_router_id != last_router_id: # Here gives the old route next_hop a `None` value, then diff --git a/neutron_dynamic_routing/tests/unit/services/bgp/test_bgp_plugin.py b/neutron_dynamic_routing/tests/unit/services/bgp/test_bgp_plugin.py index f5bdeee3..f03a8d75 100644 --- a/neutron_dynamic_routing/tests/unit/services/bgp/test_bgp_plugin.py +++ b/neutron_dynamic_routing/tests/unit/services/bgp/test_bgp_plugin.py @@ -94,9 +94,10 @@ class TestBgpPlugin(base.BaseTestCase): payload=payload) def test_floatingip_update_callback(self): - fip = {'floating_ip_address': netaddr.IPAddress('10.10.10.10'), - 'last_known_router_id': 'old-router-id', - 'router_id': '', 'floating_network_id': 'a-b-c-d-e'} + new_fip = {'floating_ip_address': netaddr.IPAddress('10.10.10.10'), + 'router_id': '', 'floating_network_id': 'a-b-c-d-e'} + old_fip = new_fip.copy() + old_fip.update(router_id='old-router-id') test_context = 'test_context' @@ -112,7 +113,7 @@ class TestBgpPlugin(base.BaseTestCase): self.plugin.floatingip_update_callback( test_context, events.AFTER_UPDATE, None, payload=events.DBEventPayload( - test_context, states=(fip,))) + test_context, states=(old_fip, new_fip))) get_bgp.assert_called_once_with(self.fake_admin_ctx, 'a-b-c-d-e',