Skip to content

Commit

Permalink
Merge branch 'devel' into samplePRBranch
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc authored Nov 28, 2024
2 parents 1d61e17 + 2775366 commit 2e10ead
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.4
rev: v0.8.0
hooks:
# Run the linter.
- id: ruff
Expand Down Expand Up @@ -213,7 +213,7 @@ repos:
additional_dependencies: ['Jinja2>=3.0.0', 'cryptography>=38.0.4', 'deepmerge>=1.1.0']

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.42.0
rev: v0.43.0
hooks:
- id: markdownlint
name: Check for Linting errors on Markdown files with settings defined in `.github/.markdownlint.yaml`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ def prepare_task_vars(self, task_vars: dict, structured_config_filename: str, *,
task_vars.update(read_vars(structured_config_filename))

# Read ansible variables and perform templating to support inline jinja2
for var in task_vars:
for var, value in task_vars.items():
# TODO: - reevaluate these variables
if str(var).startswith(("ansible", "molecule", "hostvars", "vars", "avd_switch_facts")):
continue
if self._templar.is_template(task_vars[var]):
if self._templar.is_template(value):
# Var contains a jinja2 template.
try:
task_vars[var] = self._templar.template(task_vars[var], fail_on_undefined=False)
task_vars[var] = self._templar.template(value, fail_on_undefined=False)
except Exception as e:
msg = f"Exception during templating of task_var '{var}': '{e}'"
raise AnsibleActionFail(msg) from e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def get_configlet(src_folder: str = "", prefix: str = "AVD", extension: str = "c
for file in src_configlets:
# Build structure only if configlet match device_filter.
if is_in_filter(hostname=file.stem, hostname_filter=device_filter):
name = prefix + "_" + file.stem if prefix != "none" else file.stem
name = f"{prefix}_{file.stem}" if prefix != "none" else file.stem
with file.open(encoding="utf8") as stream:
data = stream.read()
configlets[name] = data
Expand All @@ -222,10 +222,10 @@ def get_device_option_value(device_data_dict: dict, option_name: str) -> str | N
Value set for variable, else None
"""
if is_iterable(device_data_dict):
for option in device_data_dict:
if option_name == option:
return device_data_dict[option]
return None
return next(
(value for option, value in device_data_dict.items() if option_name == option),
None,
)
return None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
from .md_report import MDReport
from .results_manager import ResultsManager

__all__ = ["AnsibleEOSDevice", "get_anta_results", "AvdTestBase", "MDReport", "CSVReport", "ResultsManager", "ConfigManager"]
__all__ = ["AnsibleEOSDevice", "AvdTestBase", "CSVReport", "ConfigManager", "MDReport", "ResultsManager", "get_anta_results"]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from urllib.error import HTTPError

from ansible.errors import AnsibleActionFail, AnsibleConnectionFailure
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.connection import ConnectionError as AnsibleConnectionError

from ansible_collections.arista.avd.plugins.plugin_utils.pyavd_wrappers import RaiseOnUse

Expand Down Expand Up @@ -169,7 +169,7 @@ async def refresh(self) -> None:
except (AnsibleConnectionFailure, HTTPError) as e:
message = "Failed to connect to device"
anta_log_exception(e, message, logger)
except ConnectionError as e:
except AnsibleConnectionError as e:
message = "Error while getting the device information"
anta_log_exception(e, message, logger)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
default = get = RaiseOnUse(ImportError(f"The 'arista.avd' collection requires the 'pyavd' Python library. Got import error {e}"))

__all__ = [
"compile_searchpath",
"get_templar",
"log_message",
"NoAliasDumper",
"PythonToAnsibleContextFilter",
"PythonToAnsibleHandler",
"NoAliasDumper",
"get_validated_path",
"get_validated_value",
"cprofile",
"YamlDumper",
"YamlLoader",
"compile_searchpath",
"cprofile",
"default",
"get",
"get_templar",
"get_validated_path",
"get_validated_value",
"log_message",
"write_file",
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
from .avdtestsystem import AvdTestNTP, AvdTestReloadCause

__all__ = [
"AvdTestP2PIPReachability",
"AvdTestLoopback0Reachability",
"AvdTestLLDPTopology",
"AvdTestInbandReachability",
"AvdTestAPIHttpsSSL",
"AvdTestAvtPath",
"AvdTestAvtRole",
"AvdTestBGP",
"AvdTestDpsReachability",
"AvdTestHardware",
"AvdTestIPSecurity",
"AvdTestInbandReachability",
"AvdTestInterfacesState",
"AvdTestLLDPTopology",
"AvdTestLoopback0Reachability",
"AvdTestMLAG",
"AvdTestNTP",
"AvdTestP2PIPReachability",
"AvdTestReloadCause",
"AvdTestInterfacesState",
"AvdTestRoutingTable",
"AvdTestBGP",
"AvdTestAPIHttpsSSL",
"AvdTestStun",
"AvdTestIPSecurity",
"AvdTestDpsReachability",
"AvdTestAvtPath",
"AvdTestAvtRole",
]
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ target-version = "py310"
[tool.ruff.lint]
extend-select = ["ALL"]
ignore = [
"ANN101", # Missing type annotation for `self` in method - we know what self is..
"ANN102", # Missing type annotation for `cls` in classmethod - we know what cls is..
"D203", # Ignoring conflicting D* warnings - one-blank-line-before-class
"D212", # Ignoring conflicting D* warnings - multi-line-summary-first-line
"COM812", # Ignoring conflicting rules that may cause conflicts when used with the formatter
Expand Down
2 changes: 1 addition & 1 deletion python-avd/pyavd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
__version__ = "5.1.0"

__all__ = [
"ValidationResult",
"get_avd_facts",
"get_device_config",
"get_device_doc",
"get_device_structured_config",
"get_fabric_documentation",
"validate_inputs",
"validate_structured_config",
"ValidationResult",
]
11 changes: 6 additions & 5 deletions python-avd/pyavd/_cv/client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
# that can be found in the LICENSE file.
from __future__ import annotations

from asyncio.exceptions import TimeoutError
from re import compile, fullmatch
from asyncio.exceptions import TimeoutError as AsyncioTimeoutError
from re import compile as re_compile
from re import fullmatch

from grpclib.const import Status
from grpclib.exceptions import GRPCError

MSG_SIZE_EXCEEDED_REGEX = compile(r"grpc: received message larger than max \((?P<size>\d+) vs\. (?P<max>\d+)\)")
MSG_SIZE_EXCEEDED_REGEX = re_compile(r"grpc: received message larger than max \((?P<size>\d+) vs\. (?P<max>\d+)\)")


def get_cv_client_exception(exception: Exception, cv_client_details: str | None = None) -> Exception | None:
"""
Convert GRPCError or TimeoutError instances to an instance of the relevant subclass of CVClientException.
Convert GRPCError or AsyncioTimeoutError instances to an instance of the relevant subclass of CVClientException.
Parameters:
exception: Exception to convert.
Expand All @@ -33,7 +34,7 @@ def get_cv_client_exception(exception: Exception, cv_client_details: str | None
new_exception.max_size = int(matches.group("max"))
new_exception.size = int(matches.group("size"))
return new_exception
if isinstance(exception, TimeoutError):
if isinstance(exception, AsyncioTimeoutError):
return CVTimeoutError(cv_client_details, *exception.args)

# Last resort return None so calling exception handling can just raise the single error instead of a chain.
Expand Down
5 changes: 3 additions & 2 deletions python-avd/pyavd/_cv/client/versioning.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Copyright (c) 2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
from re import compile, fullmatch
from re import compile as re_compile
from re import fullmatch

from .constants import CVAAS_VERSION_STRING

# The double braces are escaping braces for the f-string. The regex pattern will get a single brace.
VERSION_PATTERN = compile(rf"(\d{{4}}\.\d{{1,2}}\.\d{{1,2}}|{CVAAS_VERSION_STRING})")
VERSION_PATTERN = re_compile(rf"(\d{{4}}\.\d{{1,2}}\.\d{{1,2}}|{CVAAS_VERSION_STRING})")


class CvVersion:
Expand Down
2 changes: 1 addition & 1 deletion python-avd/pyavd/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"batch",
"compare_dicts",
"default",
"get",
"get_all",
"get_all_with_path",
"get_indices_of_duplicate_items",
"get_ip_from_ip_prefix",
"get_ip_from_pool",
"get_item",
"get",
"get_v2",
"groupby",
"groupby_obj",
Expand Down
8 changes: 4 additions & 4 deletions python-avd/schema_tools/metaschema/meta_schema_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def _descendant_tables(self) -> set[str]:

return descendant_tables

def model_post_init(self, __context: Any) -> None:
def model_post_init(self, context: Any) -> None:
"""
Overrides BaseModel.model_post_init.
Expand Down Expand Up @@ -473,7 +473,7 @@ def model_post_init(self, __context: Any) -> None:
else:
self.items._is_first_list_key = True

return super().model_post_init(__context)
return super().model_post_init(context)


class AvdSchemaDict(AvdSchemaBaseModel):
Expand Down Expand Up @@ -552,7 +552,7 @@ def _descendant_tables(self) -> set[str]:

return descendant_tables

def model_post_init(self, __context: Any) -> None:
def model_post_init(self, context: Any) -> None:
"""
Overrides BaseModel.model_post_init.
Expand All @@ -572,7 +572,7 @@ def model_post_init(self, __context: Any) -> None:
childschema._key = f"<{key}>"
childschema._parent_schema = self

return super().model_post_init(__context)
return super().model_post_init(context)


class AristaAvdSchema(AvdSchemaDict):
Expand Down
2 changes: 1 addition & 1 deletion python-avd/tests/pyavd/j2filters/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestDefaultFilter:
@pytest.mark.parametrize("default_value", DEFAULT_VALUE_LIST)
def test_default(self, primary_value: Any, default_value: Any) -> None:
resp = default(primary_value, *default_value)
if isinstance(primary_value, Undefined) or primary_value is None and len(DEFAULT_VALUE_LIST) >= 1:
if isinstance(primary_value, Undefined) or (primary_value is None and len(DEFAULT_VALUE_LIST) >= 1):
for i in default_value:
if isinstance(i, Undefined) or i is None or i == "":
continue
Expand Down

0 comments on commit 2e10ead

Please sign in to comment.