Skip to content

Commit

Permalink
Properly detect changes to Netbox SNMP profiles
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lunkwill42 committed Nov 17, 2023
1 parent 03cdad2 commit 1303115
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/nav/ipdevpoll/dataloader.py
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions python/nav/ipdevpoll/shadows/netbox.py
Expand Up @@ -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))
Expand Down

0 comments on commit 1303115

Please sign in to comment.