From f50e59caf3f9b1bde107b2ca47c5fb7e26587e56 Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Wed, 21 Oct 2015 17:47:47 -0700 Subject: [PATCH] Minor improvement in port_bound operation By returning the need for binding, the (no-op) port processing is skipped in the main sync loop. In fact, the port is already detected as deleted and avoiding going over it again will save us one log message, and thus many, many, many, many bytes over time in logs.openstack.org. If this is not an improvement, I don't what is. Related-bug: 1455320 Change-Id: I4ef30bed6a1619f5980c3e61ee23ffb808c2c4f0 --- .../ml2/drivers/openvswitch/agent/ovs_neutron_agent.py | 10 ++++++---- .../openvswitch/agent/test_ovs_neutron_agent.py | 7 +++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py index 4fb4099fe..5d34b4fb9 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py @@ -804,7 +804,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, LOG.error(_LE("Expected port %s not found"), port.vif_id) else: LOG.debug("Unable to get config for port %s", port.vif_id) - return + return False vlan_mapping = {'net_uuid': net_uuid, 'network_type': network_type, @@ -814,6 +814,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, port_other_config.update(vlan_mapping) self.int_br.set_db_attribute("Port", port.port_name, "other_config", port_other_config) + return True def _bind_devices(self, need_binding_ports): devices_up = [] @@ -1276,9 +1277,10 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, "and might not be able to transmit"), vif_port.vif_id) if vif_port: if admin_state_up: - self.port_bound(vif_port, network_id, network_type, - physical_network, segmentation_id, - fixed_ips, device_owner, ovs_restarted) + port_needs_binding = self.port_bound( + vif_port, network_id, network_type, + physical_network, segmentation_id, + fixed_ips, device_owner, ovs_restarted) else: self.port_dead(vif_port) port_needs_binding = False diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py index 0e5761d25..0a2b68fd4 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py @@ -165,16 +165,19 @@ class TestOvsNeutronAgent(object): with mock.patch.object(self.agent, 'int_br', autospec=True) as int_br: int_br.db_get_val.return_value = db_get_val int_br.set_db_attribute.return_value = True - self.agent.port_bound(port, net_uuid, 'local', None, None, - fixed_ips, "compute:None", False) + needs_binding = self.agent.port_bound( + port, net_uuid, 'local', None, None, + fixed_ips, "compute:None", False) if db_get_val is None: self.assertEqual(0, int_br.set_db_attribute.call_count) + self.assertFalse(needs_binding) else: vlan_mapping = {'net_uuid': net_uuid, 'network_type': 'local', 'physical_network': None} int_br.set_db_attribute.assert_called_once_with( "Port", mock.ANY, "other_config", vlan_mapping) + self.assertTrue(needs_binding) def test_datapath_type_system(self): # verify kernel datapath is default -- 2.45.2