Skip to content
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

Device42 Unit Tests #436

Merged
merged 50 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
3e645a8
build: ⬆️ Upgrade project dependencies
jdrew82 Nov 1, 2023
70a6515
test: ✅ Add initial test for VRFGroup class
jdrew82 Nov 1, 2023
4555eb9
test: ✅ Add test validating VRFGroup.update()
jdrew82 Nov 2, 2023
868ec12
test: ✅ Add test validating delete() function for NautobotVRFGroup wo…
jdrew82 Nov 2, 2023
e6f5854
test: ✅ Add test validating NautobotSubnet.create() functionality
jdrew82 Nov 2, 2023
c640391
test: ✅ Add test validating NautobotSubnet.update() functionality.
jdrew82 Nov 2, 2023
c4df9c8
test: ✅ Add test validating NautobotSubnet.delete() functionality.
jdrew82 Nov 2, 2023
ece83b5
fix: 🐛 Correct attribute to be ip_version
jdrew82 Nov 3, 2023
5dca067
test: ✅ Add test validating NautobotIPAddress.create() with existing …
jdrew82 Nov 3, 2023
356d206
refactor: Move ids and attrs to setUp to be shared
jdrew82 Nov 3, 2023
7dd78a7
test: ✅ Add test showing IPAddress handling when missing Prefix.
jdrew82 Nov 3, 2023
15b66ad
test: 🚨 Ignore pylint warning
jdrew82 Nov 3, 2023
dc403b3
test: ✅ Add test validating NautobotIPAddress.create() with missing I…
jdrew82 Nov 3, 2023
e06b5fb
fix: 🐛 Correct IPAddress Status to be Active if available, else Reser…
jdrew82 Nov 6, 2023
2c5c415
fix: 🐛 Correct IPAddress update() for assigning to new Interface and …
jdrew82 Nov 6, 2023
0094f3e
test: ✅ Add tests validating IPAddress.update() for new available, la…
jdrew82 Nov 6, 2023
59d4aad
fix: 🐛 Correct var used when updating Device for IPAddress to use sel…
jdrew82 Nov 8, 2023
353ee51
style: 🔥 Remove unused import
jdrew82 Nov 8, 2023
0ef1d55
test: ♻️ Redo IPAddress update tests to be more DRY.
jdrew82 Nov 8, 2023
9610046
test: ✅ Add test validating NautobotIPAddress.update() for new Device.
jdrew82 Nov 8, 2023
c67f36f
style: 🚚 Rename test name to be clearer about test.
jdrew82 Nov 8, 2023
d8e11a3
test: ✅ Add test validating NautobotIPAddress.update() with changing …
jdrew82 Nov 8, 2023
ed3bcf3
test: ✅ Add test validating NautobotIPAddress.update() when setting p…
jdrew82 Nov 8, 2023
277a21a
test: ✅ Add test validating NautobotIPAddress.update() when changing …
jdrew82 Nov 8, 2023
2fb94c2
test: ✅ Add a test validating NautobotIPAddress.update() updating Cus…
jdrew82 Nov 8, 2023
a5d550f
test: ♻️ Use mock_addr for create/update calls instead of calling Nau…
jdrew82 Nov 9, 2023
ff247e2
test: ✅ Add test validating NautobotiPAddress.update() handles a Vali…
jdrew82 Nov 9, 2023
9e00393
test: ✅ Add test validating NautobotVLAN.create() works with missing …
jdrew82 Nov 10, 2023
2368aaa
style: ♻️ Update super().create() to match order of func signature.
jdrew82 Nov 10, 2023
4ae184f
fix: 🔥 Remove unused secondary None
jdrew82 Nov 10, 2023
d58ce56
fix: 🐛 Update check for building definition to ensure Global is used …
jdrew82 Nov 10, 2023
c83c0d3
test: ✅ Add test validating NautobotVLAN.create() functionality with …
jdrew82 Nov 10, 2023
652477e
test: ✅ Validate NautobotVLAN.update() functionality with updating VL…
jdrew82 Nov 10, 2023
077ed70
test: ✅ Add test validating NautobotVLAN.update() functions updating …
jdrew82 Nov 13, 2023
8fbb0cf
test: ✅ Add test validating NautobotVLAN.update() updates CustomField…
jdrew82 Nov 13, 2023
a3122ac
test: ✅ Add a test validating NautobotVLAN.update() updates VLAN tags.
jdrew82 Nov 13, 2023
41ca2b8
test: ♻️ Redo VRF create/update tests to include tags and CustomFields.
jdrew82 Nov 13, 2023
2a3f05c
test: ✅ Add test validating NautobotVRFGroup.update() clears tags in …
jdrew82 Nov 13, 2023
cfc0a73
test: ♻️ Update test for NautobotSubnet.create() to include tags and …
jdrew82 Nov 13, 2023
1fe1270
test: ✅ Add test validating NautobotSubnet.create() functionality wit…
jdrew82 Nov 15, 2023
9d45803
build: Update lockfile
jdrew82 Apr 23, 2024
c35de29
style: 🚨 Fix formatting for black
jdrew82 Apr 23, 2024
a254fce
test: 🚨 Add ignores for pylint
jdrew82 Apr 23, 2024
d4d979a
test: ✅ Correct CustomField key to use underscore
jdrew82 Apr 23, 2024
92c24d6
fix: 🐛 Correct VLAN attribute to be location instead of location_id
jdrew82 Apr 23, 2024
24b18e0
docs: 📝 Add changelog snippets
jdrew82 Apr 23, 2024
44cbd1b
docs: 📝 Update changelog snippet.
jdrew82 Apr 23, 2024
d2621e9
ci: 💚 Change check-in-docker CI step to use NB 2.2.0
jdrew82 Apr 23, 2024
8797a6b
ci: Use NB 2.2.1 to readd setup() for pylint
jdrew82 Apr 23, 2024
42884cf
ci: Update unittest to use 2.2.1 instead of 2.1.0
jdrew82 Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
fail-fast: true
matrix:
python-version: ["3.11"]
nautobot-version: ["2.1.0"]
nautobot-version: ["2.2.1"]
env:
INVOKE_NAUTOBOT_SSOT_PYTHON_VER: "${{ matrix.python-version }}"
INVOKE_NAUTOBOT_SSOT_NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
include:
- python-version: "3.11"
db-backend: "postgresql"
nautobot-version: "2.1.0"
nautobot-version: "2.2.1"
- python-version: "3.11"
db-backend: "mysql"
nautobot-version: "stable"
Expand Down
1 change: 1 addition & 0 deletions changes/436.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added additional unit tests for Device42 integration.
6 changes: 6 additions & 0 deletions changes/436.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fixed IPAddress attribute to be ip_version.
Fixed IPAddress Status to Active if available, else Reserved.
Fixed IPAddress assignment to Interface and setting primary.
Fixed variable used when assigning IPAddress to Interface.
Fixed check for Building definiton when creating a VLAN.
Fixed VLAN to use location instead of location_id in create().
1 change: 1 addition & 0 deletions development/app_config_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""App Config Schema Generator and Validator."""

import json
from importlib import import_module
from os import getenv
Expand Down
1 change: 1 addition & 0 deletions development/nautobot_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Nautobot development configuration file."""

import os
import sys

Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""App declaration for nautobot_ssot."""

import os
from importlib import metadata

Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/contrib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""SSoT Contrib."""

from nautobot_ssot.contrib.adapter import NautobotAdapter
from nautobot_ssot.contrib.model import NautobotModel
from nautobot_ssot.contrib.types import (
Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/contrib/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Contrib type classes for interfacing with Nautobot in SSoT."""

# pylint: disable=protected-access
# Diffsync relies on underscore-prefixed attributes quite heavily, which is why we disable this here.

Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/integrations/aci/constant.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for use with the ACI SSoT app."""

from django.conf import settings


Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/integrations/aci/diffsync/adapters/aci.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""DiffSync Adapter for Cisco ACI.""" # pylint: disable=too-many-lines, too-many-instance-attributes, too-many-arguments

# pylint: disable=duplicate-code


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""DiffSync Adapter for Nautobot."""

# pylint: disable=duplicate-code

import logging
Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/integrations/aci/diffsync/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""All interactions with ACI.""" # pylint: disable=too-many-lines, too-many-instance-attributes, too-many-arguments

# pylint: disable=invalid-name

import sys
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Initialize models for Nautobot and ACI."""

from .nautobot import (
NautobotTenant,
NautobotVrf,
Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/integrations/aci/diffsync/models/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base Shared Models for Cisco ACI integration with SSoT app."""

from typing import List, Optional
from diffsync import DiffSyncModel

Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/integrations/aci/diffsync/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ACI Utilities."""

# pylint: disable=invalid-name
import logging
import re
Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/integrations/aci/jobs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Jobs for ACI SSoT app."""

from django.templatetags.static import static
from django.urls import reverse
from diffsync import DiffSyncFlags
Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot/integrations/aci/signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Signals for ACI integration."""

# pylint: disable=logging-fstring-interpolation, invalid-name
import logging
import random
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""DiffSync adapter for Arista CloudVision."""

import distutils
import ipaddress
import re
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""DiffSync adapter for Nautobot."""

from collections import defaultdict
from django.contrib.contenttypes.models import ContentType
from django.db.models import ProtectedError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""DiffSyncModel subclasses for Nautobot-to-AristaCV data sync."""

from uuid import UUID
from diffsync import DiffSyncModel
from typing import List, Optional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""CloudVision DiffSync models for AristaCV SSoT."""

from nautobot_ssot.integrations.aristacv.diffsync.models.base import (
Device,
CustomField,
Expand Down
8 changes: 5 additions & 3 deletions nautobot_ssot/integrations/aristacv/utils/cloudvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,11 @@ def get_ip_interfaces(client: CloudvisionApi, dId: str):
ip_intfs.append(
{
"interface": results["intfId"],
"address": results["addrWithMask"]
if results["addrWithMask"] != "0.0.0.0/0"
else results.get("virtualAddrWithMask"),
"address": (
results["addrWithMask"]
if results["addrWithMask"] != "0.0.0.0/0"
else results.get("virtualAddrWithMask")
),
}
)
return ip_intfs
Expand Down
56 changes: 35 additions & 21 deletions nautobot_ssot/integrations/device42/diffsync/adapters/device42.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,18 +468,26 @@ def load_vendor_and_model(self, hwmodel_name: str, manuf: str):
hwmodel = self.hardware(
name=hwmodel_name,
manufacturer=manuf,
size=float(round(self.d42_hardware_map[hwmodel_name]["size"]))
if self.d42_hardware_map.get(hwmodel_name) and self.d42_hardware_map[hwmodel_name].get("size")
else 1.0,
depth=self.d42_hardware_map[hwmodel_name]["depth"]
if self.d42_hardware_map.get(hwmodel_name) and self.d42_hardware_map[hwmodel_name].get("depth")
else "Half Depth",
part_number=self.d42_hardware_map[hwmodel_name]["part_no"]
if self.d42_hardware_map.get(hwmodel_name) and self.d42_hardware_map[hwmodel_name].get("part_no")
else "",
custom_fields=get_custom_field_dict(self.d42_hardware_map[hwmodel_name]["custom_fields"])
if self.d42_hardware_map.get(hwmodel_name)
else {},
size=(
float(round(self.d42_hardware_map[hwmodel_name]["size"]))
if self.d42_hardware_map.get(hwmodel_name) and self.d42_hardware_map[hwmodel_name].get("size")
else 1.0
),
depth=(
self.d42_hardware_map[hwmodel_name]["depth"]
if self.d42_hardware_map.get(hwmodel_name) and self.d42_hardware_map[hwmodel_name].get("depth")
else "Half Depth"
),
part_number=(
self.d42_hardware_map[hwmodel_name]["part_no"]
if self.d42_hardware_map.get(hwmodel_name) and self.d42_hardware_map[hwmodel_name].get("part_no")
else ""
),
custom_fields=(
get_custom_field_dict(self.d42_hardware_map[hwmodel_name]["custom_fields"])
if self.d42_hardware_map.get(hwmodel_name)
else {}
),
uuid=None,
)
self.add(hwmodel)
Expand Down Expand Up @@ -762,9 +770,11 @@ def load_connections(self):
continue
try:
new_conn = self.conn(
src_device=self.d42_device_map[_conn["second_src_device"]]["name"]
if _conn.get("second_src_device")
else self.d42_device_map[_conn["src_device"]]["name"],
src_device=(
self.d42_device_map[_conn["second_src_device"]]["name"]
if _conn.get("second_src_device")
else self.d42_device_map[_conn["src_device"]]["name"]
),
src_port=self.d42_port_map[_conn["src_port"]]["port"],
src_port_mac=self.d42_port_map[_conn["src_port"]]["hwaddress"],
src_type="interface",
Expand Down Expand Up @@ -839,9 +849,11 @@ def load_providers_and_circuits(self):
a_side_conn = self.conn(
src_device=origin_dev,
src_port=origin_int,
src_port_mac=self.d42_port_map[_tc["origin_netport_fk"]]["hwaddress"]
if _tc["origin_type"] == "Device"
else None,
src_port_mac=(
self.d42_port_map[_tc["origin_netport_fk"]]["hwaddress"]
if _tc["origin_type"] == "Device"
else None
),
src_type="interface" if _tc["origin_type"] == "Device Port" else "patch panel",
dst_device=_tc["circuit_id"],
dst_port=_tc["circuit_id"],
Expand All @@ -859,9 +871,11 @@ def load_providers_and_circuits(self):
src_type="circuit",
dst_device=endpoint_dev,
dst_port=endpoint_int,
dst_port_mac=self.d42_port_map[_tc["end_point_netport_fk"]]["hwaddress"]
if _tc["end_point_type"] == "Device"
else None,
dst_port_mac=(
self.d42_port_map[_tc["end_point_netport_fk"]]["hwaddress"]
if _tc["end_point_type"] == "Device"
else None
),
dst_type="interface" if _tc["end_point_type"] == "Device Port" else "patch panel",
src_port_mac=None,
tags=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def create(cls, diffsync, ids, attrs):
try:
patch_panel.validated_save()
diffsync.device_map[ids["name"]] = patch_panel.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)
except ValidationError as err:
if diffsync.job.debug:
diffsync.job.logger.warning(f"Unable to create {ids['name']} patch panel. {err}")
Expand Down Expand Up @@ -165,7 +165,7 @@ def create(cls, diffsync, ids, attrs):
if ids["patchpanel"] not in diffsync.rp_map:
diffsync.rp_map[ids["patchpanel"]] = {}
diffsync.rp_map[ids["patchpanel"]][ids["name"]] = rear_port.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)
except ValidationError as err:
if diffsync.job.debug:
diffsync.job.logger.debug(f"Unable to create patch panel {ids['name']}. {err}")
Expand Down Expand Up @@ -216,7 +216,7 @@ def create(cls, diffsync, ids, attrs):
if ids["patchpanel"] not in diffsync.fp_map:
diffsync.fp_map[ids["patchpanel"]] = {}
diffsync.fp_map[ids["patchpanel"]][ids["name"]] = front_port.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)
except ValidationError as err:
diffsync.job.logger.debug(f"Unable to create patch panel front port {ids['name']}. {err}")
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create(cls, diffsync, ids, attrs):
try:
_provider.validated_save()
diffsync.provider_map[ids["name"]] = _provider.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)
except ValidationError as err:
if diffsync.job.debug:
diffsync.job.logger.warning(f"Unable to create {ids['name']} provider. {err}")
Expand Down Expand Up @@ -122,7 +122,7 @@ def create(cls, diffsync, ids, attrs):
term_side="Z",
circuit=_circuit,
)
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)

def update(self, attrs):
"""Update Circuit object in Nautobot."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def create(cls, diffsync, ids, attrs):
nautobot.update_custom_fields(new_cfields=attrs["custom_fields"], update_obj=new_site)
new_site.validated_save()
diffsync.site_map[ids["name"]] = new_site.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)

def update(self, attrs):
"""Update Site object in Nautobot."""
Expand Down Expand Up @@ -137,7 +137,7 @@ def create(cls, diffsync, ids, attrs):
if ids["building"] not in diffsync.room_map:
diffsync.room_map[ids["building"]] = {}
diffsync.room_map[ids["building"]][ids["name"]] = new_rg.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)

def update(self, attrs):
"""Update RackGroup object in Nautobot."""
Expand Down Expand Up @@ -188,7 +188,7 @@ def create(cls, diffsync, ids, attrs):
if ids["room"] not in diffsync.rack_map[ids["building"]]:
diffsync.rack_map[ids["building"]][ids["room"]] = {}
diffsync.rack_map[ids["building"]][ids["room"]][ids["name"]] = new_rack.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)

def update(self, attrs):
"""Update Rack object in Nautobot."""
Expand Down Expand Up @@ -240,7 +240,7 @@ def create(cls, diffsync, ids, attrs):
nautobot.update_custom_fields(new_cfields=attrs["custom_fields"], update_obj=new_manu)
new_manu.validated_save()
diffsync.vendor_map[ids["name"]] = new_manu.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)

def update(self, attrs):
"""Update Manufacturer object in Nautobot."""
Expand Down Expand Up @@ -287,7 +287,7 @@ def create(cls, diffsync, ids, attrs):
nautobot.update_custom_fields(new_cfields=attrs["custom_fields"], update_obj=new_dt)
new_dt.validated_save()
diffsync.devicetype_map[ids["name"]] = new_dt.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)

def update(self, attrs):
"""Update DeviceType object in Nautobot."""
Expand Down Expand Up @@ -346,7 +346,7 @@ def create(cls, diffsync, ids, attrs):
nautobot.update_custom_fields(new_cfields=attrs["custom_fields"], update_obj=new_vc)
new_vc.validated_save()
diffsync.cluster_map[ids["name"]] = new_vc.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)

def update(self, attrs):
"""Update Virtual Chassis object in Nautobot."""
Expand Down Expand Up @@ -699,7 +699,7 @@ def create(cls, diffsync, ids, attrs): # pylint: disable=inconsistent-return-st
diffsync.port_map[ids["device"]][ids["name"]] = new_intf.id
if attrs.get("mac_addr"):
diffsync.port_map[attrs["mac_addr"][:12]] = new_intf.id
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
return super().create(diffsync, ids=ids, attrs=attrs)

def update(self, attrs):
"""Update Interface object in Nautobot."""
Expand Down