Use payload for PORT and FLOATING_IP events

* Updated callback functions port_callback,
  floatingip_update_callback to include payload
* Fixed unit test cases

Change-Id: I84956d86ea45039a8841b2b1f4f02bf373efcef5
Signed-off-by: Manu B <manu.b@est.tech>
This commit is contained in:
elajkat 2021-08-30 09:17:15 +02:00 committed by Manu B
parent c021b106d9
commit b8b8788d23
2 changed files with 21 additions and 14 deletions

View File

@ -77,6 +77,9 @@ class BgpPlugin(service_base.ServicePluginBase,
self.conn.consume_in_threads()
def _register_callbacks(self):
registry.subscribe(self.floatingip_update_callback,
resources.FLOATING_IP,
events.AFTER_CREATE)
registry.subscribe(self.floatingip_update_callback,
resources.FLOATING_IP,
events.AFTER_UPDATE)
@ -224,18 +227,18 @@ class BgpPlugin(service_base.ServicePluginBase,
return super(BgpPlugin, self).get_advertised_routes(context,
bgp_speaker_id)
def floatingip_update_callback(self, resource, event, trigger, **kwargs):
if event != events.AFTER_UPDATE:
def floatingip_update_callback(self, resource, event, trigger, payload):
if event not in [events.AFTER_CREATE, events.AFTER_UPDATE]:
return
ctx = context.get_admin_context()
new_router_id = kwargs['router_id']
last_router_id = kwargs.get('last_known_router_id')
floating_ip_address = kwargs['floating_ip_address']
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']
dest = str(floating_ip_address) + '/32'
bgp_speakers = self._bgp_speakers_for_gw_network_by_family(
ctx,
kwargs['floating_network_id'],
fip['floating_network_id'],
n_const.IP_VERSION_4)
if last_router_id and new_router_id != last_router_id:
@ -348,12 +351,12 @@ class BgpPlugin(service_base.ServicePluginBase,
self.stop_route_advertisements(ctx, self._bgp_rpc,
speaker.id, routes)
def port_callback(self, resource, event, trigger, **kwargs):
def port_callback(self, resource, event, trigger, payload):
if event != events.AFTER_UPDATE:
return
original_port = kwargs['original_port']
updated_port = kwargs['port']
original_port = payload.states[0]
updated_port = payload.latest_state
if not updated_port.get('fixed_ips'):
return

View File

@ -56,6 +56,8 @@ class TestBgpPlugin(base.BaseTestCase):
expected_calls = [
mock.call(plugin.bgp_drscheduler.schedule_bgp_speaker_callback,
dr_resources.BGP_SPEAKER, events.AFTER_CREATE),
mock.call(plugin.floatingip_update_callback,
resources.FLOATING_IP, events.AFTER_CREATE),
mock.call(plugin.floatingip_update_callback,
resources.FLOATING_IP, events.AFTER_UPDATE),
mock.call(plugin.router_interface_callback,
@ -92,9 +94,9 @@ class TestBgpPlugin(base.BaseTestCase):
payload=payload)
def test_floatingip_update_callback(self):
kwargs = {'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'}
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'}
test_context = 'test_context'
@ -108,7 +110,9 @@ class TestBgpPlugin(base.BaseTestCase):
get_bgp.return_value = [bgp_speaker]
self.plugin.floatingip_update_callback(
test_context, events.AFTER_UPDATE, None, **kwargs)
test_context, events.AFTER_UPDATE, None,
payload=events.DBEventPayload(
test_context, states=(fip,)))
get_bgp.assert_called_once_with(self.fake_admin_ctx,
'a-b-c-d-e',