]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
ofagent: Ignore unknown l2pop entry removals
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>
Fri, 15 Aug 2014 05:20:00 +0000 (14:20 +0900)
committerYAMAMOTO Takashi <yamamoto@valinux.co.jp>
Tue, 16 Sep 2014 06:46:07 +0000 (06:46 +0000)
l2pop can send us entry removal without the corresponding addition.
Gracefully ignore it instead of crashing.

Closes-Bug: #1357198
Change-Id: I5a0cc44ba62faf15d6fe3730a9532a3826647820

neutron/plugins/ofagent/agent/arp_lib.py
neutron/tests/unit/ofagent/test_arp_lib.py

index c83e94352874e1bbed1238eb7fb634400b35ccf3..aeae8f3588b6aade0514658bb73544df32cb42a9 100644 (file)
@@ -120,7 +120,12 @@ class ArpLib(object):
 
     @log.log
     def del_arp_table_entry(self, network, ip):
-        del self._arp_tbl[network][ip]
+        if network not in self._arp_tbl:
+            LOG.debug("removal of unknown network %s", network)
+            return
+        if self._arp_tbl[network].pop(ip, None) is None:
+            LOG.debug("removal of unknown ip %s", ip)
+            return
         if not self._arp_tbl[network]:
             del self._arp_tbl[network]
 
index a0b0dcdafc31a75800dc427739e37244576ef849..45c1193628d1ec010ff2cb089de916b4298c8a56 100644 (file)
@@ -16,6 +16,7 @@
 
 import collections
 import contextlib
+import copy
 
 import mock
 
@@ -203,6 +204,22 @@ class TestArpLib(OFAAgentTestCase):
         self.arplib.del_arp_table_entry(self.nets[0].net, self.nets[0].ip)
         self.assertEqual(self.arplib._arp_tbl, {})
 
+    def test_del_arp_table_entry_unknown_network(self):
+        self.arplib._arp_tbl = {
+            100: {"192.0.2.1": "fa:16:3e:e2:37:37"},
+        }
+        orig = copy.deepcopy(self.arplib._arp_tbl)
+        self.arplib.del_arp_table_entry(200, "192.0.2.1")
+        self.assertEqual(orig, self.arplib._arp_tbl)
+
+    def test_del_arp_table_entry_unknown_ip(self):
+        self.arplib._arp_tbl = {
+            100: {"192.0.2.1": "fa:16:3e:e2:37:37"},
+        }
+        orig = copy.deepcopy(self.arplib._arp_tbl)
+        self.arplib.del_arp_table_entry(100, "192.0.2.9")
+        self.assertEqual(orig, self.arplib._arp_tbl)
+
     def test_del_arp_table_entry_multiple_net(self):
         self.arplib._arp_tbl = {
             self.nets[0].net: {self.nets[0].ip: self.nets[0].mac},