Skip to content

Commit

Permalink
Merge pull request #436 from nautobot/patch-d42_tests_fixes
Browse files Browse the repository at this point in the history
Device42 Unit Tests
  • Loading branch information
jdrew82 committed Apr 29, 2024
2 parents a42ab6f + 42884cf commit 6130be9
Show file tree
Hide file tree
Showing 91 changed files with 2,452 additions and 1,824 deletions.
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
1 change: 1 addition & 0 deletions nautobot_ssot/integrations/aci/diffsync/models/__init__.py
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

0 comments on commit 6130be9

Please sign in to comment.