Browse Source

use payloads for ROUTER_INTERFACE events

This patch switches the code over to the payload style of callbacks [1]
for ROUTER_INTERFACE events for those that are not using them yet.

Depends-On: https://review.opendev.org/#/c/639814/

[1] https://docs.openstack.org/neutron-lib/latest/contributor/callbacks.html

Change-Id: I5e5fb7f73ff4b9812a468d8aa528addd3247f45c
changes/34/639834/6
Boden R 2 years ago
committed by Lajos Katona
parent
commit
5f7a129dbb
4 changed files with 31 additions and 25 deletions
  1. +4
    -4
      networking_bgpvpn/neutron/services/plugin.py
  2. +5
    -5
      networking_bgpvpn/neutron/services/service_drivers/bagpipe/bagpipe.py
  3. +8
    -8
      networking_bgpvpn/neutron/services/service_drivers/bagpipe/bagpipe_v2.py
  4. +14
    -8
      networking_bgpvpn/tests/unit/services/bagpipe/test_bagpipe.py

+ 4
- 4
networking_bgpvpn/neutron/services/plugin.py View File

@ -78,10 +78,10 @@ class BGPVPNPlugin(bgpvpn.BGPVPNPluginBase,
@registry.receives(resources.ROUTER_INTERFACE, [events.BEFORE_CREATE])
def _notify_adding_interface_to_router(self, resource, event, trigger,
**kwargs):
context = kwargs.get('context')
network_id = kwargs.get('network_id')
router_id = kwargs.get('router_id')
payload):
context = payload.context
network_id = payload.metadata.get('network_id')
router_id = payload.resource_id
try:
routers_bgpvpns = self.driver.get_bgpvpns(
context,


+ 5
- 5
networking_bgpvpn/neutron/services/service_drivers/bagpipe/bagpipe.py View File

@ -534,15 +534,15 @@ class BaGPipeBGPVPNDriver(v2.BaGPipeBGPVPNDriver):
@registry.receives(resources.ROUTER_INTERFACE, [events.AFTER_DELETE])
@log_helpers.log_method_call
def registry_router_interface_deleted(self, resource, event, trigger,
**kwargs):
payload=None):
try:
context = kwargs['context']
context = payload.context
# for router_interface after_delete, in stable/newton, the
# callback does not include the router_id directly, but we find
# it in the port device_id
router_id = kwargs['port']['device_id']
net_id = kwargs['port']['network_id']
router_id = payload.metadata.get('port')['device_id']
net_id = payload.metadata.get('port')['network_id']
self.notify_router_interface_deleted(context, router_id, net_id)
except Exception as e:
_log_callback_processing_exception(resource, event, trigger,
kwargs, e)
payload.metadata, e)

+ 8
- 8
networking_bgpvpn/neutron/services/service_drivers/bagpipe/bagpipe_v2.py View File

@ -59,14 +59,14 @@ def network_is_external(context, net_id):
return False
def _log_callback_processing_exception(resource, event, trigger, kwargs, e):
def _log_callback_processing_exception(resource, event, trigger, metadata, e):
LOG.exception("Error during notification processing "
"%(resource)s %(event)s, %(trigger)s, "
"%(kwargs)s: %(exc)s",
"%(metadata)s: %(exc)s",
{'trigger': trigger,
'resource': resource,
'event': event,
'kwargs': kwargs,
'metadata': metadata,
'exc': e})
@ -228,15 +228,15 @@ class BaGPipeBGPVPNDriver(driver_api.BGPVPNDriverRC):
@registry.receives(resources.ROUTER_INTERFACE, [events.AFTER_CREATE])
@log_helpers.log_method_call
def registry_router_interface_created(self, resource, event, trigger,
**kwargs):
payload=None):
try:
context = kwargs['context']
router_id = kwargs['router_id']
net_id = kwargs['port']['network_id']
context = payload.context
router_id = payload.resource_id
net_id = payload.metadata.get('port')['network_id']
self.notify_router_interface_created(context, router_id, net_id)
except Exception as e:
_log_callback_processing_exception(resource, event, trigger,
kwargs, e)
payload.metadata, e)
# need to subscribe to router interface *before*_delete
# because after delete, we can't build the OVO objects from the DB anymore


+ 14
- 8
networking_bgpvpn/tests/unit/services/bagpipe/test_bagpipe.py View File

@ -29,6 +29,7 @@ from neutron.plugins.ml2 import rpc as ml2_rpc
from neutron.tests.common import helpers
from neutron_lib.api.definitions import portbindings
from neutron_lib.callbacks import events
from neutron_lib import constants as const
from neutron_lib import context as n_context
from neutron_lib.plugins import directory
@ -793,11 +794,12 @@ class TestBagpipeServiceDriverCallbacks(TestBagpipeCommon,
return_value=[{
'bgpvpn_id': bgpvpn['bgpvpn']['id']
}]).start():
payload = events.DBEventPayload(
self.ctxt, resource_id=router['router']['id'],
metadata={'port': {'network_id': net['network']['id']}})
self.bagpipe_driver.registry_router_interface_created(
None, None, None,
context=self.ctxt,
port={'network_id': net['network']['id']},
router_id=router['router']['id'],
None, None, None, payload=payload
)
self.mock_update_rpc.assert_called_once_with(
mock.ANY,
@ -818,12 +820,16 @@ class TestBagpipeServiceDriverCallbacks(TestBagpipeCommon,
return_value=[{
'bgpvpn_id': bgpvpn['bgpvpn']['id']
}]).start():
payload = events.DBEventPayload(
self.ctxt, metadata={
'network_id': port['port']['network_id'],
'port': {
'device_id': router['router']['id'],
'network_id': net['network']['id']}
})
self.bagpipe_driver.registry_router_interface_deleted(
None, None, None,
context=self.ctxt,
network_id=port['port']['network_id'],
port={'device_id': router['router']['id'],
'network_id': net['network']['id']}
payload=payload
)
self.mock_delete_rpc.assert_called_once_with(
mock.ANY,


Loading…
Cancel
Save