From 40866acd02a5ecd7fc6705578a82ea79946549a2 Mon Sep 17 00:00:00 2001 From: Boden R Date: Wed, 14 Jun 2017 08:19:22 -0600 Subject: [PATCH] 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 --- neutron/plugins/ml2/drivers/agent/capabilities.py | 2 +- neutron/services/logapi/drivers/base.py | 2 +- neutron/services/logapi/drivers/manager.py | 2 +- neutron/services/qos/drivers/manager.py | 2 +- neutron/services/trunk/drivers/base.py | 2 +- neutron/services/trunk/plugin.py | 2 +- .../tests/unit/plugins/ml2/drivers/agent/test_capabilities.py | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/neutron/plugins/ml2/drivers/agent/capabilities.py b/neutron/plugins/ml2/drivers/agent/capabilities.py index 3545e1e23da..2c935917f55 100644 --- a/neutron/plugins/ml2/drivers/agent/capabilities.py +++ b/neutron/plugins/ml2/drivers/agent/capabilities.py @@ -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): diff --git a/neutron/services/logapi/drivers/base.py b/neutron/services/logapi/drivers/base.py index 97eb9eea253..4e05996e982 100644 --- a/neutron/services/logapi/drivers/base.py +++ b/neutron/services/logapi/drivers/base.py @@ -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) diff --git a/neutron/services/logapi/drivers/manager.py b/neutron/services/logapi/drivers/manager.py index c2e702df6a4..3165707cf40 100644 --- a/neutron/services/logapi/drivers/manager.py +++ b/neutron/services/logapi/drivers/manager.py @@ -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): diff --git a/neutron/services/qos/drivers/manager.py b/neutron/services/qos/drivers/manager.py index db676e2a15f..2ac31c5647f 100644 --- a/neutron/services/qos/drivers/manager.py +++ b/neutron/services/qos/drivers/manager.py @@ -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() diff --git a/neutron/services/trunk/drivers/base.py b/neutron/services/trunk/drivers/base.py index 0deedd26d9e..46165dbc296 100644 --- a/neutron/services/trunk/drivers/base.py +++ b/neutron/services/trunk/drivers/base.py @@ -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 diff --git a/neutron/services/trunk/plugin.py b/neutron/services/trunk/plugin.py index f5043de61fd..416ac8b1f1c 100644 --- a/neutron/services/trunk/plugin.py +++ b/neutron/services/trunk/plugin.py @@ -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() diff --git a/neutron/tests/unit/plugins/ml2/drivers/agent/test_capabilities.py b/neutron/tests/unit/plugins/ml2/drivers/agent/test_capabilities.py index 34a2bdfae1c..79f56de8124 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/agent/test_capabilities.py +++ b/neutron/tests/unit/plugins/ml2/drivers/agent/test_capabilities.py @@ -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()