Skip to content

Commit 20c7406

Browse files
Bugfix: Fixes no endpoint updates if tags are specified (#325)
1 parent ff34e4e commit 20c7406

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

changelogs/fragments/fix_tags.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfix:
2+
- Fix bug introduced by #247 to deal with tags

plugins/module_utils/netbox_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,10 @@ def _update_netbox_object(self, data):
870870
"""
871871
serialized_nb_obj = self.nb_object.serialize()
872872
updated_obj = serialized_nb_obj.copy()
873+
updated_obj.update(data)
873874
if serialized_nb_obj.get("tags") and data.get("tags"):
874875
serialized_nb_obj["tags"] = set(serialized_nb_obj["tags"])
875876
updated_obj["tags"] = set(data["tags"])
876-
else:
877-
updated_obj.update(data)
878877

879878
if serialized_nb_obj == updated_obj:
880879
return serialized_nb_obj, None

tests/integration/targets/regression/tasks/main.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
device_role: "Core Switch"
9191
site: "Test Site"
9292
status: "Staged"
93+
asset_tag: "1234"
9394
tags:
9495
- second
9596
- third
@@ -134,3 +135,27 @@
134135
- test_six.results[3]["diff"]["before"]["state"] == "absent"
135136
- test_six.results[3]["diff"]["after"]["state"] == "present"
136137
- test_six.results[3]["interface_template"]["device_type"] == 3
138+
139+
- name: "7 - Don't prevent updates to other params if tags are specified"
140+
netbox.netbox.netbox_device:
141+
netbox_url: "http://localhost:32768"
142+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
143+
data:
144+
name: "issue-242"
145+
device_type: "Cisco Test"
146+
device_role: "Core Switch"
147+
site: "Test Site"
148+
status: "Staged"
149+
asset_tag: "Null"
150+
tags:
151+
- second
152+
- third
153+
- first
154+
register: test_seven
155+
156+
- name: "5 - Assert added tag - Tests #242 is fixed"
157+
assert:
158+
that:
159+
- test_seven is changed
160+
- test_seven["diff"]["after"]["asset_tag"] == "Null"
161+
- test_seven["device"]["asset_tag"] == "Null"

0 commit comments

Comments
 (0)