use callback payloads for ROUTER/ROUTER_GATEWAY BEFORE_DELETE events

This patch switches callbacks over to the payload object style events
[1] for ROUTER and ROUTER_GATEWAY BEFORE_DELETE based notifications. To
do so a DBEventPayload object is used with the publish() method to pass
along the related data.

NeutronLibImpact

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

Change-Id: I3ce4475643f4f0afed01f2e9956b3bf84714e6f2
This commit is contained in:
Boden R 2018-04-19 11:15:31 -06:00
parent 1deb0d9f7d
commit 73c7eddb5a
4 changed files with 18 additions and 14 deletions

View File

@ -394,8 +394,10 @@ class L3NATAgent(ha.AgentMixin,
self.namespaces_manager.ensure_router_cleanup(router_id)
return
registry.notify(resources.ROUTER, events.BEFORE_DELETE,
self, router=ri)
registry.publish(resources.ROUTER, events.BEFORE_DELETE, self,
payload=events.DBEventPayload(
self.context, states=(ri,),
resource_id=router_id))
ri.delete()
del self.router_info[router_id]

View File

@ -320,11 +320,11 @@ def after_router_updated(resource, event, l3_agent, **kwargs):
router_id=router.router_id)
def before_router_removed(resource, event, l3_agent, **kwargs):
router = kwargs['router']
def before_router_removed(resource, event, l3_agent, payload=None):
router = payload.latest_state
proxy = l3_agent.metadata_driver
proxy.destroy_monitored_metadata_proxy(l3_agent.process_monitor,
router.router['id'],
l3_agent.conf,
router.ns_name)
router.router['id'],
l3_agent.conf,
router.ns_name)

View File

@ -457,10 +457,11 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
if router not in context.session:
context.session.add(router)
try:
kwargs = {'context': context, 'router_id': router.id}
registry.notify(
resources.ROUTER_GATEWAY, events.BEFORE_DELETE, self,
**kwargs)
registry.publish(resources.ROUTER_GATEWAY,
events.BEFORE_DELETE, self,
payload=events.DBEventPayload(
context, states=(router,),
resource_id=router.id))
except exceptions.CallbackFailure as e:
# NOTE(armax): preserve old check's behavior
if len(e.errors) == 1:
@ -555,8 +556,9 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
@db_api.retry_if_session_inactive()
def delete_router(self, context, id):
registry.notify(resources.ROUTER, events.BEFORE_DELETE,
self, context=context, router_id=id)
registry.publish(resources.ROUTER, events.BEFORE_DELETE, self,
payload=events.DBEventPayload(
context, resource_id=id))
# TODO(nati) Refactor here when we have router insertion model
router = self._ensure_router_not_in_use(context, id)
original = self._make_router_dict(router)

View File

@ -67,7 +67,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework):
mock.call('router', 'after_create', self.agent, router=router),
mock.call('router', 'before_update', self.agent, router=router),
mock.call('router', 'after_update', self.agent, router=router),
mock.call('router', 'before_delete', self.agent, router=router),
mock.call('router', 'before_delete', self.agent, payload=mock.ANY),
mock.call('router', 'after_delete', self.agent, router=router)]
event_handler.assert_has_calls(expected_calls)