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.

NeutronLibImpact

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

Change-Id: I9194c7857f10392149159071cda8e080e93adc10
This commit is contained in:
Boden R 2017-06-14 08:19:22 -06:00
parent 779a8d31e7
commit 40866acd02
7 changed files with 8 additions and 8 deletions

View File

@ -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):

View File

@ -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
trigger.register_driver(self)

View File

@ -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)
@property
def drivers(self):

View File

@ -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()

View File

@ -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

View File

@ -60,7 +60,7 @@ class TrunkPlugin(service_base.ServicePluginBase,
drivers.register()
registry.subscribe(rules.enforce_port_deletion_rules,
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', driver.name)
self.check_compatibility()

View File

@ -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)
self._mgr.notify.assert_called_with(mock_agent_type,
self._mgr.publish.assert_called_with(mock_agent_type,
events.AFTER_INIT,
mock_agent,
agent=mock_agent)
payload=None)
def test_register(self):
mock_callback = mock.Mock()