From e2a99fa3c456a57e6e74e53ab04ad4899d1a9cf2 Mon Sep 17 00:00:00 2001 From: Darragh O'Reilly Date: Tue, 2 Dec 2014 18:28:38 +0000 Subject: [PATCH] lb-agent: handle security group updates in main loop Patch I1574544734865506ff5383404516cc9349c16ec4 introduced deferring firewall refreshes to the main loop of the ovs-agent to improve performance. This patch enables the same on the linuxbridge agent. Change-Id: Ia8fe229910d2be718da52cb341be163b86ace571 Closes-Bug: #1368281 --- .../linuxbridge/agent/linuxbridge_neutron_agent.py | 12 +++++------- .../agent/test_linuxbridge_neutron_agent.py | 9 ++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py index 66be308a2..d539fe38f 100644 --- a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -788,7 +788,7 @@ class LinuxBridgeNeutronAgentRPC(service.Service): self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN) self.sg_plugin_rpc = sg_rpc.SecurityGroupServerRpcApi(topics.PLUGIN) self.sg_agent = sg_rpc.SecurityGroupAgentRpc(self.context, - self.sg_plugin_rpc) + self.sg_plugin_rpc, defer_refresh_firewall=True) self.setup_rpc(self.interface_mappings.values()) self.daemon_loop() @@ -859,11 +859,8 @@ class LinuxBridgeNeutronAgentRPC(service.Service): resync_a = False resync_b = False - self.sg_agent.prepare_devices_filter(device_info.get('added')) - - if device_info.get('updated'): - self.sg_agent.refresh_firewall() - + self.sg_agent.setup_port_filters(device_info.get('added'), + device_info.get('updated')) # Updated devices are processed the same as new ones, as their # admin_state_up may have changed. The set union prevents duplicating # work when a device is new and updated in the same polling iteration. @@ -1011,7 +1008,8 @@ class LinuxBridgeNeutronAgentRPC(service.Service): LOG.info(_LI("Agent out of sync with plugin!")) sync = False - if self._device_info_has_changes(device_info): + if (self._device_info_has_changes(device_info) + or self.sg_agent.firewall_refresh_needed()): LOG.debug("Agent loop found changes! %s", device_info) try: sync = self.process_network_devices(device_info) diff --git a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py index 8651a14d8..134b313ee 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py @@ -279,16 +279,15 @@ class TestLinuxBridgeAgent(base.BaseTestCase): 'added': set(['tap3', 'tap4']), 'updated': set(['tap2', 'tap3']), 'removed': set(['tap1'])} - agent.sg_agent.prepare_devices_filter = mock.Mock() - agent.sg_agent.refresh_firewall = mock.Mock() + agent.sg_agent.setup_port_filters = mock.Mock() agent.treat_devices_added_updated = mock.Mock(return_value=False) agent.treat_devices_removed = mock.Mock(return_value=False) agent.process_network_devices(device_info) - agent.sg_agent.prepare_devices_filter.assert_called_with( - set(['tap3', 'tap4'])) - self.assertTrue(agent.sg_agent.refresh_firewall.called) + agent.sg_agent.setup_port_filters.assert_called_with( + device_info['added'], + device_info['updated']) agent.treat_devices_added_updated.assert_called_with(set(['tap2', 'tap3', 'tap4'])) -- 2.45.2