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

Feat(eos_validate_state): ANTA Provide custom ANTA catalog files to validate state #3655

Merged

Conversation

carl-baillargeon
Copy link
Contributor

Change Summary

Feature to provide custom ANTA catalog files to validate state.

Related Issue(s)

Fixes #3384

Component(s) name

arista.avd.eos_validate_state ANTA Mode

Proposed changes

  • New variable custom_anta_catalogs_dir added
  • The plugin will look for <hostname>.yml or <hostname>.yaml files representing a custom ANTA catalog and will merge that catalog on top of the auto-generated AVD tests.
  • <group>.yml or <group>.yaml can also be provided, group being an Ansible inventory group. The custom catalog will be merged on top of the auto-generated AVD tests for all devices part of that group.
  • ANTA has built-in validation with Pydantic and will remove duplicate tests automatically.

How to test

  • Add your custom catalogs to the intended/custom_anta_catalogs folder:
.
├── intended
│   ├── custom_anta_catalogs
│   │   ├── DC1_L3_LEAVES.yml
│   │   └── DC1-LEAF1A.yml

In this example, the DC1_L3_LEAVES.yml catalog will be applied to all devices under that group and DC1-LEAF1A.yml catalog will be applied to this host only. You can also use all.yml to target all devices in your Ansible inventory.

Follow the ANTA documentation to provide custom tests. Here are some examples: https://github.com/arista-netdevops-community/anta/blob/main/examples/tests.yaml

You can then run validate state in ANTA mode --> ansible-playbook playbooks/fabric-validate.yaml -e use_anta=true

Checklist

User Checklist

  • N/A

Repository Checklist

  • My code has been rebased from devel before I start
  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation and documentation have been updated accordingly.
  • I have updated molecule CI testing accordingly. (check the box if not applicable)

@github-actions github-actions bot added type: documentation Improvements or additions to documentation state: Documentation role Updated labels Feb 23, 2024
@github-actions github-actions bot added the role: build_output_folders issue related to build_output_folders role label Feb 27, 2024
@@ -168,7 +193,7 @@ def get_skipped_tests_from_tags(run_tags: tuple, skip_tags: tuple) -> list[dict]
return result


def generate_tests(device_name: str, hostvars: Mapping, skipped_tests: list[dict]) -> RawCatalogInput:
def generate_tests(device_name: str, hostvars: Mapping, skipped_tests: list[dict], custom_catalog: dict | None = None) -> RawCatalogInput:
"""Create the test catalog in a dictionnary format generated from the AVD test classes.

Test definitions are generated from the AVD structured_config for each AVD test classes and are merged together to create the final catalog.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add here something about custom_catalog

Suggested change
Test definitions are generated from the AVD structured_config for each AVD test classes and are merged together to create the final catalog.
Test definitions are generated from the AVD structured_config for each AVD test classes and are merged together with an optional custom_catalog to create the final catalog.

Copy link
Contributor Author

@carl-baillargeon carl-baillargeon Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c490e18.

Comment on lines 144 to 146
with file.open("r", encoding="UTF-8") as fd:
catalog = load(fd, Loader=CSafeLoader)
catalog_list.append(catalog)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception handling - what if the file opening is causing issue. e.g. permission denied or malformated yaml?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We catch all exceptions in the runner. The task will fail for the device that is trying to open the catalog only:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1461c6d

@gmuloc gmuloc added the one approval This PR has one approval and is only missing one more. label Feb 28, 2024
Copy link
Contributor

@gmuloc gmuloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for adding this! Let's merge when CI finihes :shipit:

@gmuloc gmuloc merged commit ba7f522 into aristanetworks:devel Feb 28, 2024
38 checks passed
sugetha24 pushed a commit to sugetha24/ansible-avd that referenced this pull request Feb 28, 2024
…alidate state (aristanetworks#3655)

Co-authored-by: Guillaume Mulocher <gmulocher@arista.com>
@carl-baillargeon carl-baillargeon deleted the feat/custom_catalog_input branch May 18, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
one approval This PR has one approval and is only missing one more. rn: Feat(eos_validate_state) role: build_output_folders issue related to build_output_folders role role: eos_validate_state state: CI Updated CI scenario have been updated in the PR state: Documentation role Updated type: documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat(eos_validate_state): ANTA Add the option of providing a custom test catalog to ANTA from AVD
3 participants