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

Fix(plugins): Prevent deprecation warnings when deprecated filters are not used #4199

Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ repos:
name: Build documentation for collection filter plugins.
entry: ansible-doc-extractor --template ansible_collections/arista/avd/docs/templates/plugin-docs.j2 --markdown "ansible_collections/arista/avd/docs/plugins/Filter_plugins/"
language: python
types: [python]
types_or: [python, yaml]
additional_dependencies: ['ansible-doc-extractor>=0.1.10', 'ansible-core>=2.15.0,<2.18.0']
files: ansible_collections/arista/avd/plugins/filter/
exclude: ^(ansible_collections/arista/avd/plugins/filter/deprecated_filters.py)$

- id: docs-plugin-lookup
name: Build documentation for collection lookup plugins.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def prepare_task_vars(self, task_vars: dict, structured_config_filename: str, *,
try:
task_vars[var] = self._templar.template(task_vars[var], fail_on_undefined=False)
except Exception as e:
raise AnsibleActionFail(f"Exception during templating of task_var '{var}'") from e
raise AnsibleActionFail(f"Exception during templating of task_var '{var}': '{e}'") from e

if not isinstance(task_vars, dict):
# Corner case for ansible-test where the passed task_vars is a nested chain-map
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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.
#
# deprecated filters - grouped together to avoid Ansible to generate warning on loading the module name...
#

__metaclass__ = type

from ansible.errors import AnsibleFilterError

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

PLUGIN_NAME_1 = "arista.avd.generate_lacp_id"
PLUGIN_NAME_2 = "arista.avd.generate_esi"
PLUGIN_NAME_3 = "arista.avd.generate_route_target"

try:
from pyavd.j2filters import generate_esi, generate_lacp_id, generate_route_target
except ImportError as e:
generate_lacp_id = RaiseOnUse(
AnsibleFilterError(
f"The '{PLUGIN_NAME_1}' plugin requires the 'pyavd' Python library. Got import error",
orig_exc=e,
)
)
generate_esi = RaiseOnUse(
AnsibleFilterError(
f"The '{PLUGIN_NAME_2}' plugin requires the 'pyavd' Python library. Got import error",
orig_exc=e,
)
)
generate_route_target = RaiseOnUse(
AnsibleFilterError(
f"The '{PLUGIN_NAME_3}' plugin requires the 'pyavd' Python library. Got import error",
orig_exc=e,
)
)


class FilterModule(object):
def filters(self):
return {
"generate_lacp_id": wrap_filter(PLUGIN_NAME_1)(generate_lacp_id),
"generate_esi": wrap_filter(PLUGIN_NAME_2)(generate_esi),
"generate_route_target": wrap_filter(PLUGIN_NAME_3)(generate_route_target),
}
66 changes: 0 additions & 66 deletions ansible_collections/arista/avd/plugins/filter/generate_esi.py

This file was deleted.

31 changes: 31 additions & 0 deletions ansible_collections/arista/avd/plugins/filter/generate_esi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
DOCUMENTATION:
name: generate_esi
collection: arista.avd
author: Arista Ansible Team (@aristanetworks)
version_added: "1.1"
short_description: Transforms short_esi `0303:0202:0101` to EVPN ESI format `0000:0000:0303:0202:0101`
description: Concatenates the given `esi_prefix` and `short_esi`.
positional: _input
options:
_input:
description: Short ESI value as per AVD definition in eos_designs.
type: string
required: true
esi_prefix:
description: ESI prefix value. Will be concatenated with the `short_esi`.
type: string
default: "0000:0000:"
deprecated:
removed_in: "5.0.0"
why: This filter is no longer used by AVD and is very simple to replace with generic Jinja syntax.
alternative: Use Jinja string concatenation instead like `{{ <esi_prefix> ~ <short_esi> }}`

EXAMPLES: |
---
esi: "{{ short_esi | arista.avd.generate_esi('deaf:beed:') }}"

RETURN:
_value:
description: Concatenated string of `esi_prefix` and `short_esi` like `0000:0000:0303:0202:0101`
type: string

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
DOCUMENTATION:
name: generate_lacp_id
collection: arista.avd
author: Arista Ansible Team (@aristanetworks)
version_added: "1.1"
short_description: Transforms short_esi `0303:0202:0101` to LACP ID format `0303.0202.0101`
description: Replaces `:` with `.`
positional: _input
options:
_input:
description: Short ESI value as per AVD definition in eos_designs.
type: string
required: true
deprecated:
removed_in: "5.0.0"
why: This filter is no longer used by AVD and is very simple to replace with a generic Jinja filter.
alternative: Use the builtin `replace` filter instead like `{{ <short_esi> | replace(':', '.') }}`

EXAMPLES: |-
---
lacp_id: "{{ short_esi | arista.avd.generate_lacp_id }}"

RETURN:
_value:
description: String based on LACP ID format like 0303.0202.0101
type: string

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
DOCUMENTATION:
name: generate_route_target
collection: arista.avd
author: Arista Ansible Team (@aristanetworks)
version_added: "1.1"
short_description: Transforms short_esi `0303:0202:0101` to route-target format `03:03:02:02:01:01`
description: Removes `:` and inserts new `:` for each two characters.
positional: _input
options:
_input:
description: Short ESI value as per AVD definition in eos_designs.
type: string
required: true
deprecated:
removed_in: "5.0.0"
why: This filter is no longer used by AVD and is very simple to replace with a generic Jinja filter.
alternative: |-
Use the builtin `ansible.builtin.regex_replace` filter instead like
`{{ <short_esi> | ansible.builtin.regex_replace('(\\d{2})(\\d{2}):(\\d{2})(\\d{2}):(\\d{2})(\\d{2})', '\\1:\\2:\\3:\\4:\\5:\\6') }}`

EXAMPLES: |-
---
rt: "{{ short_esi | arista.avd.generate_route_target }}"

RETURN:
_value:
description: String based on route-target format like 03:03:02:02:01:01
type: string
Loading