From: Dermot Tynan Date: Fri, 20 Feb 2015 16:57:33 +0000 (+0000) Subject: Make del_fdb_flow() idempotent. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=841b2f58f375df53b380cf5796bb31c82cd09260;p=openstack-build%2Fneutron-build.git Make del_fdb_flow() idempotent. Addresses an issue where del_fdb_flow() gets a duplicate call for the same port, which results in a KeyError. This change makes the call more idempotent, so that it doesn't cause other follow-on errors as a result of the uncaught exception. Change-Id: I7a3a34dd654e143dee06c3e4642e859211a312ca Closes-bug: #1421105 --- diff --git a/neutron/plugins/ofagent/agent/ofa_neutron_agent.py b/neutron/plugins/ofagent/agent/ofa_neutron_agent.py index e6d66d67e..a36aa9257 100644 --- a/neutron/plugins/ofagent/agent/ofa_neutron_agent.py +++ b/neutron/plugins/ofagent/agent/ofa_neutron_agent.py @@ -394,6 +394,9 @@ class OFANeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, def del_fdb_flow(self, br, port_info, remote_ip, lvm, ofport): if port_info == n_const.FLOODING_ENTRY: + if ofport not in lvm.tun_ofports: + LOG.debug("attempt to remove a non-existent port %s", ofport) + return lvm.tun_ofports.remove(ofport) if len(lvm.tun_ofports) > 0: br.install_tunnel_output( diff --git a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py index a500187ba..81d4ab514 100644 --- a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py @@ -425,6 +425,9 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, def del_fdb_flow(self, br, port_info, remote_ip, lvm, ofport): if port_info == q_const.FLOODING_ENTRY: + if ofport not in lvm.tun_ofports: + LOG.debug("attempt to remove a non-existent port %s", ofport) + return lvm.tun_ofports.remove(ofport) if len(lvm.tun_ofports) > 0: ofports = _ofport_set_to_str(lvm.tun_ofports) diff --git a/neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py b/neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py index e97f24195..03463d35d 100644 --- a/neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py @@ -863,6 +863,21 @@ class TestOvsNeutronAgent(base.BaseTestCase): self.assertEqual(len(expected_calls), len(do_action_flows_fn.mock_calls)) + def test_del_fdb_flow_idempotency(self): + lvm = mock.Mock() + lvm.network_type = 'gre' + lvm.vlan = 'vlan1' + lvm.segmentation_id = 'seg1' + lvm.tun_ofports = set(['1', '2']) + with contextlib.nested( + mock.patch.object(self.agent.tun_br, 'mod_flow'), + mock.patch.object(self.agent.tun_br, 'delete_flows') + ) as (mod_flow_fn, delete_flows_fn): + self.agent.del_fdb_flow(self.agent.tun_br, n_const.FLOODING_ENTRY, + '1.1.1.1', lvm, '3') + self.assertFalse(mod_flow_fn.called) + self.assertFalse(delete_flows_fn.called) + def test_recl_lv_port_to_preserve(self): self._prepare_l2_pop_ofports() self.agent.l2_pop = True