-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI(pyavd): Recompile schemas and templates on change (#4637)
- Loading branch information
Showing
18 changed files
with
397 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2023-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 __future__ import annotations | ||
|
||
from contextlib import suppress | ||
from pathlib import Path | ||
|
||
PYTHON_AVD_PATH = Path(__file__).parents[4] / "python-avd" | ||
RUNNING_FROM_SOURCE_PATH = PYTHON_AVD_PATH / "pyavd/running_from_src.txt" | ||
RUNNING_FROM_SOURCE = RUNNING_FROM_SOURCE_PATH.exists() | ||
|
||
if RUNNING_FROM_SOURCE: | ||
import sys | ||
|
||
# TODO: @gmuloc - once proper logging has been implemented for the collection, replace this with a log statement. | ||
# Note that we can't output anything to stdout or stderr in normal mode or it breaks ansible-sanity | ||
with suppress(ImportError): | ||
from ansible.utils.display import Display | ||
|
||
display = Display() | ||
|
||
display.v(f"AVD detected it is running from source, prepending the path to the source of pyavd '{PYTHON_AVD_PATH}' to PATH to use it.") | ||
|
||
sys.path = [str(PYTHON_AVD_PATH), *sys.path] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
ansible_collections/arista/avd/plugins/plugin_utils/utils/init_logging.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (c) 2023-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 __future__ import annotations | ||
|
||
import logging | ||
|
||
from ansible.utils.display import Display | ||
|
||
from .python_to_ansible_logging_handler import PythonToAnsibleHandler | ||
|
||
|
||
def init_pyavd_logging() -> None: | ||
""" | ||
Specify logger parameters for pyavd and schematools. | ||
The verbosity depends on the verbosity level passed to Ansible | ||
- Ansible verbosity 0 translate to a level of warning | ||
- Ansible verbosity 1 to 2 (-v to -vv) translates to a level of info | ||
- Ansible verbosity 3 and above translates to a level of debug | ||
""" | ||
pyavd_logger = logging.getLogger("pyavd") | ||
schema_tools_logger = logging.getLogger("schema_tools") | ||
# Avoid duplicate logs | ||
pyavd_logger.propagate = False | ||
schema_tools_logger.propagate = False | ||
|
||
pyavd_handler = PythonToAnsibleHandler(None) | ||
pyavd_formatter = logging.Formatter("[pyavd] - %(message)s") | ||
pyavd_handler.setFormatter(pyavd_formatter) | ||
|
||
pyavd_logger.addHandler(pyavd_handler) | ||
schema_tools_logger.addHandler(pyavd_handler) | ||
|
||
verbosity = Display().verbosity | ||
if verbosity >= 3: | ||
pyavd_logger.setLevel(logging.DEBUG) | ||
schema_tools_logger.setLevel(logging.DEBUG) | ||
elif verbosity > 0: | ||
pyavd_logger.setLevel(logging.INFO) | ||
schema_tools_logger.setLevel(logging.INFO) | ||
else: | ||
pyavd_logger.setLevel(logging.WARNING) | ||
schema_tools_logger.setLevel(logging.WARNING) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.