Skip to content

Commit 0b143b0

Browse files
BugFix: If device name is empty string, set UUID, added integration tests as well (#110)
1 parent 7593e6f commit 0b143b0

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

plugins/modules/netbox_device.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@
135135
site: Main
136136
state: present
137137
138+
- name: Create device within Netbox with empty string name to generate UUID
139+
netbox_device:
140+
netbox_url: http://netbox.local
141+
netbox_token: thisIsMyToken
142+
data:
143+
name: ""
144+
device_type: C9410R
145+
device_role: Core Switch
146+
site: Main
147+
state: present
148+
138149
- name: Delete device within netbox
139150
netbox_device:
140151
netbox_url: http://netbox.local
@@ -187,6 +198,7 @@
187198
NetboxDcimModule,
188199
NB_DEVICES,
189200
)
201+
import uuid
190202

191203

192204
def main():
@@ -244,6 +256,8 @@ def main():
244256
module = NetboxAnsibleModule(
245257
argument_spec=argument_spec, supports_check_mode=True, required_if=required_if
246258
)
259+
if module.params["data"]["name"] == "":
260+
module.params["data"]["name"] = str(uuid.uuid4())
247261

248262
netbox_device = NetboxDcimModule(module, NB_DEVICES)
249263
netbox_device.run()

tests/integration/integration-tests.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,32 @@
182182
- test_seven['device']['primary_ip6'] == 2
183183
- test_seven['msg'] == "device test100 updated"
184184

185+
- name: "8 - Device with empty string name"
186+
netbox_device:
187+
netbox_url: "http://localhost:32768"
188+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
189+
data:
190+
name: ""
191+
device_type: "Cisco Test"
192+
device_role: "Core Switch"
193+
site: "Test Site"
194+
status: "Staged"
195+
state: present
196+
register: test_eight
197+
198+
- name: "8 - ASSERT"
199+
assert:
200+
that:
201+
- test_eight is changed
202+
- test_eight['diff']['before']['state'] == 'absent'
203+
- test_eight['diff']['after']['state'] == 'present'
204+
- test_eight['device']['device_role'] == 1
205+
- test_eight['device']['device_type'] == 1
206+
- test_eight['device']['site'] == 1
207+
- test_eight['device']['status'] == 3
208+
- "'-' in test_eight['device']['name']"
209+
- "test_eight['device']['name'] | length == 36"
210+
185211
##
186212
##
187213
### NETBOX_DEVICE_INTERFACE

0 commit comments

Comments
 (0)