From 13031159ae4930a04228beb1076005496ee16fb4 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Fri, 17 Nov 2023 10:18:51 +0100 Subject: [PATCH] Properly detect changes to Netbox SNMP profiles The ipdevpoll-internal Netbox data structure needs to be udpated when the netbox' preferred SNMP profile has changed in the database, to ensure we can still communicate with the netbox. This is simply done by comparing the new computed `snmp_parameters` attribute. But, we must also remember to actually store the new value in the Netbox.copy() method. --- python/nav/ipdevpoll/dataloader.py | 2 +- python/nav/ipdevpoll/shadows/netbox.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/python/nav/ipdevpoll/dataloader.py b/python/nav/ipdevpoll/dataloader.py index 8eefd5355f..b37a56dbb9 100644 --- a/python/nav/ipdevpoll/dataloader.py +++ b/python/nav/ipdevpoll/dataloader.py @@ -178,9 +178,9 @@ def is_netbox_changed(netbox1, netbox2): 'type', 'up', 'snmp_up', + 'snmp_parameters', 'deleted_at', ): - # TODO Need some way to detect an updated SNMP profile if getattr(netbox1, attr) != getattr(netbox2, attr): _logger.debug( "%s.%s changed from %r to %r", diff --git a/python/nav/ipdevpoll/shadows/netbox.py b/python/nav/ipdevpoll/shadows/netbox.py index bc4ccb19e2..59d07599fb 100644 --- a/python/nav/ipdevpoll/shadows/netbox.py +++ b/python/nav/ipdevpoll/shadows/netbox.py @@ -62,13 +62,15 @@ def is_up(self): return self.up == manage.Netbox.UP_UP def copy(self, other): + """In addition to copying the 'official' attrs of another Netbox object, + this also copies 'computed'/'internal' attributes that are only part of the + Netbox shadow class definition. + """ super(Netbox, self).copy(other) for attr in ( "snmp_up", "last_updated", - "snmp_version", - "read_only", - "read_write", + "snmp_parameters", ): if hasattr(other, attr): setattr(self, attr, getattr(other, attr))