Skip to content

Commit 9bdafac

Browse files
Bugfix: Fix netbox_service to use protocol for allowed_query_params (#175)
1 parent b6f6ba8 commit 9bdafac

File tree

4 files changed

+77
-11
lines changed

4 files changed

+77
-11
lines changed

plugins/module_utils/netbox_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
"region": set(["slug"]),
216216
"rir": set(["slug"]),
217217
"role": set(["slug"]),
218-
"services": set(["device", "virtual_machine", "name", "port"]),
218+
"services": set(["device", "virtual_machine", "name", "port", "protocol"]),
219219
"site": set(["slug"]),
220220
"tagged_vlans": set(["name", "site", "vlan_group", "tenant"]),
221221
"tenant": set(["slug"]),

tests/integration/v2.6/tasks/netbox_service.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
- test_service_idempotence['services']['port'] == 9100
5959
- test_service_idempotence['services']['protocol'] == 6
6060
- test_service_idempotence['msg'] == "services node-exporter already exists"
61+
6162
- name: "NETBOX_SERVICE: Test update"
6263
netbox_service:
6364
netbox_url: "http://localhost:32768"
@@ -66,19 +67,19 @@
6667
device: "FOR_SERVICE"
6768
name: "node-exporter"
6869
port: 9100
69-
protocol: UDP
70+
description: "Service updated"
71+
protocol: TCP
7072
state: present
7173
register: test_service_update
7274

7375
- name: "NETBOX_SERVICE ASSERT - Service has been updated"
7476
assert:
7577
that:
7678
- test_service_update is changed
77-
- test_service_update['diff']['before']['protocol'] == 6
78-
- test_service_update['diff']['after']['protocol'] == 17
79+
- test_service_update['diff']['after']['description'] == "Service updated"
7980
- test_service_update['msg'] == "services node-exporter updated"
8081

81-
- name: "NETBOX_SERVICE: Test service deletion"
82+
- name: "NETBOX_SERVICE: Test same details, but different protocol - Create"
8283
netbox_service:
8384
netbox_url: "http://localhost:32768"
8485
netbox_token: "0123456789abcdef0123456789abcdef01234567"
@@ -87,6 +88,29 @@
8788
name: "node-exporter"
8889
port: 9100
8990
protocol: UDP
91+
state: present
92+
register: test_service_protocol
93+
94+
- name: "NETBOX_SERVICE ASSERT - Different protocol - Create"
95+
assert:
96+
that:
97+
- test_service_protocol is changed
98+
- test_service_protocol['diff']['after']['state'] == "present"
99+
- test_service_protocol['diff']['before']['state'] == "absent"
100+
- test_service_protocol['services']['name'] == "node-exporter"
101+
- test_service_protocol['services']['port'] == 9100
102+
- test_service_protocol['services']['protocol'] == 17
103+
- test_service_protocol['msg'] == "services node-exporter created"
104+
105+
- name: "NETBOX_SERVICE: Test service deletion"
106+
netbox_service:
107+
netbox_url: "http://localhost:32768"
108+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
109+
data:
110+
device: "FOR_SERVICE"
111+
name: "node-exporter"
112+
port: 9100
113+
protocol: TCP
90114
state: absent
91115
register: test_service_delete
92116

tests/integration/v2.7/tasks/netbox_service.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
device: "FOR_SERVICE"
6868
name: "node-exporter"
6969
port: 9100
70-
protocol: UDP
70+
protocol: TCP
7171
tags:
7272
- "Schnozzberry"
7373
state: present
@@ -77,11 +77,32 @@
7777
assert:
7878
that:
7979
- test_service_update is changed
80-
- test_service_update['diff']['before']['protocol'] == "tcp"
81-
- test_service_update['diff']['after']['protocol'] == "udp"
8280
- test_service_update['diff']['after']['tags'][0] == "Schnozzberry"
8381
- test_service_update['msg'] == "services node-exporter updated"
8482

83+
- name: "NETBOX_SERVICE: Test same details, but different protocol - Create"
84+
netbox_service:
85+
netbox_url: "http://localhost:32768"
86+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
87+
data:
88+
device: "FOR_SERVICE"
89+
name: "node-exporter"
90+
port: 9100
91+
protocol: UDP
92+
state: present
93+
register: test_service_protocol
94+
95+
- name: "NETBOX_SERVICE ASSERT - Different protocol - Create"
96+
assert:
97+
that:
98+
- test_service_protocol is changed
99+
- test_service_protocol['diff']['after']['state'] == "present"
100+
- test_service_protocol['diff']['before']['state'] == "absent"
101+
- test_service_protocol['services']['name'] == "node-exporter"
102+
- test_service_protocol['services']['port'] == 9100
103+
- test_service_protocol['services']['protocol'] == "udp"
104+
- test_service_protocol['msg'] == "services node-exporter created"
105+
85106
- name: "NETBOX_SERVICE: Test service deletion"
86107
netbox_service:
87108
netbox_url: "http://localhost:32768"

tests/integration/v2.8/tasks/netbox_service.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
device: "FOR_SERVICE"
6868
name: "node-exporter"
6969
port: 9100
70-
protocol: UDP
70+
protocol: TCP
7171
tags:
7272
- "Schnozzberry"
7373
state: present
@@ -77,11 +77,32 @@
7777
assert:
7878
that:
7979
- test_service_update is changed
80-
- test_service_update['diff']['before']['protocol'] == "tcp"
81-
- test_service_update['diff']['after']['protocol'] == "udp"
8280
- test_service_update['diff']['after']['tags'][0] == "Schnozzberry"
8381
- test_service_update['msg'] == "services node-exporter updated"
8482

83+
- name: "NETBOX_SERVICE: Test same details, but different protocol - Create"
84+
netbox_service:
85+
netbox_url: "http://localhost:32768"
86+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
87+
data:
88+
device: "FOR_SERVICE"
89+
name: "node-exporter"
90+
port: 9100
91+
protocol: UDP
92+
state: present
93+
register: test_service_protocol
94+
95+
- name: "NETBOX_SERVICE ASSERT - Different protocol - Create"
96+
assert:
97+
that:
98+
- test_service_protocol is changed
99+
- test_service_protocol['diff']['after']['state'] == "present"
100+
- test_service_protocol['diff']['before']['state'] == "absent"
101+
- test_service_protocol['services']['name'] == "node-exporter"
102+
- test_service_protocol['services']['port'] == 9100
103+
- test_service_protocol['services']['protocol'] == "udp"
104+
- test_service_protocol['msg'] == "services node-exporter created"
105+
85106
- name: "NETBOX_SERVICE: Test service deletion"
86107
netbox_service:
87108
netbox_url: "http://localhost:32768"

0 commit comments

Comments
 (0)