use new payload objects for *_INIT callbacks

Part of the work we did while rehoming the callback modules introduced
the notion of payload objects [1] to replace the unstructured kwargs
used today. When using payloads event sources need to use publish()
rather than notify() to trigger the callback(s) and pass along a payload
object (if needed).

This patch begins to move us onto the payload objects by updating
BEFORE_INIT and AFTER_INIT event types to use the payloads.

NB: This change needs to be in sync with consumers using the events
herein. Once publish() is used with payloads, callback functions must
also define the payload kwarg to follow suit. Therefore such consumers
need to depend on this patch.



Change-Id: I9194c7857f10392149159071cda8e080e93adc10
Boden R 6 years ago
parent 779a8d31e7
commit 40866acd02

@ -17,7 +17,7 @@ from neutron_lib.callbacks import registry
def notify_init_event(agent_type, agent):
"""Notify init event for the specified agent."""
registry.notify(agent_type, events.AFTER_INIT, agent, agent=agent)
registry.publish(agent_type, events.AFTER_INIT, agent)
def register(callback, agent_type):

@ -48,7 +48,7 @@ class DriverBase(object):
# logging plugin can discover which resources types are supported by
# the log driver.
@registry.receives(log_const.LOGGING_PLUGIN, [events.AFTER_INIT])
def _register(self, resource, event, trigger, **kwargs):
def _register(self, resource, event, trigger, payload=None):
if self.is_loaded:
# trigger is the LoggingServiceDriverManager

@ -26,7 +26,7 @@ class LoggingServiceDriverManager(object):
def __init__(self):
self._drivers = set()
registry.notify(log_const.LOGGING_PLUGIN, events.AFTER_INIT, self)
registry.publish(log_const.LOGGING_PLUGIN, events.AFTER_INIT, self)
def drivers(self):

@ -43,7 +43,7 @@ class QosServiceDriverManager(object):
# notify any registered QoS driver that we're ready, those will
# call the driver manager back with register_driver if they
# are enabled
registry.notify(qos_consts.QOS_PLUGIN, events.AFTER_INIT, self)
registry.publish(qos_consts.QOS_PLUGIN, events.AFTER_INIT, self)
if self.rpc_notifications_required:
self.push_api = resources_rpc.ResourcesPushRpcApi()

@ -62,7 +62,7 @@ class DriverBase(object):
return agent_type == self.agent_type
@registry.receives(trunk_consts.TRUNK_PLUGIN, [events.AFTER_INIT])
def register(self, resource, event, trigger, **kwargs):
def register(self, resource, event, trigger, payload=None):
"""Register the trunk driver.
This method should be overridden so that the driver can subscribe

@ -60,7 +60,7 @@ class TrunkPlugin(service_base.ServicePluginBase,
resources.PORT, events.BEFORE_DELETE)
registry.notify(constants.TRUNK_PLUGIN, events.AFTER_INIT, self)
registry.publish(constants.TRUNK_PLUGIN, events.AFTER_INIT, self)
for driver in self._drivers:
LOG.debug('Trunk plugin loaded with driver %s',

@ -31,10 +31,10 @@ class CapabilitiesTest(base.BaseTestCase):
mock_agent_type = mock.Mock()
mock_agent = mock.Mock()
capabilities.notify_init_event(mock_agent_type, mock_agent)
def test_register(self):
mock_callback = mock.Mock()