Skip to content

Commit

Permalink
Log deprecation warnings
Browse files Browse the repository at this point in the history
Refactor validation error logging
  • Loading branch information
dlobato committed Jul 3, 2024
1 parent 8a83cd8 commit 9be5d2f
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions pyavd_cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ansible.plugins.loader import init_plugin_loader # type: ignore
from ansible.template import Templar # type: ignore
from ansible.vars.manager import VariableManager # type: ignore
from pyavd import ValidationResult
from pyavd import __version__ as pyavd_version # type: ignore
from pyavd import (
get_avd_facts,
Expand Down Expand Up @@ -47,13 +48,21 @@ def wrapper(*args, **kwargs):
return decorator_log_execution_time


def log_host_validation_result(hostname: str, result: ValidationResult) -> None:
for validation_error in result.validation_errors:
logger.error("%s: %s", hostname, validation_error)

for deprecation_warning in result.deprecation_warnings:
logger.warning("%s: %s", hostname, deprecation_warning)


def validate_hostvars(hostname: str, hostvars: dict, strict: bool):
results = validate_inputs(hostvars)
if results.failed:
for result in results.validation_errors:
logger.error("%s: %s", hostname, result)
if strict:
raise RuntimeError(f"{hostname} validate_inputs failed")
validation_result = validate_inputs(hostvars)

log_host_validation_result(hostname, validation_result)

if validation_result.failed and strict:
raise RuntimeError(f"{hostname} validate_inputs failed")

return hostname, hostvars

Expand All @@ -68,12 +77,12 @@ def build_structured_config(hostname: str, inputs: dict, avd_facts: dict):


def build_device_config(hostname: str, structured_config: dict, strict: bool):
results = validate_structured_config(structured_config)
if results.failed:
for result in results.validation_errors:
logger.error("%s: %s", hostname, result)
if strict:
raise RuntimeError(f"{hostname} validate_structured_config failed")
validation_result = validate_structured_config(structured_config)

log_host_validation_result(hostname, validation_result)

if validation_result.failed and strict:
raise RuntimeError(f"{hostname} validate_structured_config failed")

return hostname, get_device_config(structured_config)

Expand Down

0 comments on commit 9be5d2f

Please sign in to comment.