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

Add ssl_verify option to pynautobot object initilization, update pynautobot #137

Merged
merged 9 commits into from
Feb 6, 2024
Merged
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
1 change: 1 addition & 0 deletions examples/basic_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testing file."""

# pylint: disable=duplicate-code
import os
from nornir import InitNornir
Expand Down
1 change: 1 addition & 0 deletions examples/filter_location.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testing file."""

# pylint: disable=duplicate-code
import os
from nornir import InitNornir
Expand Down
1 change: 1 addition & 0 deletions examples/filter_multiple_locations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testing file."""

# pylint: disable=duplicate-code
import os
from nornir import InitNornir
Expand Down
1 change: 1 addition & 0 deletions examples/filter_negate_location.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testing file."""

# pylint: disable=duplicate-code
import os
from nornir import InitNornir
Expand Down
10 changes: 7 additions & 3 deletions nornir_nautobot/plugins/inventory/nautobot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Nornir Nautobot Inventory Plugin."""

# Python Imports
import os
import sys
Expand Down Expand Up @@ -111,6 +112,7 @@ def pynautobot_obj(self) -> pynautobot.core.api.Api:
self.nautobot_url,
token=self.nautobot_token,
threading=self.enable_threading,
verify=self.ssl_verify,
)
self.api_session.params = {"depth": 1}

Expand Down Expand Up @@ -161,9 +163,11 @@ def load(self) -> Inventory:
host["hostname"] = (
str(ipaddress.IPv4Interface(device.primary_ip4.address).ip)
if device["primary_ip4"]
else str(ipaddress.IPv6Interface(device.primary_ip6.address).ip)
if device["primary_ip6"]
else device["name"]
else (
str(ipaddress.IPv6Interface(device.primary_ip6.address).ip)
if device["primary_ip6"]
else device["name"]
)
)
host["name"] = device.name or str(device.id)
host["groups"] = []
Expand Down
1 change: 1 addition & 0 deletions nornir_nautobot/plugins/processors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""BaseProcessor for the nornir."""

import logging

from nornir.core.inventory import Host
Expand Down
1 change: 1 addition & 0 deletions nornir_nautobot/plugins/tasks/dispatcher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Used to initialize the dispatcher."""

# pylint: disable=raise-missing-from

import logging
Expand Down
1 change: 1 addition & 0 deletions nornir_nautobot/plugins/tasks/dispatcher/default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""default driver for the network_importer."""

# pylint: disable=raise-missing-from,too-many-arguments

import logging
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""nornir dispatcher for Mikrotik Router OS."""

# pylint: disable=raise-missing-from

import os
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""nornir dispatcher for Ruckus ICX/FastIron Switches."""

from nornir.core.task import Result, Task
from nornir.core.exceptions import NornirSubTaskError

Expand Down
1,661 changes: 803 additions & 858 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nornir-nautobot"
version = "3.1.0"
version = "3.1.1"
description = "Nornir Nautobot"
authors = ["Network to Code, LLC <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -31,7 +31,7 @@ nornir-utils = "^0"
nornir-napalm = ">=0.4.0 <1.0.0"
nornir-jinja2 = "^0.2.0"
nornir-netmiko = "^1"
pynautobot = ">=2.0.0rc2"
pynautobot = ">=2.0.2"
netutils = "^1.6.0"
routeros-api = {version = "^0.17.0", optional = true}
httpx = "^0.24.1"
Expand Down
1 change: 1 addition & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tasks for use with Invoke."""

import os
import sys
from distutils.util import strtobool # pylint: disable=deprecated-module
Expand Down
1 change: 1 addition & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Used to setup fixtures to be used through tests."""

import pytest
import pynautobot
from nornir_nautobot.plugins.inventory.nautobot import NautobotInventory
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/test_nautobot_inventory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pytest of Nautobot Inventory."""

# Standard Library Imports
from os import path

Expand All @@ -23,11 +24,26 @@
"url": "http://mock.example.com/api/",
"method": "get",
},
{
"fixture_path": f"{HERE}/mocks/00_api_root.json",
"url": "https://mock.example.com/api/",
"method": "get",
},
{
"fixture_path": f"{HERE}/mocks/01_get_devices.json",
"url": "http://mock.example.com/api/dcim/devices/?depth=1",
"method": "get",
},
{
"fixture_path": f"{HERE}/mocks/01_get_devices.json",
"url": "https://mock.example.com/api/dcim/devices/?depth=1",
"method": "get",
},
{
"fixture_path": f"{HERE}/mocks/01_get_devices.json",
"url": "https://mock.example.com/api/dcim/devices/?depth=1&limit=0",
"method": "get",
},
{
"fixture_path": f"{HERE}/mocks/02_get_device1.json",
"url": "http://mock.example.com/api/dcim/devices/?name=den-dist01",
Expand Down Expand Up @@ -89,6 +105,28 @@ def test_nornir_nautobot_initialization():
assert no_exception_found


def test_nornir_nautobot_initialization_ssl_verify_default():
with Mocker() as mock:
load_api_calls(mock)
nornir_nautobot_class = NautobotInventory(
nautobot_url="https://mock.example.com", nautobot_token="0123456789abcdef01234567890"
)
assert nornir_nautobot_class.pynautobot_obj.http_session.verify is True
assert nornir_nautobot_class.api_session.verify is True
assert nornir_nautobot_class.ssl_verify is True


def test_nornir_nautobot_initialization_ssl_verify_false():
with Mocker() as mock:
load_api_calls(mock)
nornir_nautobot_class = NautobotInventory(
nautobot_url="https://mock.example.com", nautobot_token="0123456789abcdef01234567890", ssl_verify=False
)
assert nornir_nautobot_class.pynautobot_obj.http_session.verify is False
assert nornir_nautobot_class.api_session.verify is False
assert nornir_nautobot_class.ssl_verify is False


def test_nornir_nautobot_missing_url():
with pytest.raises(ValueError) as err:
NautobotInventory(nautobot_url=None, nautobot_token="0123456789abcdef01234567890")
Expand Down
Loading