use callback payloads for BEFORE_READ events

This patch switches callbacks over to the payload object style events
[1] for BEFORE_READ based notifications. To do so an EventPayload object
is used with the publish() method to pass along the API related data.
In addition a few UTs are updated to work with the changes.

NeutronLibImpact

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

Change-Id: Iff3e96c56867b4bf4272fed676f39cd6796d756c
changes/02/528102/5
Boden R 5 years ago committed by garyk
parent 3f1a9846d2
commit bfd499445c
  1. 6
      neutron/plugins/ml2/drivers/openvswitch/mech_driver/mech_openvswitch.py
  2. 5
      neutron/services/trunk/drivers/openvswitch/driver.py
  3. 2
      neutron/tests/unit/plugins/ml2/drivers/openvswitch/mech_driver/test_mech_openvswitch.py
  4. 13
      neutron/tests/unit/services/trunk/drivers/openvswitch/test_driver.py

@ -121,9 +121,9 @@ class OpenvswitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
def set_bridge_name_inner(bridge_name):
vif_details[portbindings.VIF_DETAILS_BRIDGE_NAME] = bridge_name
registry.notify(
a_const.OVS_BRIDGE_NAME, events.BEFORE_READ,
set_bridge_name_inner, port=port)
registry.publish(a_const.OVS_BRIDGE_NAME, events.BEFORE_READ,
set_bridge_name_inner, payload=events.EventPayload(
None, metadata={'port': port}))
def _pre_get_vif_details(self, agent, context):
a_config = agent['configurations']

@ -68,8 +68,9 @@ def register():
LOG.debug('Open vSwitch trunk driver registered')
def vif_details_bridge_name_handler(resource, event, set_br_name, **kwargs):
def vif_details_bridge_name_handler(resource, event, set_br_name,
payload=None):
"""If port is a trunk port, generate a bridge_name for its vif_details."""
port = kwargs['port']
port = payload.metadata['port']
if 'trunk_details' in port:
set_br_name(utils.gen_trunk_br_name(port['trunk_details']['trunk_id']))

@ -67,7 +67,7 @@ class OpenvswitchMechanismBaseTestCase(base.AgentMechanismBaseTestCase):
def test__set_bridge_name_notify(self):
def fake_callback(resource, event, trigger, **kwargs):
def fake_callback(resource, event, trigger, payload=None):
trigger('fake-br-name')
registry.subscribe(fake_callback, a_const.OVS_BRIDGE_NAME,

@ -60,7 +60,14 @@ class OVSDriverTestCase(base.BaseTestCase):
driver.register()
mock_gen_br_name.return_value = 'fake-trunk-br-name'
test_trigger = mock.Mock()
registry.notify(agent_consts.OVS_BRIDGE_NAME, events.BEFORE_READ,
test_trigger, **{'port': {'trunk_details':
{'trunk_id': 'foo'}}})
registry.publish(agent_consts.OVS_BRIDGE_NAME, events.BEFORE_READ,
test_trigger,
payload=events.EventPayload(
None, metadata={
'port': {
'trunk_details': {
'trunk_id': 'foo'
}
}
}))
test_trigger.assert_called_once_with('fake-trunk-br-name')

Loading…
Cancel
Save