Skip to content

Commit

Permalink
Jls dev jun29 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyschulman authored Sep 16, 2024
1 parent d70d1dc commit 5bc443f
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 65 deletions.
21 changes: 13 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
.PHONY: setup.py requirements.txt
PACKAGE_and_VERSION = $(shell poetry version)
PACKAGE_NAME = $(word 1, $(PACKAGE_and_VERSION))
PACKAGE_VERSION = $(word 2, $(PACKAGE_and_VERSION))

DIST_BASENAME := $(shell poetry version | tr ' ' '-')
precheck: code-format code-check
pre-commit run -a && \
interrogate -c pyproject.toml

all: precheck
code-format:
ruff format --config pyproject.toml $(CODE_DIRS)

.PHONY: prechck
precheck:
invoke precheck
code-check:
ruff check --config pyproject.toml $(CODE_DIRS)

clean:
rm -rf dist *.egg-info .pytest_cache
rm -f requirements.txt setup.py
rm -f poetry.lock
find . -name '__pycache__' | xargs rm -rf

doc-check:
interrogate -vvv netcam_aioeos --omit-covered-files
doccheck:
interrogate -vvv netinfraiac --omit-covered-files

33 changes: 33 additions & 0 deletions netcam_aioeos/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.10

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: debug-statements
- id: check-merge-conflict
- id: trailing-whitespace
exclude: 'configs|checks'
- id: check-yaml
- id: check-toml
- id: check-added-large-files


# Run the Ruff linter.
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.0
hooks:
- id: ruff
args: [--config,pyproject.toml]

# Run the Ruff formatter.
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.0
hooks:
- id: ruff-format
args: [--config,pyproject.toml]
2 changes: 1 addition & 1 deletion netcam_aioeos/bgp_peering/eos_check_bgp_peering_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# -----------------------------------------------------------------------------

from types import MappingProxyType
from netcad.bgp_peering.bgp_nei_state import BgpNeighborState
from netcad.feats.bgp_peering import BgpNeighborState


EOS_DEFAULT_VRF_NAME = "default"
Expand Down
2 changes: 1 addition & 1 deletion netcam_aioeos/bgp_peering/eos_checks_bgp_peering.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Public Imports
# -----------------------------------------------------------------------------

from netcad.bgp_peering.checks import (
from netcad.feats.bgp_peering.checks import (
BgpNeighborsCheckCollection,
BgpNeighborCheck,
BgpNeighborCheckResult,
Expand Down
2 changes: 1 addition & 1 deletion netcam_aioeos/bgp_peering/eos_checks_bgp_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Public Imports
# -----------------------------------------------------------------------------

from netcad.bgp_peering.checks import (
from netcad.feats.bgp_peering.checks import (
BgpRoutersCheckCollection,
BgpRouterCheck,
BgpRouterCheckResult,
Expand Down
1 change: 0 additions & 1 deletion netcam_aioeos/eos_dut.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ async def setup(self):

try:
self.version_info = await self.eapi.cli("show version")

except httpx.HTTPError as exc:
rt_exc = RuntimeError(
f"Unable to connect to EOS device {self.device.name}: {str(exc)}"
Expand Down
2 changes: 1 addition & 1 deletion netcam_aioeos/eos_plugin_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def plugin_init(plugin_def: dict):

def eos_plugin_config(config: dict):
"""
Called during plugin init, this function is used to setup the default
Called during plugin init, this function is used to set up the default
credentials to access the EOS devices.
Parameters
Expand Down
4 changes: 2 additions & 2 deletions netcam_aioeos/topology/eos_check_cabling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
# Public Imports
# -----------------------------------------------------------------------------

from netcad.topology.checks.check_cabling_nei import (
from netcad.feats.topology.checks.check_cabling_nei import (
InterfaceCablingCheckCollection,
InterfaceCablingCheck,
InterfaceCablingCheckResult,
)
from netcad.topology.checks.utils_cabling_nei import (
from netcad.feats.topology.checks.utils_cabling_nei import (
nei_interface_match,
nei_hostname_match,
)
Expand Down
11 changes: 9 additions & 2 deletions netcam_aioeos/topology/eos_check_device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# -----------------------------------------------------------------------------

from netcad.checks import CheckResultsCollection, CheckResult, CheckStatus
from netcad.topology.checks.check_device_info import (
from netcad.feats.topology.checks.check_device_info import (
DeviceInformationCheckCollection,
DeviceInformationCheckResult,
)
Expand Down Expand Up @@ -59,7 +59,6 @@ async def eos_check_device_info(
# purposes.

check = device_checks.checks[0]
result = DeviceInformationCheckResult(device=dut.device, check=check)

exp_values = check.expected_results

Expand All @@ -69,6 +68,14 @@ async def eos_check_device_info(
check_len = min(len(has_product_model), len(exp_product_model))
model_match = has_product_model[:check_len] == exp_product_model[:check_len]

result = DeviceInformationCheckResult(
device=dut.device,
check=check,
measurement=DeviceInformationCheckResult.Measurement(
product_model=has_product_model
),
)

def on_mismatch(_field, _expd, _msrd):
return CheckStatus.PASS if model_match else CheckStatus.FAIL

Expand Down
17 changes: 8 additions & 9 deletions netcam_aioeos/topology/eos_check_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from netcad.device import Device, DeviceInterface
from netcad.checks import CheckResultsCollection, CheckStatus

from netcad.topology.checks.check_interfaces import (
from netcad.feats.topology.checks.check_interfaces import (
InterfaceCheckCollection,
InterfaceExclusiveListCheck,
InterfaceExclusiveListCheckResult,
Expand Down Expand Up @@ -124,7 +124,7 @@ async def eos_check_interfaces(
if_name = check.check_id()

# ---------------------------------------------------------------------
# if the interface is an SVI, that is begins with "Vlan", then we need
# if the interface is an SVI, that it begins with "Vlan", then we need
# to examine it differently since it does not show up in the "show
# interfaces ..." command.
# ---------------------------------------------------------------------
Expand Down Expand Up @@ -162,10 +162,7 @@ async def eos_check_interfaces(

# if the loopback exists, then it is a PASS, and we are not going
# to check anything else at this time.
# TODO: could check operational state, but when does anyone
# disable a loopback or config??

result.measurement.native_status = lo_status
result.measurement.oper_up = lo_status["lineProtocolStatus"] == "up"
results.append(result)

# done with Loopback, go to next test-case
Expand Down Expand Up @@ -251,7 +248,6 @@ def eos_check_one_interface(
Validates a specific physical interface against the expectations in the
design.
"""

result = InterfaceCheckResult(device=device, check=check)

# if the interface does not exist, then no further checking.
Expand All @@ -265,7 +261,6 @@ def eos_check_one_interface(
# comparison with the expected values.

measurement = EosInterfaceMeasurement.from_cli(iface_oper_status)

if_flags = check.check_params.interface_flags or {}
is_reserved = if_flags.get("is_reserved", False)

Expand All @@ -284,6 +279,11 @@ def eos_check_one_interface(
if is_forced_unused := if_flags.get("is_forced_unused"):
check.expected_results.used = False

# see if the port was explicity set to disabled.
if_name = check.check_id()
if device.interfaces[if_name].enabled is False:
check.expected_results.used = False

# -------------------------------------------------------------------------
# Check the 'used' status. Then if the interface is not being used, then no
# more checks are required.
Expand All @@ -294,7 +294,6 @@ def eos_check_one_interface(
def on_mismatch(_field, _expected, _measured) -> CheckStatus:
# if the field is description, then it is a warning, and not a failure.
if _field == "desc":

# if the design is meant to force a shutdown on the port, then we
# really do want to surface the description error.

Expand Down
2 changes: 1 addition & 1 deletion netcam_aioeos/topology/eos_check_ipaddrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Public Imports
# -----------------------------------------------------------------------------

from netcad.topology.checks.check_ipaddrs import (
from netcad.feats.topology.checks.check_ipaddrs import (
IPInterfacesCheckCollection,
IPInterfaceCheck,
IPInterfaceCheckResult,
Expand Down
2 changes: 1 addition & 1 deletion netcam_aioeos/topology/eos_check_lags.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Public Imports
# -----------------------------------------------------------------------------

from netcad.topology.checks.check_lags import (
from netcad.feats.topology.checks.check_lags import (
LagCheckCollection,
LagCheck,
LagCheckResult,
Expand Down
4 changes: 2 additions & 2 deletions netcam_aioeos/topology/eos_check_transceivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
# -----------------------------------------------------------------------------
from netcad.checks import CheckResultsCollection, CheckStatus

from netcad.topology.checks.check_transceivers import (
from netcad.feats.topology.checks.check_transceivers import (
TransceiverCheckCollection,
TransceiverCheckResult,
TransceiverExclusiveListCheck,
TransceiverExclusiveListCheckResult,
)
from netcad.topology import transceiver_model_matches, transceiver_type_matches
from netcad.feats.topology import transceiver_model_matches, transceiver_type_matches
from netcad.device import Device, DeviceInterface

# -----------------------------------------------------------------------------
Expand Down
19 changes: 15 additions & 4 deletions netcam_aioeos/vlans/eos_check_switchports.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
# Public Imports
# -----------------------------------------------------------------------------

from netcad.checks import CheckResultsCollection
from netcad.checks import CheckResultsCollection, CheckStatus

from netcad.helpers import range_string, parse_istrange

from netcad.vlans.checks.check_switchports import (
from netcad.feats.vlans.checks.check_switchports import (
SwitchportCheckCollection,
SwitchportCheck,
SwitchportCheckResult,
Expand Down Expand Up @@ -177,14 +177,25 @@ def on_mismatch(_field, _expd_v, _msrd_v):
if _field != "trunk_allowed_vlans":
return

if _msrd_v == "ALL":
result.logs.warn(
_field,
dict(
message="Using 'ALL' is not recommended",
expected=_expd_v,
measured=_msrd_v,
),
)
return CheckStatus.PASS

_msrd_v_set = parse_istrange(_msrd_v)

_expd_v_set = set(expd_allowed_vids)
_info = dict()
if _missing := _expd_v_set - _msrd_v_set:
_info["missing"] = _missing
_info["missing"] = list(_missing)
if _extra := _msrd_v_set - _expd_v_set:
_info["extra"] = _extra
_info["extra"] = list(_extra)

result.logs.INFO("trunk_allowed_vlans_mismatch", _info)

Expand Down
8 changes: 4 additions & 4 deletions netcam_aioeos/vlans/eos_check_vlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
from netcad.device import Device
from netcad.checks import CheckResultsCollection, CheckStatus

from netcad.vlans.checks.check_vlans import (
from netcad.feats.vlans.checks.check_vlans import (
VlanCheckCollection,
VlanCheckResult,
VlanExclusiveListCheck,
VlanExclusiveListCheckResult,
)

from netcad.vlans import VlanDesignServiceConfig
from netcad.feats.vlans import VlanDesignServiceConfig

# -----------------------------------------------------------------------------
# Private Imports
Expand Down Expand Up @@ -197,10 +197,10 @@ def eos_check_one_vlan(

if exclusive:
if missing_interfaces := expd_ifs_set - msrd_ifs_set:
result.logs.FAIL("interfaces", dict(missing=missing_interfaces))
result.logs.FAIL("interfaces", dict(missing=list(missing_interfaces)))

if extra_interfaces := msrd_ifs_set - expd_ifs_set:
result.logs.FAIL("interfaces", dict(extra=extra_interfaces))
result.logs.FAIL("interfaces", dict(extra=list(extra_interfaces)))

def on_mismatch(_field, _expd, _msrd):
if _field == "name":
Expand Down
17 changes: 12 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[tool.poetry]
name = "netcam-aioeos"
version = "0.8.0"
version = "1.0.0"
description = "NetCAD/CAM - Arista EOS/eAPI asyncio driver"
readme = "README.md"
authors = ["Jeremy Schulman"]

[tool.poetry.dependencies]
python = ">=3.10"
netcad = ">=0.12.0"
asyncssh = "*"
pydantic = "<2"
pydantic-env = "*"
netcad = ">=0.20.0"
pydantic-env = ">=0.3.0"
aio-eapi = ">=0.6.0"
asyncssh = "^2.14.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand All @@ -23,3 +22,11 @@ build-backend = "poetry.core.masonry.api"
color = true
ignore-module = true
exclude = ["tasks.py", "examples", "build", "venv"]

[tool.ruff]
# Set the maximum line length to 132.
# line-length = 132
lint.ignore = ["E731"]

[tool.ruff.lint.extend-per-file-ignores]
"__init__.py" = ["F401", "E402"]
22 changes: 0 additions & 22 deletions tasks.py

This file was deleted.

0 comments on commit 5bc443f

Please sign in to comment.