Skip to content

Commit e569358

Browse files
Bugfix: Change query_dict for _template modules to choose devicetype_id (#300)
1 parent 9abb60b commit e569358

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

plugins/module_utils/netbox_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,6 @@ 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-
672668
elif parent == "rear_port_template" and self.endpoint == "front_port_templates":
673669
if isinstance(module_data.get("rear_port_template"), str):
674670
rear_port_template = {
@@ -677,6 +673,10 @@ def _build_query_params(
677673
}
678674
query_dict.update(rear_port_template)
679675

676+
elif "_template" in parent:
677+
if query_dict.get("device_type"):
678+
query_dict["devicetype_id"] = query_dict.pop("device_type")
679+
680680
query_dict = self._convert_identical_keys(query_dict)
681681
return query_dict
682682

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,72 @@
330330
"devicetype_id": 1
331331
}
332332
},
333+
{
334+
"parent": "console_port_template",
335+
"module_data": {
336+
"name": "CP 1",
337+
"device_type": 1
338+
},
339+
"expected": {
340+
"name": "CP 1",
341+
"devicetype_id": 1
342+
}
343+
},
344+
{
345+
"parent": "console_server_port_template",
346+
"module_data": {
347+
"name": "CP - Server 1",
348+
"device_type": 1
349+
},
350+
"expected": {
351+
"name": "CP - Server 1",
352+
"devicetype_id": 1
353+
}
354+
},
355+
{
356+
"parent": "interface_template",
357+
"module_data": {
358+
"name": "Dev Intf 1",
359+
"device_type": 1
360+
},
361+
"expected": {
362+
"name": "Dev Intf 1",
363+
"devicetype_id": 1
364+
}
365+
},
366+
{
367+
"parent": "front_port_template",
368+
"module_data": {
369+
"name": "FP 1",
370+
"device_type": 1
371+
},
372+
"expected": {
373+
"name": "FP 1",
374+
"devicetype_id": 1
375+
}
376+
},
377+
{
378+
"parent": "power_outlet_template",
379+
"module_data": {
380+
"name": "PO 1",
381+
"device_type": 1
382+
},
383+
"expected": {
384+
"name": "PO 1",
385+
"devicetype_id": 1
386+
}
387+
},
388+
{
389+
"parent": "power_port_template",
390+
"module_data": {
391+
"name": "PP 1",
392+
"device_type": 1
393+
},
394+
"expected": {
395+
"name": "PP 1",
396+
"devicetype_id": 1
397+
}
398+
},
333399
{
334400
"parent": "virtual_machine",
335401
"module_data": {

0 commit comments

Comments
 (0)