Merge "use payloads for all PORT_DEVICE events"
This commit is contained in:
commit
0951e846c1
|
@ -308,10 +308,11 @@ class CommonAgentLoop(service.Service):
|
|||
device_details['port_id'],
|
||||
device_details['device'])
|
||||
self.ext_manager.handle_port(self.context, device_details)
|
||||
registry.notify(local_resources.PORT_DEVICE,
|
||||
events.AFTER_UPDATE, self,
|
||||
context=self.context,
|
||||
device_details=device_details)
|
||||
registry.publish(local_resources.PORT_DEVICE,
|
||||
events.AFTER_UPDATE, self,
|
||||
payload=events.DBEventPayload(
|
||||
self.context, states=(device_details,),
|
||||
resource_id=device))
|
||||
elif c_const.NO_ACTIVE_BINDING in device_details:
|
||||
LOG.info("Device %s has no active binding in host", device)
|
||||
else:
|
||||
|
@ -355,9 +356,10 @@ class CommonAgentLoop(service.Service):
|
|||
LOG.exception("Error occurred while processing extensions "
|
||||
"for port removal %s", device)
|
||||
resync = True
|
||||
registry.notify(local_resources.PORT_DEVICE, events.AFTER_DELETE,
|
||||
self, context=self.context, device=device,
|
||||
port_id=port_id)
|
||||
registry.publish(local_resources.PORT_DEVICE, events.AFTER_DELETE,
|
||||
self, payload=events.DBEventPayload(
|
||||
self.context, states=(details,),
|
||||
resource_id=device))
|
||||
self.mgr.delete_arp_spoofing_protection(devices)
|
||||
return resync
|
||||
|
||||
|
|
|
@ -74,8 +74,7 @@ class LinuxBridgeTrunkDriver(trunk_rpc.TrunkSkeleton):
|
|||
|
||||
@registry.receives(local_resources.PORT_DEVICE,
|
||||
[local_events.AFTER_DELETE])
|
||||
def agent_port_delete(self, resource, event, trigger, context, port_id,
|
||||
**kwargs):
|
||||
def agent_port_delete(self, resource, event, trigger, payload=None):
|
||||
"""Agent informed us a VIF was removed."""
|
||||
# NOTE(kevinbenton): we don't need to do anything to cleanup VLAN
|
||||
# interfaces if a trunk was removed because the kernel will do that
|
||||
|
@ -85,17 +84,17 @@ class LinuxBridgeTrunkDriver(trunk_rpc.TrunkSkeleton):
|
|||
|
||||
@registry.receives(local_resources.PORT_DEVICE,
|
||||
[local_events.AFTER_UPDATE])
|
||||
def agent_port_change(self, resource, event, trigger, context,
|
||||
device_details, **kwargs):
|
||||
def agent_port_change(self, resource, event, trigger, payload=None):
|
||||
"""The agent hath informed us thusly of a port update or create."""
|
||||
trunk = self._tapi.get_trunk(context, device_details['port_id'])
|
||||
port_id = payload.latest_state['port_id']
|
||||
trunk = self._tapi.get_trunk(payload.context, port_id)
|
||||
if trunk:
|
||||
# a wild trunk has appeared! make its children
|
||||
self.wire_trunk(context, trunk)
|
||||
self.wire_trunk(payload.context, trunk)
|
||||
return
|
||||
# clear any VLANs in case this was a trunk that changed status while
|
||||
# agent was offline.
|
||||
self._plumber.delete_subports_by_port_id(device_details['port_id'])
|
||||
self._plumber.delete_subports_by_port_id(port_id)
|
||||
|
||||
def wire_trunk(self, context, trunk):
|
||||
"""Wire up subports while keeping the server trunk status apprised."""
|
||||
|
|
|
@ -77,8 +77,7 @@ class TestCommonAgentLoop(base.BaseTestCase):
|
|||
devices = [DEVICE_1]
|
||||
self.agent.treat_devices_removed(devices)
|
||||
handler.assert_called_once_with(mock.ANY, mock.ANY, self.agent,
|
||||
context=mock.ANY, device=DEVICE_1,
|
||||
port_id=mock.ANY)
|
||||
payload=mock.ANY)
|
||||
|
||||
def test_treat_devices_added_updated_notify(self):
|
||||
handler = mock.Mock()
|
||||
|
@ -98,8 +97,11 @@ class TestCommonAgentLoop(base.BaseTestCase):
|
|||
agent.mgr.plug_interface.return_value = True
|
||||
agent.treat_devices_added_updated(set(['dev123']))
|
||||
handler.assert_called_once_with(mock.ANY, mock.ANY, self.agent,
|
||||
context=mock.ANY,
|
||||
device_details=mock_details)
|
||||
payload=mock.ANY)
|
||||
|
||||
payload = handler.mock_calls[0][2]['payload']
|
||||
self.assertDictEqual(mock_details, payload.latest_state)
|
||||
self.assertEqual(mock_details['device'], payload.resource_id)
|
||||
|
||||
def test_treat_devices_removed_with_existed_device(self):
|
||||
agent = self.agent
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
from neutron_lib.callbacks import events as cb_events
|
||||
import oslo_messaging
|
||||
from oslo_utils import uuidutils
|
||||
import testtools
|
||||
|
@ -85,8 +86,10 @@ class LinuxBridgeTrunkDriverTestCase(base.BaseTestCase):
|
|||
|
||||
def test_agent_port_change_is_trunk(self):
|
||||
self.tapi.get_trunk.return_value = self.trunk
|
||||
self.lbd.agent_port_change('resource', 'event', 'trigger', 'context',
|
||||
{'port_id': self.trunk.port_id})
|
||||
self.lbd.agent_port_change(
|
||||
'resource', 'event', 'trigger', payload=cb_events.DBEventPayload(
|
||||
'context', states=({'port_id': self.trunk.port_id},),
|
||||
resource_id=self.trunk.port_id))
|
||||
# should have tried to wire trunk
|
||||
self.plumber.trunk_on_host.assert_called_once_with(self.trunk)
|
||||
|
||||
|
@ -94,17 +97,22 @@ class LinuxBridgeTrunkDriverTestCase(base.BaseTestCase):
|
|||
self.tapi.get_trunk.return_value = None
|
||||
self.tapi.get_trunk_for_subport.return_value = None
|
||||
other_port_id = uuidutils.generate_uuid()
|
||||
self.lbd.agent_port_change('resource', 'event', 'trigger', 'context',
|
||||
{'port_id': other_port_id})
|
||||
self.lbd.agent_port_change(
|
||||
'resource', 'event', 'trigger', payload=cb_events.DBEventPayload(
|
||||
'context', states=({'port_id': other_port_id},),
|
||||
resource_id=other_port_id))
|
||||
self.plumber.delete_subports_by_port_id.assert_called_once_with(
|
||||
other_port_id)
|
||||
|
||||
def test_agent_port_change_is_subport(self):
|
||||
self.tapi.get_trunk.return_value = None
|
||||
self.tapi.get_trunk_for_subport.return_value = self.trunk
|
||||
self.lbd.agent_port_change('resource', 'event', 'trigger', 'context',
|
||||
{'port_id': self.trunk.sub_ports[0].port_id,
|
||||
'mac_address': 'mac_addr'})
|
||||
port_dev = {'port_id': self.trunk.sub_ports[0].port_id,
|
||||
'mac_address': 'mac_addr'}
|
||||
self.lbd.agent_port_change(
|
||||
'resource', 'event', 'trigger', payload=cb_events.DBEventPayload(
|
||||
'context', states=(port_dev,),
|
||||
resource_id=port_dev['port_id']))
|
||||
self.plumber.delete_subports_by_port_id.assert_called_once_with(
|
||||
self.trunk.sub_ports[0].port_id)
|
||||
|
||||
|
|
Loading…
Reference in New Issue