Skip to content

Commit e98a0d7

Browse files
authored
Bugfix: Make a copy of ipaddress before modifying to not break caching. (#277)
1 parent 98e105e commit e98a0d7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

plugins/inventory/nb_inventory.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,13 @@ def refresh_ipaddresses(self):
831831
interface_id = ipaddress["interface"]["id"]
832832
ip_id = ipaddress["id"]
833833

834-
self.ipaddresses_lookup[interface_id][ip_id] = ipaddress
834+
# We need to copy the ipaddress entry to preserve the original in case caching is used.
835+
ipaddress_copy = ipaddress.copy()
836+
837+
self.ipaddresses_lookup[interface_id][ip_id] = ipaddress_copy
835838

836839
# Remove "interface" attribute, as that's redundant when ipaddress is added to an interface
837-
del ipaddress["interface"]
840+
del ipaddress_copy["interface"]
838841

839842
@property
840843
def lookup_processes(self):

tests/integration/targets/inventory/files/test-inventory-options-flatten.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ api_endpoint: "http://localhost:32768"
33
token: "0123456789abcdef0123456789abcdef01234567"
44
validate_certs: False
55

6+
# Use cache on this test to make sure interfaces is tested via the cache
7+
cache: True
8+
cache_timeout: 3600
9+
cache_plugin: jsonfile
10+
cache_connection: /tmp/inventory_netbox
11+
12+
613
config_context: True
714
flatten_config_context: True
815
flatten_custom_fields: True

0 commit comments

Comments
 (0)