]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make del_fdb_flow() idempotent.
authorDermot Tynan <tynan@hp.com>
Fri, 20 Feb 2015 16:57:33 +0000 (16:57 +0000)
committerDermot Tynan <tynan@hp.com>
Fri, 27 Feb 2015 10:46:51 +0000 (10:46 +0000)
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

neutron/plugins/ofagent/agent/ofa_neutron_agent.py
neutron/plugins/openvswitch/agent/ovs_neutron_agent.py
neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py

index e6d66d67ed54a27745a1cca8192c137465f2f7d9..a36aa92575211dabdf56a12eedfdd57f73b2a52c 100644 (file)
@@ -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(
index a500187ba18b4a2819489d8071d353d39e249f40..81d4ab514c3abcc61013703c141bc6c961eed6a1 100644 (file)
@@ -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)
index e97f2419543d2e00f32c734d68f315563dfea149..03463d35d18ccf53a42cb9bc4e234b9b93787237 100644 (file)
@@ -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