Skip to content

Fix sevral integration tests failure #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bugfixes:
- Add netbox version check to support service creation for netbox version prior of 4.3
- Use dedicated function to check netbox version istead of self.full_version for rack.
- Fix typos in tag integration tests.
- Fix integration test for circuit termination, missing assignment
- Fix integration test for service
20 changes: 3 additions & 17 deletions plugins/module_utils/netbox_dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

__metaclass__ = type

from ansible.module_utils.basic import missing_required_lib
from ansible_collections.netbox.netbox.plugins.module_utils.netbox_utils import (
NetboxModule,
ENDPOINT_NAME_MAPPING,
Expand Down Expand Up @@ -53,22 +52,9 @@
NB_VIRTUAL_CHASSIS = "virtual_chassis"
NB_MAC_ADDRESSES = "mac_addresses"

try:
from packaging.version import Version

HAS_PACKAGING = True
PACKAGING_IMPORT_ERROR = ""
except ImportError as imp_exc:
PACKAGING_IMPORT_ERROR = imp_exc
HAS_PACKAGING = False


class NetboxDcimModule(NetboxModule):
def __init__(self, module, endpoint):
if not HAS_PACKAGING:
module.fail_json(
msg=missing_required_lib("packaging"), exception=PACKAGING_IMPORT_ERROR
)
super().__init__(module, endpoint)

def run(self):
Expand Down Expand Up @@ -128,7 +114,7 @@ def run(self):

# Handle rack and form_factor
if endpoint_name == "rack":
if Version(self.full_version) >= Version("4.1.0"):
if self._version_check_greater(self.version, "4.1", greater_or_equal=True):
if "type" in data:
data["form_factor"] = self._to_slug(data["type"])
del data["type"]
Expand Down Expand Up @@ -207,7 +193,7 @@ def run(self):
data["color"] = data["color"].lower()

if self.endpoint == "cables":
if Version(self.full_version) >= Version("3.0.6"):
if self._version_check_greater(self.version, "3.0", greater_or_equal=True):
cables = [
nb_endpoint.get(
termination_a_type=data["termination_a_type"],
Expand Down Expand Up @@ -236,7 +222,7 @@ def run(self):
else:
self._handle_errors(msg="More than one result returned for %s" % (name))

if Version(self.full_version) >= Version("3.3.0"):
if self._version_check_greater(self.version, "3.3", greater_or_equal=True):
data["a_terminations"] = [
{
"object_id": data.pop("termination_a_id"),
Expand Down
4 changes: 3 additions & 1 deletion plugins/module_utils/netbox_ipam.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ def run(self):
if not data.get("slug"):
data["slug"] = self._to_slug(name)

if self.endpoint == "services":
if self.endpoint == "services" and self._version_check_greater(
self.version, "4.3", greater_or_equal=True
):
if "device" in data:
data["parent_object_type"] = "dcim.device"
data["parent_object_id"] = data["device"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@
### NETBOX_CIRCUIT_TERMINATION
##
##
- name: "NETBOX_CIRCUIT_TERMINATION 0: Create provider network within NetBox with only required information"
netbox.netbox.netbox_provider_network:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
provider: Test Provider
name: Test Provider Network One
state: present
register: test_one

- name: "NETBOX_CIRCUIT_TERMINATION 0: ASSERT - Necessary info creation"
ansible.builtin.assert:
that:
- test_one is changed
- test_one['diff']['before']['state'] == "absent"
- test_one['diff']['after']['state'] == "present"
- test_one['provider_network']['name'] == "Test Provider Network One"
- test_one['msg'] == "provider_network Test Provider Network One created"

- name: "NETBOX_CIRCUIT_TERMINATION 1: Create provider within NetBox with only required information"
netbox.netbox.netbox_circuit_termination:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
circuit: Test Circuit
term_side: A
site: Test Site
termination_id: 2
termination_type: circuits.providernetwork
port_speed: 10000
state: present
register: test_one
Expand All @@ -22,9 +42,10 @@
- test_one is changed
- test_one['diff']['before']['state'] == "absent"
- test_one['diff']['after']['state'] == "present"
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_one['circuit_termination']['circuit'] == 1
- test_one['circuit_termination']['term_side'] == "A"
- test_one['circuit_termination']['site'] == 1
- test_one['circuit_termination']['port_speed'] == 10000
- test_one['msg'] == "circuit_termination test_circuit_a created"

Expand All @@ -42,9 +63,10 @@
ansible.builtin.assert:
that:
- not test_two['changed']
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_two['circuit_termination']['circuit'] == 1
- test_two['circuit_termination']['term_side'] == "A"
- test_two['circuit_termination']['site'] == 1
- test_two['circuit_termination']['port_speed'] == 10000
- test_two['msg'] == "circuit_termination test_circuit_a already exists"

Expand All @@ -66,13 +88,14 @@
ansible.builtin.assert:
that:
- test_three is changed
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_three['diff']['after']['upstream_speed'] == 1000
- test_three['diff']['after']['xconnect_id'] == "10X100"
- test_three['diff']['after']['pp_info'] == "PP10-24"
- test_three['diff']['after']['description'] == "Test description"
- test_three['circuit_termination']['circuit'] == 1
- test_three['circuit_termination']['term_side'] == "A"
- test_three['circuit_termination']['site'] == 1
- test_three['circuit_termination']['port_speed'] == 10000
- test_three['circuit_termination']['upstream_speed'] == 1000
- test_three['circuit_termination']['xconnect_id'] == "10X100"
Expand All @@ -87,7 +110,8 @@
data:
circuit: Test Circuit
term_side: Z
site: Test Site
termination_id: 2
termination_type: circuits.providernetwork
port_speed: 10000
state: present
register: test_four
Expand All @@ -98,9 +122,10 @@
- test_four is changed
- test_four['diff']['before']['state'] == "absent"
- test_four['diff']['after']['state'] == "present"
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_four['circuit_termination']['circuit'] == 1
- test_four['circuit_termination']['term_side'] == "Z"
- test_four['circuit_termination']['site'] == 1
- test_four['circuit_termination']['port_speed'] == 10000
- test_four['msg'] == "circuit_termination test_circuit_z created"

Expand All @@ -120,10 +145,11 @@
- test_five is changed
- test_five['circuit_termination']['circuit'] == 1
- test_five['circuit_termination']['term_side'] == "A"
- test_five['circuit_termination']['site'] == 1
- test_five['circuit_termination']['port_speed'] == 10000
- test_five['circuit_termination']['upstream_speed'] == 1000
- test_five['circuit_termination']['xconnect_id'] == "10X100"
- test_five['circuit_termination']['pp_info'] == "PP10-24"
- test_five['circuit_termination']['description'] == "Test description"
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_five['msg'] == "circuit_termination test_circuit_a deleted"
6 changes: 3 additions & 3 deletions tests/integration/targets/v4.2/tasks/netbox_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
virtual_machine: test100-vm
name: node-exporter
name: node-exporter-vm
port: 9100
protocol: TCP
state: present
Expand All @@ -188,9 +188,9 @@
ansible.builtin.assert:
that:
- test_service_create_vm is changed
- test_service_create_vm['services']['name'] == "node-exporter"
- test_service_create_vm['services']['name'] == "node-exporter-vm"
- test_service_create_vm['services']['ports'] == [9100]
- test_service_create_vm['services']['protocol'] == "tcp"
- test_service_create_vm['diff']['after']['state'] == "present"
- test_service_create_vm['diff']['before']['state'] == "absent"
- test_service_create_vm['msg'] == "services node-exporter created"
- test_service_create_vm['msg'] == "services node-exporter-vm created"
6 changes: 3 additions & 3 deletions tests/integration/targets/v4.2/tasks/netbox_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
description: Tag 1 test
color: "0000ff"
object_types:
- ipem.prefix
- ipam.prefix
state: present
register: test_one

Expand All @@ -27,7 +27,7 @@
- test_one['tags']['description'] == "Tag 1 test"
- test_one['tags']['name'] == "Test Tag 1"
- test_one['tags']['slug'] == "test-tag-1"
- test_one['tags']['object_types'][0] = "ipam.prefix"
- test_one['tags']['object_types'][0] == "ipam.prefix"
- test_one['msg'] == "tags Test Tag 1 created"

- name: "TAG 2: Create duplicate"
Expand Down Expand Up @@ -70,7 +70,7 @@
- test_three['tags']['name'] == "Test Tag 1"
- test_three['tags']['description'] == "Tag 1 update test"
- test_three['tags']['color'] == "00ff00"
-test_three['tags']['object_types'][0] == "ipam.asn"
- test_three['tags']['object_types'][0] == "ipam.asn"
- test_three['msg'] == "tags Test Tag 1 updated"

- name: "TAG 4: ASSERT - Delete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@
### NETBOX_CIRCUIT_TERMINATION
##
##
- name: "NETBOX_CIRCUIT_TERMINATION 0: Create provider network within NetBox with only required information"
netbox.netbox.netbox_provider_network:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
provider: Test Provider
name: Test Provider Network One
state: present
register: test_one

- name: "NETBOX_CIRCUIT_TERMINATION 0: ASSERT - Necessary info creation"
ansible.builtin.assert:
that:
- test_one is changed
- test_one['diff']['before']['state'] == "absent"
- test_one['diff']['after']['state'] == "present"
- test_one['provider_network']['name'] == "Test Provider Network One"
- test_one['msg'] == "provider_network Test Provider Network One created"

- name: "NETBOX_CIRCUIT_TERMINATION 1: Create provider within NetBox with only required information"
netbox.netbox.netbox_circuit_termination:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
circuit: Test Circuit
term_side: A
site: Test Site
termination_id: 2
termination_type: circuits.providernetwork
port_speed: 10000
state: present
register: test_one
Expand All @@ -22,9 +42,10 @@
- test_one is changed
- test_one['diff']['before']['state'] == "absent"
- test_one['diff']['after']['state'] == "present"
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_one['circuit_termination']['circuit'] == 1
- test_one['circuit_termination']['term_side'] == "A"
- test_one['circuit_termination']['site'] == 1
- test_one['circuit_termination']['port_speed'] == 10000
- test_one['msg'] == "circuit_termination test_circuit_a created"

Expand All @@ -42,9 +63,10 @@
ansible.builtin.assert:
that:
- not test_two['changed']
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_two['circuit_termination']['circuit'] == 1
- test_two['circuit_termination']['term_side'] == "A"
- test_two['circuit_termination']['site'] == 1
- test_two['circuit_termination']['port_speed'] == 10000
- test_two['msg'] == "circuit_termination test_circuit_a already exists"

Expand All @@ -66,13 +88,14 @@
ansible.builtin.assert:
that:
- test_three is changed
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_three['diff']['after']['upstream_speed'] == 1000
- test_three['diff']['after']['xconnect_id'] == "10X100"
- test_three['diff']['after']['pp_info'] == "PP10-24"
- test_three['diff']['after']['description'] == "Test description"
- test_three['circuit_termination']['circuit'] == 1
- test_three['circuit_termination']['term_side'] == "A"
- test_three['circuit_termination']['site'] == 1
- test_three['circuit_termination']['port_speed'] == 10000
- test_three['circuit_termination']['upstream_speed'] == 1000
- test_three['circuit_termination']['xconnect_id'] == "10X100"
Expand All @@ -87,7 +110,8 @@
data:
circuit: Test Circuit
term_side: Z
site: Test Site
termination_id: 2
termination_type: circuits.providernetwork
port_speed: 10000
state: present
register: test_four
Expand All @@ -98,9 +122,10 @@
- test_four is changed
- test_four['diff']['before']['state'] == "absent"
- test_four['diff']['after']['state'] == "present"
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_four['circuit_termination']['circuit'] == 1
- test_four['circuit_termination']['term_side'] == "Z"
- test_four['circuit_termination']['site'] == 1
- test_four['circuit_termination']['port_speed'] == 10000
- test_four['msg'] == "circuit_termination test_circuit_z created"

Expand All @@ -120,10 +145,11 @@
- test_five is changed
- test_five['circuit_termination']['circuit'] == 1
- test_five['circuit_termination']['term_side'] == "A"
- test_five['circuit_termination']['site'] == 1
- test_five['circuit_termination']['port_speed'] == 10000
- test_five['circuit_termination']['upstream_speed'] == 1000
- test_five['circuit_termination']['xconnect_id'] == "10X100"
- test_five['circuit_termination']['pp_info'] == "PP10-24"
- test_five['circuit_termination']['description'] == "Test description"
- test_one['circuit_termination']['termination_type'] == "circuits.providernetwork"
- test_one['circuit_termination']['termination_id'] == 2
- test_five['msg'] == "circuit_termination test_circuit_a deleted"
6 changes: 3 additions & 3 deletions tests/integration/targets/v4.3/tasks/netbox_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
virtual_machine: test100-vm
name: node-exporter
name: node-exporter-vm
port: 9100
protocol: TCP
state: present
Expand All @@ -188,9 +188,9 @@
ansible.builtin.assert:
that:
- test_service_create_vm is changed
- test_service_create_vm['services']['name'] == "node-exporter"
- test_service_create_vm['services']['name'] == "node-exporter-vm"
- test_service_create_vm['services']['ports'] == [9100]
- test_service_create_vm['services']['protocol'] == "tcp"
- test_service_create_vm['diff']['after']['state'] == "present"
- test_service_create_vm['diff']['before']['state'] == "absent"
- test_service_create_vm['msg'] == "services node-exporter created"
- test_service_create_vm['msg'] == "services node-exporter-vm created"
Loading