Skip to content

Commit becc534

Browse files
authored
Fix sevral integration tests failure (#1439)
* Fix service creation Add netbox version check to support service creation for netbox version prior of 4.3 * Fix netbox version check for rack Use dedicated function to check netbox version istead of self.full_version for rack. * Fix typos in tag integration tests * Fix interaction test circuit termination missing assignment since version 4.2 * Fix interaction test circuit termination missing assignment for V4.3 * Fix Typo in netbox_circuit_termination and netbox_service integration test * Add Changelog
1 parent 77e28f8 commit becc534

File tree

8 files changed

+87
-41
lines changed

8 files changed

+87
-41
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bugfixes:
2+
- Add netbox version check to support service creation for netbox version prior of 4.3
3+
- Use dedicated function to check netbox version istead of self.full_version for rack.
4+
- Fix typos in tag integration tests.
5+
- Fix integration test for circuit termination, missing assignment
6+
- Fix integration test for service

plugins/module_utils/netbox_dcim.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
__metaclass__ = type
88

9-
from ansible.module_utils.basic import missing_required_lib
109
from ansible_collections.netbox.netbox.plugins.module_utils.netbox_utils import (
1110
NetboxModule,
1211
ENDPOINT_NAME_MAPPING,
@@ -53,22 +52,9 @@
5352
NB_VIRTUAL_CHASSIS = "virtual_chassis"
5453
NB_MAC_ADDRESSES = "mac_addresses"
5554

56-
try:
57-
from packaging.version import Version
58-
59-
HAS_PACKAGING = True
60-
PACKAGING_IMPORT_ERROR = ""
61-
except ImportError as imp_exc:
62-
PACKAGING_IMPORT_ERROR = imp_exc
63-
HAS_PACKAGING = False
64-
6555

6656
class NetboxDcimModule(NetboxModule):
6757
def __init__(self, module, endpoint):
68-
if not HAS_PACKAGING:
69-
module.fail_json(
70-
msg=missing_required_lib("packaging"), exception=PACKAGING_IMPORT_ERROR
71-
)
7258
super().__init__(module, endpoint)
7359

7460
def run(self):
@@ -128,7 +114,7 @@ def run(self):
128114

129115
# Handle rack and form_factor
130116
if endpoint_name == "rack":
131-
if Version(self.full_version) >= Version("4.1.0"):
117+
if self._version_check_greater(self.version, "4.1", greater_or_equal=True):
132118
if "type" in data:
133119
data["form_factor"] = self._to_slug(data["type"])
134120
del data["type"]
@@ -207,7 +193,7 @@ def run(self):
207193
data["color"] = data["color"].lower()
208194

209195
if self.endpoint == "cables":
210-
if Version(self.full_version) >= Version("3.0.6"):
196+
if self._version_check_greater(self.version, "3.0", greater_or_equal=True):
211197
cables = [
212198
nb_endpoint.get(
213199
termination_a_type=data["termination_a_type"],
@@ -236,7 +222,7 @@ def run(self):
236222
else:
237223
self._handle_errors(msg="More than one result returned for %s" % (name))
238224

239-
if Version(self.full_version) >= Version("3.3.0"):
225+
if self._version_check_greater(self.version, "3.3", greater_or_equal=True):
240226
data["a_terminations"] = [
241227
{
242228
"object_id": data.pop("termination_a_id"),

plugins/module_utils/netbox_ipam.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ def run(self):
216216
if not data.get("slug"):
217217
data["slug"] = self._to_slug(name)
218218

219-
if self.endpoint == "services":
219+
if self.endpoint == "services" and self._version_check_greater(
220+
self.version, "4.3", greater_or_equal=True
221+
):
220222
if "device" in data:
221223
data["parent_object_type"] = "dcim.device"
222224
data["parent_object_id"] = data["device"]

tests/integration/targets/v4.2/tasks/netbox_circuit_termination.yml

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@
44
### NETBOX_CIRCUIT_TERMINATION
55
##
66
##
7+
- name: "NETBOX_CIRCUIT_TERMINATION 0: Create provider network within NetBox with only required information"
8+
netbox.netbox.netbox_provider_network:
9+
netbox_url: http://localhost:32768
10+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
11+
data:
12+
provider: Test Provider
13+
name: Test Provider Network One
14+
state: present
15+
register: test_one
16+
17+
- name: "NETBOX_CIRCUIT_TERMINATION 0: ASSERT - Necessary info creation"
18+
ansible.builtin.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['provider_network']['name'] == "Test Provider Network One"
24+
- test_one['msg'] == "provider_network Test Provider Network One created"
25+
726
- name: "NETBOX_CIRCUIT_TERMINATION 1: Create provider within NetBox with only required information"
827
netbox.netbox.netbox_circuit_termination:
928
netbox_url: http://localhost:32768
1029
netbox_token: "0123456789abcdef0123456789abcdef01234567"
1130
data:
1231
circuit: Test Circuit
1332
term_side: A
14-
site: Test Site
33+
termination_id: 2
34+
termination_type: circuits.providernetwork
1535
port_speed: 10000
1636
state: present
1737
register: test_one
@@ -22,9 +42,10 @@
2242
- test_one is changed
2343
- test_one['diff']['before']['state'] == "absent"
2444
- test_one['diff']['after']['state'] == "present"
45+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
46+
- test_one['circuit_termination']['termination_id'] == 2
2547
- test_one['circuit_termination']['circuit'] == 1
2648
- test_one['circuit_termination']['term_side'] == "A"
27-
- test_one['circuit_termination']['site'] == 1
2849
- test_one['circuit_termination']['port_speed'] == 10000
2950
- test_one['msg'] == "circuit_termination test_circuit_a created"
3051

@@ -42,9 +63,10 @@
4263
ansible.builtin.assert:
4364
that:
4465
- not test_two['changed']
66+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
67+
- test_one['circuit_termination']['termination_id'] == 2
4568
- test_two['circuit_termination']['circuit'] == 1
4669
- test_two['circuit_termination']['term_side'] == "A"
47-
- test_two['circuit_termination']['site'] == 1
4870
- test_two['circuit_termination']['port_speed'] == 10000
4971
- test_two['msg'] == "circuit_termination test_circuit_a already exists"
5072

@@ -66,13 +88,14 @@
6688
ansible.builtin.assert:
6789
that:
6890
- test_three is changed
91+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
92+
- test_one['circuit_termination']['termination_id'] == 2
6993
- test_three['diff']['after']['upstream_speed'] == 1000
7094
- test_three['diff']['after']['xconnect_id'] == "10X100"
7195
- test_three['diff']['after']['pp_info'] == "PP10-24"
7296
- test_three['diff']['after']['description'] == "Test description"
7397
- test_three['circuit_termination']['circuit'] == 1
7498
- test_three['circuit_termination']['term_side'] == "A"
75-
- test_three['circuit_termination']['site'] == 1
7699
- test_three['circuit_termination']['port_speed'] == 10000
77100
- test_three['circuit_termination']['upstream_speed'] == 1000
78101
- test_three['circuit_termination']['xconnect_id'] == "10X100"
@@ -87,7 +110,8 @@
87110
data:
88111
circuit: Test Circuit
89112
term_side: Z
90-
site: Test Site
113+
termination_id: 2
114+
termination_type: circuits.providernetwork
91115
port_speed: 10000
92116
state: present
93117
register: test_four
@@ -98,9 +122,10 @@
98122
- test_four is changed
99123
- test_four['diff']['before']['state'] == "absent"
100124
- test_four['diff']['after']['state'] == "present"
125+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
126+
- test_one['circuit_termination']['termination_id'] == 2
101127
- test_four['circuit_termination']['circuit'] == 1
102128
- test_four['circuit_termination']['term_side'] == "Z"
103-
- test_four['circuit_termination']['site'] == 1
104129
- test_four['circuit_termination']['port_speed'] == 10000
105130
- test_four['msg'] == "circuit_termination test_circuit_z created"
106131

@@ -120,10 +145,11 @@
120145
- test_five is changed
121146
- test_five['circuit_termination']['circuit'] == 1
122147
- test_five['circuit_termination']['term_side'] == "A"
123-
- test_five['circuit_termination']['site'] == 1
124148
- test_five['circuit_termination']['port_speed'] == 10000
125149
- test_five['circuit_termination']['upstream_speed'] == 1000
126150
- test_five['circuit_termination']['xconnect_id'] == "10X100"
127151
- test_five['circuit_termination']['pp_info'] == "PP10-24"
128152
- test_five['circuit_termination']['description'] == "Test description"
153+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
154+
- test_one['circuit_termination']['termination_id'] == 2
129155
- test_five['msg'] == "circuit_termination test_circuit_a deleted"

tests/integration/targets/v4.2/tasks/netbox_service.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
netbox_token: "0123456789abcdef0123456789abcdef01234567"
179179
data:
180180
virtual_machine: test100-vm
181-
name: node-exporter
181+
name: node-exporter-vm
182182
port: 9100
183183
protocol: TCP
184184
state: present
@@ -188,9 +188,9 @@
188188
ansible.builtin.assert:
189189
that:
190190
- test_service_create_vm is changed
191-
- test_service_create_vm['services']['name'] == "node-exporter"
191+
- test_service_create_vm['services']['name'] == "node-exporter-vm"
192192
- test_service_create_vm['services']['ports'] == [9100]
193193
- test_service_create_vm['services']['protocol'] == "tcp"
194194
- test_service_create_vm['diff']['after']['state'] == "present"
195195
- test_service_create_vm['diff']['before']['state'] == "absent"
196-
- test_service_create_vm['msg'] == "services node-exporter created"
196+
- test_service_create_vm['msg'] == "services node-exporter-vm created"

tests/integration/targets/v4.2/tasks/netbox_tag.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
description: Tag 1 test
1414
color: "0000ff"
1515
object_types:
16-
- ipem.prefix
16+
- ipam.prefix
1717
state: present
1818
register: test_one
1919

@@ -27,7 +27,7 @@
2727
- test_one['tags']['description'] == "Tag 1 test"
2828
- test_one['tags']['name'] == "Test Tag 1"
2929
- test_one['tags']['slug'] == "test-tag-1"
30-
- test_one['tags']['object_types'][0] = "ipam.prefix"
30+
- test_one['tags']['object_types'][0] == "ipam.prefix"
3131
- test_one['msg'] == "tags Test Tag 1 created"
3232

3333
- name: "TAG 2: Create duplicate"
@@ -70,7 +70,7 @@
7070
- test_three['tags']['name'] == "Test Tag 1"
7171
- test_three['tags']['description'] == "Tag 1 update test"
7272
- test_three['tags']['color'] == "00ff00"
73-
-test_three['tags']['object_types'][0] == "ipam.asn"
73+
- test_three['tags']['object_types'][0] == "ipam.asn"
7474
- test_three['msg'] == "tags Test Tag 1 updated"
7575

7676
- name: "TAG 4: ASSERT - Delete"

tests/integration/targets/v4.3/tasks/netbox_circuit_termination.yml

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@
44
### NETBOX_CIRCUIT_TERMINATION
55
##
66
##
7+
- name: "NETBOX_CIRCUIT_TERMINATION 0: Create provider network within NetBox with only required information"
8+
netbox.netbox.netbox_provider_network:
9+
netbox_url: http://localhost:32768
10+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
11+
data:
12+
provider: Test Provider
13+
name: Test Provider Network One
14+
state: present
15+
register: test_one
16+
17+
- name: "NETBOX_CIRCUIT_TERMINATION 0: ASSERT - Necessary info creation"
18+
ansible.builtin.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['provider_network']['name'] == "Test Provider Network One"
24+
- test_one['msg'] == "provider_network Test Provider Network One created"
25+
726
- name: "NETBOX_CIRCUIT_TERMINATION 1: Create provider within NetBox with only required information"
827
netbox.netbox.netbox_circuit_termination:
928
netbox_url: http://localhost:32768
1029
netbox_token: "0123456789abcdef0123456789abcdef01234567"
1130
data:
1231
circuit: Test Circuit
1332
term_side: A
14-
site: Test Site
33+
termination_id: 2
34+
termination_type: circuits.providernetwork
1535
port_speed: 10000
1636
state: present
1737
register: test_one
@@ -22,9 +42,10 @@
2242
- test_one is changed
2343
- test_one['diff']['before']['state'] == "absent"
2444
- test_one['diff']['after']['state'] == "present"
45+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
46+
- test_one['circuit_termination']['termination_id'] == 2
2547
- test_one['circuit_termination']['circuit'] == 1
2648
- test_one['circuit_termination']['term_side'] == "A"
27-
- test_one['circuit_termination']['site'] == 1
2849
- test_one['circuit_termination']['port_speed'] == 10000
2950
- test_one['msg'] == "circuit_termination test_circuit_a created"
3051

@@ -42,9 +63,10 @@
4263
ansible.builtin.assert:
4364
that:
4465
- not test_two['changed']
66+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
67+
- test_one['circuit_termination']['termination_id'] == 2
4568
- test_two['circuit_termination']['circuit'] == 1
4669
- test_two['circuit_termination']['term_side'] == "A"
47-
- test_two['circuit_termination']['site'] == 1
4870
- test_two['circuit_termination']['port_speed'] == 10000
4971
- test_two['msg'] == "circuit_termination test_circuit_a already exists"
5072

@@ -66,13 +88,14 @@
6688
ansible.builtin.assert:
6789
that:
6890
- test_three is changed
91+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
92+
- test_one['circuit_termination']['termination_id'] == 2
6993
- test_three['diff']['after']['upstream_speed'] == 1000
7094
- test_three['diff']['after']['xconnect_id'] == "10X100"
7195
- test_three['diff']['after']['pp_info'] == "PP10-24"
7296
- test_three['diff']['after']['description'] == "Test description"
7397
- test_three['circuit_termination']['circuit'] == 1
7498
- test_three['circuit_termination']['term_side'] == "A"
75-
- test_three['circuit_termination']['site'] == 1
7699
- test_three['circuit_termination']['port_speed'] == 10000
77100
- test_three['circuit_termination']['upstream_speed'] == 1000
78101
- test_three['circuit_termination']['xconnect_id'] == "10X100"
@@ -87,7 +110,8 @@
87110
data:
88111
circuit: Test Circuit
89112
term_side: Z
90-
site: Test Site
113+
termination_id: 2
114+
termination_type: circuits.providernetwork
91115
port_speed: 10000
92116
state: present
93117
register: test_four
@@ -98,9 +122,10 @@
98122
- test_four is changed
99123
- test_four['diff']['before']['state'] == "absent"
100124
- test_four['diff']['after']['state'] == "present"
125+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
126+
- test_one['circuit_termination']['termination_id'] == 2
101127
- test_four['circuit_termination']['circuit'] == 1
102128
- test_four['circuit_termination']['term_side'] == "Z"
103-
- test_four['circuit_termination']['site'] == 1
104129
- test_four['circuit_termination']['port_speed'] == 10000
105130
- test_four['msg'] == "circuit_termination test_circuit_z created"
106131

@@ -120,10 +145,11 @@
120145
- test_five is changed
121146
- test_five['circuit_termination']['circuit'] == 1
122147
- test_five['circuit_termination']['term_side'] == "A"
123-
- test_five['circuit_termination']['site'] == 1
124148
- test_five['circuit_termination']['port_speed'] == 10000
125149
- test_five['circuit_termination']['upstream_speed'] == 1000
126150
- test_five['circuit_termination']['xconnect_id'] == "10X100"
127151
- test_five['circuit_termination']['pp_info'] == "PP10-24"
128152
- test_five['circuit_termination']['description'] == "Test description"
153+
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
154+
- test_one['circuit_termination']['termination_id'] == 2
129155
- test_five['msg'] == "circuit_termination test_circuit_a deleted"

tests/integration/targets/v4.3/tasks/netbox_service.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
netbox_token: "0123456789abcdef0123456789abcdef01234567"
179179
data:
180180
virtual_machine: test100-vm
181-
name: node-exporter
181+
name: node-exporter-vm
182182
port: 9100
183183
protocol: TCP
184184
state: present
@@ -188,9 +188,9 @@
188188
ansible.builtin.assert:
189189
that:
190190
- test_service_create_vm is changed
191-
- test_service_create_vm['services']['name'] == "node-exporter"
191+
- test_service_create_vm['services']['name'] == "node-exporter-vm"
192192
- test_service_create_vm['services']['ports'] == [9100]
193193
- test_service_create_vm['services']['protocol'] == "tcp"
194194
- test_service_create_vm['diff']['after']['state'] == "present"
195195
- test_service_create_vm['diff']['before']['state'] == "absent"
196-
- test_service_create_vm['msg'] == "services node-exporter created"
196+
- test_service_create_vm['msg'] == "services node-exporter-vm created"

0 commit comments

Comments
 (0)