Skip to content

Commit 44a3176

Browse files
committed
tidy tunnel_group code and tests
1 parent 6339c4b commit 44a3176

File tree

6 files changed

+41
-16
lines changed

6 files changed

+41
-16
lines changed

plugins/modules/netbox_tunnel.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
encapsulation:
4848
description:
4949
- The encapsulation protocol or technique employed to effect the tunnel
50-
required: false
50+
required: true
5151
type: raw
5252
ipsec_profile:
5353
description:
@@ -101,7 +101,6 @@
101101
netbox_token: thisIsMyToken
102102
data:
103103
name: Test Tunnel
104-
status: active
105104
encapsulation: ipsec-tunnel
106105
state: present
107106
@@ -111,6 +110,7 @@
111110
netbox_token: thisIsMyToken
112111
data:
113112
name: Test Tunnel
113+
encapsulation: ipsec-tunnel
114114
state: absent
115115
116116
- name: Create tunnel with all information
@@ -127,7 +127,7 @@
127127
tenant: Test Tenant
128128
tunnel_id: 200
129129
tags:
130-
- test
130+
- Schnozzberry
131131
state: present
132132
"""
133133

@@ -167,7 +167,16 @@ def main():
167167
name=dict(required=True, type="str"),
168168
status=dict(required=False, type="raw"),
169169
tunnel_group=dict(required=False, type="raw"),
170-
encapsulation=dict(required=False, type="raw"),
170+
encapsulation=dict(
171+
required=True,
172+
type="str",
173+
choices=[
174+
"ipsec-transport",
175+
"ipsec-tunnel",
176+
"ip-ip",
177+
"gre",
178+
],
179+
),
171180
ipsec_profile=dict(required=False, type="raw"),
172181
tenant=dict(required=False, type="raw"),
173182
tunnel_id=dict(required=False, type="int"),
@@ -180,7 +189,9 @@ def main():
180189
)
181190
)
182191

183-
required_if = [("state", "present", ["name"]), ("state", "absent", ["name"])]
192+
required_if = [("state", "present", ["name", "encapsulation"]),
193+
("state", "absent", ["name", "encapsulation"]),
194+
]
184195

185196
module = NetboxAnsibleModule(
186197
argument_spec=argument_spec, supports_check_mode=True, required_if=required_if

plugins/modules/netbox_tunnel_group.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
module: netbox_tunnel_group
1313
short_description: Create, update or delete tunnel groups within NetBox
1414
description:
15-
- Creates, updates or deletes tunnel groups from NetBox
15+
- Creates, updates or deletes tunnel groups within NetBox
1616
notes:
1717
- Tags should be defined as a YAML list
1818
- This should be ran with connection C(local) and hosts C(localhost)
@@ -35,6 +35,12 @@
3535
- The name of the tunnel group
3636
required: true
3737
type: str
38+
slug:
39+
description:
40+
- The slugified version of the name or custom slug.
41+
- This is auto-generated following NetBox rules if not provided
42+
required: false
43+
type: str
3844
description:
3945
description:
4046
- The description of the tunnel group
@@ -65,15 +71,15 @@
6571
netbox_url: http://netbox.local
6672
netbox_token: thisIsMyToken
6773
data:
68-
name: Test Cluster Group
74+
name: Test Tunnel Group
6975
state: present
7076
7177
- name: Delete tunnel group within netbox
7278
netbox.netbox.netbox_tunnel_group:
7379
netbox_url: http://netbox.local
7480
netbox_token: thisIsMyToken
7581
data:
76-
name: Test Cluster Group
82+
name: Test Tunnel Group
7783
state: absent
7884
"""
7985

@@ -111,6 +117,7 @@ def main():
111117
required=True,
112118
options=dict(
113119
name=dict(required=True, type="str"),
120+
slug=dict(required=False, type="str"),
114121
description=dict(required=False, type="str"),
115122
tags=dict(required=False, type="list", elements="raw"),
116123
custom_fields=dict(required=False, type="dict"),

tests/integration/targets/v3.7/tasks/netbox_tunnel.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
netbox_token: "0123456789abcdef0123456789abcdef01234567"
5353
data:
5454
name: Test Tunnel
55+
encapsulation: ipsec-tunnel
5556
description: Test Description
5657
tenant: Test Tenant
5758
tunnel_id: 200
@@ -73,6 +74,7 @@
7374
- test_three['tunnel']['tunnel_id'] == 200
7475
- test_three['tunnel']['description'] == "Test Description"
7576
- test_three['tunnel']['tags'][0] == 4
77+
- test_three['tunnel']['encapsulation'] == "ipsec-tunnel"
7678
- test_three['msg'] == "tunnel Test Tunnel updated"
7779

7880
- name: "TUNNEL 4: Delete"
@@ -81,6 +83,7 @@
8183
netbox_token: "0123456789abcdef0123456789abcdef01234567"
8284
data:
8385
name: Test Tunnel
86+
encapsulation: ipsec-tunnel
8487
state: absent
8588
register: test_four
8689

tests/integration/targets/v3.7/tasks/netbox_tunnel_group.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- name: "TUNNEL_GROUP 1: Necessary info creation"
88
netbox.netbox.netbox_tunnel_group:
99
netbox_url: http://localhost:32768
10-
netbox_token: "6bd1da4f7657a0748667f64b5786710383627d9a"
10+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
1111
data:
1212
name: Test Tunnel Group
1313
state: present
@@ -26,7 +26,7 @@
2626
- name: "TUNNEL_GROUP 2: Create duplicate"
2727
netbox.netbox.netbox_tunnel_group:
2828
netbox_url: http://localhost:32768
29-
netbox_token: "6bd1da4f7657a0748667f64b5786710383627d9a"
29+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
3030
data:
3131
name: Test Tunnel Group
3232
state: present
@@ -43,7 +43,7 @@
4343
- name: "TUNNEL_GROUP 3: Update Existing"
4444
netbox.netbox.netbox_tunnel_group:
4545
netbox_url: http://localhost:32768
46-
netbox_token: "6bd1da4f7657a0748667f64b5786710383627d9a"
46+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
4747
data:
4848
name: Test Tunnel Group
4949
description: Test Description
@@ -59,14 +59,15 @@
5959
- test_three['diff']['after']['description'] == "Test Description"
6060
- test_three['diff']['after']['tags'][0] == 4
6161
- test_three['tunnel_group']['name'] == "Test Tunnel Group"
62+
- test_three['tunnel_group']['slug'] == "test-tunnel-group"
6263
- test_three['tunnel_group']['description'] == "Test Description"
6364
- test_three['tunnel_group']['tags'][0] == 4
6465
- test_three['msg'] == "tunnel_group Test Tunnel Group updated"
6566

6667
- name: "TUNNEL_GROUP 4: Delete"
6768
netbox.netbox.netbox_tunnel_group:
6869
netbox_url: http://localhost:32768
69-
netbox_token: "6bd1da4f7657a0748667f64b5786710383627d9a"
70+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
7071
data:
7172
name: Test Tunnel Group
7273
state: absent

tests/integration/targets/v4.0/tasks/netbox_tunnel.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
netbox_token: "0123456789abcdef0123456789abcdef01234567"
5353
data:
5454
name: Test Tunnel
55+
encapsulation: ipsec-tunnel
5556
description: Test Description
5657
tenant: Test Tenant
5758
tunnel_id: 200
@@ -73,6 +74,7 @@
7374
- test_three['tunnel']['tunnel_id'] == 200
7475
- test_three['tunnel']['description'] == "Test Description"
7576
- test_three['tunnel']['tags'][0] == 4
77+
- test_three['tunnel']['encapsulation'] == "ipsec-tunnel"
7678
- test_three['msg'] == "tunnel Test Tunnel updated"
7779

7880
- name: "TUNNEL 4: Delete"
@@ -81,6 +83,7 @@
8183
netbox_token: "0123456789abcdef0123456789abcdef01234567"
8284
data:
8385
name: Test Tunnel
86+
encapsulation: ipsec-tunnel
8487
state: absent
8588
register: test_four
8689

tests/integration/targets/v4.0/tasks/netbox_tunnel_group.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- name: "TUNNEL_GROUP 1: Necessary info creation"
88
netbox.netbox.netbox_tunnel_group:
99
netbox_url: http://localhost:32768
10-
netbox_token: "6bd1da4f7657a0748667f64b5786710383627d9a"
10+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
1111
data:
1212
name: Test Tunnel Group
1313
state: present
@@ -26,7 +26,7 @@
2626
- name: "TUNNEL_GROUP 2: Create duplicate"
2727
netbox.netbox.netbox_tunnel_group:
2828
netbox_url: http://localhost:32768
29-
netbox_token: "6bd1da4f7657a0748667f64b5786710383627d9a"
29+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
3030
data:
3131
name: Test Tunnel Group
3232
state: present
@@ -43,7 +43,7 @@
4343
- name: "TUNNEL_GROUP 3: Update Existing"
4444
netbox.netbox.netbox_tunnel_group:
4545
netbox_url: http://localhost:32768
46-
netbox_token: "6bd1da4f7657a0748667f64b5786710383627d9a"
46+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
4747
data:
4848
name: Test Tunnel Group
4949
description: Test Description
@@ -66,7 +66,7 @@
6666
- name: "TUNNEL_GROUP 4: Delete"
6767
netbox.netbox.netbox_tunnel_group:
6868
netbox_url: http://localhost:32768
69-
netbox_token: "6bd1da4f7657a0748667f64b5786710383627d9a"
69+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
7070
data:
7171
name: Test Tunnel Group
7272
state: absent

0 commit comments

Comments
 (0)