Skip to content

Commit 71b7814

Browse files
committed
Skip ARP collection if ARP already collected
This ensures that the SNMP-based `arp` plugin exits early if it appears that some other plugin has already collected Arp records before it. This makes the `arp` plugin a sort of fallback in a scenario where vendor specific ARP collection plugins run first, rather than having multiple ARP plugin step on each others toes.
1 parent b37d4a5 commit 71b7814

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

python/nav/ipdevpoll/plugins/arp.py

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def can_handle(cls, netbox):
7070
@defer.inlineCallbacks
7171
def handle(self):
7272
yield self._check_and_update_prefix_cache()
73+
if self._is_arp_already_collected():
74+
self._logger.debug("ARP records already collected for this device")
75+
return
7376
self._logger.debug("Collecting IP/MAC mappings")
7477

7578
# Fetch standard MIBs
@@ -103,6 +106,10 @@ def _check_and_update_prefix_cache(cls):
103106
if prefix_cache_age > cls.prefix_cache_max_age:
104107
yield cls._update_prefix_cache()
105108

109+
def _is_arp_already_collected(self):
110+
"""Returns True if ARP entries have already been collected in this run"""
111+
return shadows.Arp in self.containers and bool(self.containers[shadows.Arp])
112+
106113
@defer.inlineCallbacks
107114
def _get_ip_mib(self):
108115
if not self.is_arista():

tests/unittests/ipdevpoll/plugins_arp_test.py

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
import pytest_twisted
66

7+
from nav.ipdevpoll import shadows
78
from nav.ipdevpoll.storage import ContainerRepository
89
from nav.ipdevpoll.plugins.arp import ipv6_address_in_mappings, Arp
910

@@ -35,3 +36,15 @@ def test_make_new_mappings_should_not_raise_on_empty_ip():
3536
a = Arp(None, None, ContainerRepository())
3637
mappings = [(None, '00:0b:ad:c0:ff:ee')]
3738
a._make_new_mappings(mappings)
39+
40+
41+
def test_when_arp_records_exist_is_arp_already_collected_should_return_true():
42+
containers = ContainerRepository()
43+
containers.factory(('192.168.0.1', '00:co:ff:ee:ba:be'), shadows.Arp)
44+
plugin = Arp(None, None, containers)
45+
assert plugin._is_arp_already_collected()
46+
47+
48+
def test_when_arp_records_do_not_exist_is_arp_already_collected_should_return_false():
49+
plugin = Arp(None, None, ContainerRepository())
50+
assert not plugin._is_arp_already_collected()

0 commit comments

Comments
 (0)