Skip to content

Commit 9403a08

Browse files
Bugfix: Change search type for device_bay/interface_template to devicetype_id (#284)
1 parent fd760ea commit 9403a08

File tree

5 files changed

+65
-7
lines changed

5 files changed

+65
-7
lines changed

plugins/module_utils/netbox_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,10 @@ def _build_query_params(
665665
}
666666
query_dict.update(rear_port)
667667

668+
elif parent == "interface_template" or parent == "device_bay_template":
669+
if query_dict.get("device_type"):
670+
query_dict["devicetype_id"] = query_dict.pop("device_type")
671+
668672
elif parent == "rear_port_template" and self.endpoint == "front_port_templates":
669673
if isinstance(module_data.get("rear_port_template"), str):
670674
rear_port_template = {

tests/integration/targets/latest/tasks/netbox_cable.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- test_one['diff']['before']['state'] == "absent"
3131
- test_one['diff']['after']['state'] == "present"
3232
- test_one['cable']['termination_a_type'] == "dcim.interface"
33-
- test_one['cable']['termination_a_id'] == 23
33+
- test_one['cable']['termination_a_id'] == 25
3434
- test_one['cable']['termination_b_type'] == "dcim.interface"
3535
- test_one['cable']['termination_b_id'] == 2
3636
- test_one['msg'] == "cable dcim.interface Ethernet2/2 <> dcim.interface Ethernet2/1 created"
@@ -56,7 +56,7 @@
5656
that:
5757
- not test_two['changed']
5858
- test_two['cable']['termination_a_type'] == "dcim.interface"
59-
- test_two['cable']['termination_a_id'] == 23
59+
- test_two['cable']['termination_a_id'] == 25
6060
- test_two['cable']['termination_b_type'] == "dcim.interface"
6161
- test_two['cable']['termination_b_id'] == 2
6262
- test_two['msg'] == "cable dcim.interface Ethernet2/2 <> dcim.interface Ethernet2/1 already exists"
@@ -94,7 +94,7 @@
9494
- test_three['diff']['after']['length'] == 30
9595
- test_three['diff']['after']['length_unit'] == "m"
9696
- test_three['cable']['termination_a_type'] == "dcim.interface"
97-
- test_three['cable']['termination_a_id'] == 23
97+
- test_three['cable']['termination_a_id'] == 25
9898
- test_three['cable']['termination_b_type'] == "dcim.interface"
9999
- test_three['cable']['termination_b_id'] == 2
100100
- test_three['cable']['type'] == "mmf-om4"
@@ -155,4 +155,4 @@
155155
- test_five['cable']['termination_a_id'] == 1
156156
- test_five['cable']['termination_b_type'] == "dcim.consoleport"
157157
- test_five['cable']['termination_b_id'] == 1
158-
- test_five['msg'] == "cable dcim.consoleserverport Console Server Port <> dcim.consoleport Console Port created"
158+
- test_five['msg'] == "cable dcim.consoleserverport Console Server Port <> dcim.consoleport Console Port created"

tests/integration/targets/latest/tasks/netbox_device_interface.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
- test_five['interface']['enabled'] == false
124124
- test_five['interface']['type'] == "1000base-t"
125125
- test_five['interface']['mgmt_only'] == false
126-
- test_five['interface']['lag'] == 18
126+
- test_five['interface']['lag'] == 20
127127
- test_five['interface']['mode'] == "access"
128128
- test_five['interface']['mtu'] == 1600
129129

@@ -221,7 +221,7 @@
221221
- test_eight['interface']['enabled'] == false
222222
- test_eight['interface']['type'] == "1000base-t"
223223
- test_eight['interface']['mgmt_only'] == false
224-
- test_eight['interface']['lag'] == 18
224+
- test_eight['interface']['lag'] == 20
225225
- test_eight['interface']['mode'] == "access"
226226
- test_eight['interface']['mtu'] == 1600
227227

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,34 @@
103103
- test_five is changed
104104
- test_five["diff"]["after"]["tags"] is defined
105105
- test_five["device"]["tags"] is defined
106+
107+
- name: "6 - Loop through and add interface templates to different device interface templates - Fixes #282"
108+
netbox.netbox.netbox_device_interface_template:
109+
netbox_url: "http://localhost:32768"
110+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
111+
data:
112+
name: "SFP+ (10GE)"
113+
type: "SFP+ (10GE)"
114+
device_type: "{{ item }}"
115+
register: test_six
116+
loop:
117+
- "Cisco Test"
118+
- "Arista Test"
119+
- "Nexus Child"
120+
- "Nexus Parent"
121+
122+
- name: "6 - Assert device type is correct - Fixes #282"
123+
assert:
124+
that:
125+
- test_six.results[0]["diff"]["before"]["state"] == "absent"
126+
- test_six.results[0]["diff"]["after"]["state"] == "present"
127+
- test_six.results[0]["interface_template"]["device_type"] == 1
128+
- test_six.results[1]["diff"]["before"]["state"] == "absent"
129+
- test_six.results[1]["diff"]["after"]["state"] == "present"
130+
- test_six.results[1]["interface_template"]["device_type"] == 2
131+
- test_six.results[2]["diff"]["before"]["state"] == "absent"
132+
- test_six.results[2]["diff"]["after"]["state"] == "present"
133+
- test_six.results[2]["interface_template"]["device_type"] == 4
134+
- test_six.results[3]["diff"]["before"]["state"] == "absent"
135+
- test_six.results[3]["diff"]["after"]["state"] == "present"
136+
- test_six.results[3]["interface_template"]["device_type"] == 3

tests/unit/module_utils/test_data/build_query_params_no_child/data.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,29 @@
307307
"slug": "test-tenant-group"
308308
}
309309
},
310+
{
311+
"parent": "interface_template",
312+
"module_data": {
313+
"device_type": 1,
314+
"name": "SFP+ (10GBE)",
315+
"type": "SFP+ (10GBE)"
316+
},
317+
"expected": {
318+
"name": "SFP+ (10GBE)",
319+
"devicetype_id": 1
320+
}
321+
},
322+
{
323+
"parent": "device_bay_template",
324+
"module_data": {
325+
"name": "Bay 1",
326+
"device_type": 1
327+
},
328+
"expected": {
329+
"name": "Bay 1",
330+
"devicetype_id": 1
331+
}
332+
},
310333
{
311334
"parent": "virtual_machine",
312335
"module_data": {
@@ -318,4 +341,4 @@
318341
"cluster_id": 1
319342
}
320343
}
321-
]
344+
]

0 commit comments

Comments
 (0)