Skip to content

Commit e80041d

Browse files
BugFix: Python 3.8 - Dict iteration error (#163)
1 parent bbed118 commit e80041d

36 files changed

+4345
-4
lines changed

plugins/module_utils/netbox_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,18 @@ def _convert_identical_keys(self, data):
387387
Returns data
388388
:params data (dict): Data dictionary after _find_ids method ran
389389
"""
390+
temp_dict = dict()
390391
if self.version and self.version >= 2.7:
391392
if data.get("form_factor"):
392-
data["type"] = data.pop("form_factor")
393+
temp_dict["type"] = data["form_factor"]
393394
for key in data:
394395
if key in CONVERT_KEYS:
395396
new_key = CONVERT_KEYS[key]
396-
value = data.pop(key)
397-
data[new_key] = value
397+
temp_dict[new_key] = data[key]
398+
else:
399+
temp_dict[key] = data[key]
398400

399-
return data
401+
return temp_dict
400402

401403
def _remove_arg_spec_default(self, data):
402404
"""Used to remove any data keys that were not provided by user, but has the arg spec

tests/integration/v2.8/main.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
- hosts: localhost
3+
connection: local
4+
gather_facts: no
5+
collections:
6+
- netbox.netbox
7+
8+
tasks:
9+
- name: "NETBOX_DEVICE TESTS"
10+
include_tasks: "tasks/netbox_device.yml"
11+
12+
- name: "NETBOX_DEVICE_INTERFACE TESTS"
13+
include_tasks: "tasks/netbox_device_interface.yml"
14+
15+
- name: "NETBOX_IP_ADDRESS TESTS"
16+
include_tasks: "tasks/netbox_ip_address.yml"
17+
18+
- name: "NETBOX_PREFIX TESTS"
19+
include_tasks: "tasks/netbox_prefix.yml"
20+
21+
- name: "NETBOX_SITE TESTS"
22+
include_tasks: "tasks/netbox_site.yml"
23+
24+
- name: "NETBOX_TENTANT TESTS"
25+
include_tasks: "tasks/netbox_tenant.yml"
26+
27+
- name: "NETBOX_TENTANT_GROUP TESTS"
28+
include_tasks: "tasks/netbox_tenant_group.yml"
29+
30+
- name: "NETBOX_RACK TESTS"
31+
include_tasks: "tasks/netbox_rack.yml"
32+
33+
- name: "NETBOX_RACK_ROLE TESTS"
34+
include_tasks: "tasks/netbox_rack_role.yml"
35+
36+
- name: "NETBOX_RACK_GROUP TESTS"
37+
include_tasks: "tasks/netbox_rack_group.yml"
38+
39+
- name: "NETBOX_MANUFACTURER TESTS"
40+
include_tasks: "tasks/netbox_manufacturer.yml"
41+
42+
- name: "NETBOX_PLATFORM TESTS"
43+
include_tasks: "tasks/netbox_platform.yml"
44+
45+
- name: "NETBOX_DEVICE_TYPE TESTS"
46+
include_tasks: "tasks/netbox_device_type.yml"
47+
48+
- name: "NETBOX_DEVICE_ROLE TESTS"
49+
include_tasks: "tasks/netbox_device_role.yml"
50+
51+
- name: "NETBOX_IPAM_ROLE TESTS"
52+
include_tasks: "tasks/netbox_ipam_role.yml"
53+
54+
- name: "NETBOX_VLAN_GROUP TESTS"
55+
include_tasks: "tasks/netbox_vlan_group.yml"
56+
57+
- name: "NETBOX_VLAN TESTS"
58+
include_tasks: "tasks/netbox_vlan.yml"
59+
60+
- name: "NETBOX_VRF TESTS"
61+
include_tasks: "tasks/netbox_vrf.yml"
62+
63+
- name: "NETBOX_RIR TESTS"
64+
include_tasks: "tasks/netbox_rir.yml"
65+
66+
- name: "NETBOX_AGGREGATE TESTS"
67+
include_tasks: "tasks/netbox_aggregate.yml"
68+
69+
- name: "NETBOX_REGION TESTS"
70+
include_tasks: "tasks/netbox_region.yml"
71+
72+
- name: "NETBOX_DEVICE_BAY TESTS"
73+
include_tasks: "tasks/netbox_device_bay.yml"
74+
75+
- name: "NETBOX_INVENTORY_ITEM TESTS"
76+
include_tasks: "tasks/netbox_inventory_item.yml"
77+
78+
- name: "NETBOX_VIRTUAL_MACHINE TESTS"
79+
include_tasks: "tasks/netbox_virtual_machine.yml"
80+
81+
- name: "NETBOX_CLUSTER TESTS"
82+
include_tasks: "tasks/netbox_cluster.yml"
83+
84+
- name: "NETBOX_CLUSTER_GROUP TESTS"
85+
include_tasks: "tasks/netbox_cluster_group.yml"
86+
87+
- name: "NETBOX_CLUSTER_TYPE TESTS"
88+
include_tasks: "tasks/netbox_cluster_type.yml"
89+
90+
- name: "NETBOX_VM_INTERFACE TESTS"
91+
include_tasks: "tasks/netbox_vm_interface.yml"
92+
93+
- name: "NETBOX_PROVIDER TESTS"
94+
include_tasks: "tasks/netbox_provider.yml"
95+
96+
- name: "NETBOX_CIRCUIT_TYPE TESTS"
97+
include_tasks: "tasks/netbox_circuit_type.yml"
98+
99+
- name: "NETBOX_CIRCUIT TESTS"
100+
include_tasks: "tasks/netbox_circuit.yml"
101+
102+
- name: "NETBOX_CIRCUIT_TERMINATION TESTS"
103+
include_tasks: "tasks/netbox_circuit_termination.yml"
104+
105+
- name: "NETBOX_SERVICE TESTS"
106+
include_tasks: "tasks/netbox_service.yml"
107+
108+
- name: "NETBOX_LOOKUP TESTS"
109+
include_tasks: "tasks/netbox_lookup.yml"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
##
3+
##
4+
### NETBOX_AGGEGATE
5+
##
6+
##
7+
- name: "AGGREGATE 1: Necessary info creation"
8+
netbox_aggregate:
9+
netbox_url: http://localhost:32768
10+
netbox_token: 0123456789abcdef0123456789abcdef01234567
11+
data:
12+
prefix: "10.0.0.0/8"
13+
rir: "Example RIR"
14+
state: present
15+
register: test_one
16+
17+
- name: "AGGREGATE 1: ASSERT - Necessary info creation"
18+
assert:
19+
that:
20+
- test_one is changed
21+
- test_one['diff']['before']['state'] == "absent"
22+
- test_one['diff']['after']['state'] == "present"
23+
- test_one['aggregate']['prefix'] == "10.0.0.0/8"
24+
- test_one['aggregate']['family'] == 4
25+
- test_one['aggregate']['rir'] == 1
26+
- test_one['msg'] == "aggregate 10.0.0.0/8 created"
27+
28+
- name: "AGGREGATE 2: Create duplicate"
29+
netbox_aggregate:
30+
netbox_url: http://localhost:32768
31+
netbox_token: 0123456789abcdef0123456789abcdef01234567
32+
data:
33+
prefix: "10.0.0.0/8"
34+
state: present
35+
register: test_two
36+
37+
- name: "AGGREGATE 2: ASSERT - Create duplicate"
38+
assert:
39+
that:
40+
- not test_two['changed']
41+
- test_two['aggregate']['prefix'] == "10.0.0.0/8"
42+
- test_two['aggregate']['family'] == 4
43+
- test_two['aggregate']['rir'] == 1
44+
- test_two['msg'] == "aggregate 10.0.0.0/8 already exists"
45+
46+
- name: "AGGREGATE 3: ASSERT - Update"
47+
netbox_aggregate:
48+
netbox_url: http://localhost:32768
49+
netbox_token: 0123456789abcdef0123456789abcdef01234567
50+
data:
51+
prefix: "10.0.0.0/8"
52+
rir: "Example RIR"
53+
date_added: "1989-01-18"
54+
description: "Test Description"
55+
tags:
56+
- Schnozzberry
57+
state: present
58+
register: test_three
59+
60+
- name: "AGGREGATE 3: ASSERT - Updated"
61+
assert:
62+
that:
63+
- test_three is changed
64+
- test_three['diff']['after']['date_added'] == "1989-01-18"
65+
- test_three['diff']['after']['description'] == "Test Description"
66+
- test_three['diff']['after']['tags'][0] == "Schnozzberry"
67+
- test_three['aggregate']['prefix'] == "10.0.0.0/8"
68+
- test_three['aggregate']['family'] == 4
69+
- test_three['aggregate']['rir'] == 1
70+
- test_three['aggregate']['date_added'] == "1989-01-18"
71+
- test_three['aggregate']['description'] == "Test Description"
72+
- test_three['aggregate']['tags'][0] == "Schnozzberry"
73+
- test_three['msg'] == "aggregate 10.0.0.0/8 updated"
74+
75+
- name: "AGGREGATE 4: ASSERT - Delete"
76+
netbox_aggregate:
77+
netbox_url: http://localhost:32768
78+
netbox_token: 0123456789abcdef0123456789abcdef01234567
79+
data:
80+
prefix: "10.0.0.0/8"
81+
state: absent
82+
register: test_four
83+
84+
- name: "AGGREGATE 4: ASSERT - Delete"
85+
assert:
86+
that:
87+
- test_four is changed
88+
- test_four['aggregate']['prefix'] == "10.0.0.0/8"
89+
- test_four['aggregate']['family'] == 4
90+
- test_four['aggregate']['rir'] == 1
91+
- test_four['aggregate']['date_added'] == "1989-01-18"
92+
- test_four['aggregate']['description'] == "Test Description"
93+
- test_four['aggregate']['tags'][0] == "Schnozzberry"
94+
- test_four['msg'] == "aggregate 10.0.0.0/8 deleted"
95+
96+
- name: "AGGREGATE 5: Necessary info creation"
97+
netbox_aggregate:
98+
netbox_url: http://localhost:32768
99+
netbox_token: 0123456789abcdef0123456789abcdef01234567
100+
data:
101+
prefix: "2001::/32"
102+
rir: "Example RIR"
103+
state: present
104+
register: test_five
105+
106+
- name: "AGGREGATE 5: ASSERT - Necessary info creation"
107+
assert:
108+
that:
109+
- test_five is changed
110+
- test_five['diff']['before']['state'] == "absent"
111+
- test_five['diff']['after']['state'] == "present"
112+
- test_five['aggregate']['prefix'] == "2001::/32"
113+
- test_five['aggregate']['family'] == 6
114+
- test_five['aggregate']['rir'] == 1
115+
- test_five['msg'] == "aggregate 2001::/32 created"
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
##
3+
##
4+
### NETBOX_CIRCUIT
5+
##
6+
##
7+
- name: "NETBOX_CIRCUIT 1: Create provider within Netbox with only required information"
8+
netbox_circuit:
9+
netbox_url: http://localhost:32768
10+
netbox_token: 0123456789abcdef0123456789abcdef01234567
11+
data:
12+
cid: Test Circuit One
13+
provider: Test Provider
14+
circuit_type: Test Circuit Type
15+
state: present
16+
register: test_one
17+
18+
- name: "NETBOX_CIRCUIT 1: ASSERT - Necessary info creation"
19+
assert:
20+
that:
21+
- test_one is changed
22+
- test_one['diff']['before']['state'] == "absent"
23+
- test_one['diff']['after']['state'] == "present"
24+
- test_one['circuit']['cid'] == "Test Circuit One"
25+
- test_one['circuit']['provider'] == 1
26+
- test_one['circuit']['type'] == 1
27+
- test_one['msg'] == "circuit Test Circuit One created"
28+
29+
- name: "NETBOX_CIRCUIT 2: Duplicate"
30+
netbox_circuit:
31+
netbox_url: http://localhost:32768
32+
netbox_token: 0123456789abcdef0123456789abcdef01234567
33+
data:
34+
cid: Test Circuit One
35+
provider: Test Provider
36+
circuit_type: Test Circuit Type
37+
state: present
38+
register: test_two
39+
40+
- name: "NETBOX_CIRCUIT 2: ASSERT - Create duplicate"
41+
assert:
42+
that:
43+
- not test_two['changed']
44+
- test_two['circuit']['cid'] == "Test Circuit One"
45+
- test_two['circuit']['provider'] == 1
46+
- test_two['circuit']['type'] == 1
47+
- test_two['msg'] == "circuit Test Circuit One already exists"
48+
49+
- name: "NETBOX_CIRCUIT 3: Update provider with other fields"
50+
netbox_circuit:
51+
netbox_url: http://localhost:32768
52+
netbox_token: 0123456789abcdef0123456789abcdef01234567
53+
data:
54+
cid: Test Circuit One
55+
provider: Test Provider
56+
circuit_type: Test Circuit Type
57+
status: Planned
58+
tenant: Test Tenant
59+
install_date: "2018-12-25"
60+
commit_rate: 10000
61+
description: Test circuit
62+
comments: "FAST CIRCUIT"
63+
state: present
64+
register: test_three
65+
66+
- name: "NETBOX_CIRCUIT 3: ASSERT - Updated"
67+
assert:
68+
that:
69+
- test_three is changed
70+
- test_three['diff']['after']['status'] == "planned"
71+
- test_three['diff']['after']['tenant'] == 1
72+
- test_three['diff']['after']['install_date'] == "2018-12-25"
73+
- test_three['diff']['after']['commit_rate'] == 10000
74+
- test_three['diff']['after']['description'] == "Test circuit"
75+
- test_three['diff']['after']['comments'] == "FAST CIRCUIT"
76+
- test_three['circuit']['cid'] == "Test Circuit One"
77+
- test_three['circuit']['provider'] == 1
78+
- test_three['circuit']['type'] == 1
79+
- test_three['circuit']['status'] == "planned"
80+
- test_three['circuit']['tenant'] == 1
81+
- test_three['circuit']['install_date'] == "2018-12-25"
82+
- test_three['circuit']['commit_rate'] == 10000
83+
- test_three['circuit']['description'] == "Test circuit"
84+
- test_three['circuit']['comments'] == "FAST CIRCUIT"
85+
- test_three['msg'] == "circuit Test Circuit One updated"
86+
87+
- name: "NETBOX_CIRCUIT 4: Delete provider within netbox"
88+
netbox_circuit:
89+
netbox_url: http://localhost:32768
90+
netbox_token: 0123456789abcdef0123456789abcdef01234567
91+
data:
92+
cid: Test Circuit One
93+
state: absent
94+
register: test_four
95+
96+
- name: "NETBOX_CIRCUIT 4 : ASSERT - Delete"
97+
assert:
98+
that:
99+
- test_four is changed
100+
- test_four['circuit']['cid'] == "Test Circuit One"
101+
- test_four['circuit']['provider'] == 1
102+
- test_four['circuit']['type'] == 1
103+
- test_four['circuit']['status'] == "planned"
104+
- test_four['circuit']['tenant'] == 1
105+
- test_four['circuit']['install_date'] == "2018-12-25"
106+
- test_four['circuit']['commit_rate'] == 10000
107+
- test_four['circuit']['description'] == "Test circuit"
108+
- test_four['circuit']['comments'] == "FAST CIRCUIT"
109+
- test_four['msg'] == "circuit Test Circuit One deleted"

0 commit comments

Comments
 (0)