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: New anta_workflow plugin using PyAVD #4196

Merged
merged 77 commits into from
Mar 14, 2025

Conversation

carl-baillargeon
Copy link
Contributor

@carl-baillargeon carl-baillargeon commented Jul 9, 2024

Change Summary

  • anta_workflow Ansible action plugin
  • anta_runner Ansible role
  • get_device_anta_catalog function in PyAVD to generate the ANTA catalogs
  • ANTA test index with their input factories in PyAVD

Requirements

NEEDS ANTA v1.3.0

On ANTA:

On AVD:

Component(s) name

PyAVD

Proposed changes

Example playbook for anta_runner role:

---
- name: Validate AVD
  hosts: GLOBAL
  tasks:
    - name: Validate states on EOS devices
      import_role:
        name: arista.avd.anta_runner
      vars:
        
        # AVD catalogs generation settings
        avd_catalogs_enabled: true  # Enable/disable AVD catalogs generation
        avd_catalogs_dir: "{{ inventory_dir }}/anta/avd_catalogs"  # Directory to store AVD catalogs
        avd_catalogs_allow_bgp_vrfs: true  # Allow BGP VRFs tests in AVD catalogs
        avd_catalogs_filters:
          # Skip VerifyNTP for all fabric devices
          - device_list: "{{ groups['GLOBAL'] }}"
            skip_tests:
              - VerifyNTP
          # Only VerifyReachability will run on DC1 devices
          - device_list: "{{ groups['DC1'] }}"
            run_tests:
              - VerifyReachability
        structured_dir: "{{ inventory_dir }}/intended/structured_configs"  # Directory to store structured configuration files
        avd_structured_config_file_format: "yml"  # Format of structured configuration files
        
        # User-defined catalogs settings
        user_catalogs_dir: "{{ inventory_dir }}/anta/user_catalogs"  # Directory to store user-defined catalogs

        # Runner settings
        anta_runner_timeout: 30 # Timeout for eAPI calls
        anta_runner_batch_size: 10  # Number of devices to process in parallel
        anta_runner_tags: []  # Tags to filter tests, can be used in conjunction with `anta_tags` host variable to filter tests
        anta_runner_dry_run: false  # Dry-run mode
        anta_runner_logs_dir: "{{ inventory_dir }}/anta/logs"  # Directory to store debug logs when running `-vvv`
        
        # Report settings
        anta_report_csv_path: "{{ inventory_dir }}/anta/reports/anta_report.csv"  # Path to store the CSV report
        anta_report_md_path: "{{ inventory_dir }}/anta/reports/anta_report.md"  # Path to store the Markdown report
        anta_report_json_path: "{{ inventory_dir }}/anta/reports/anta_report.json"  # Path to store the JSON report
        anta_report_hide_statuses:  # Filter out success and skipped tests from the report
          - success
          - skipped
    

How to test

1- Follow theTo test this pull request snippet from github-actions to install the requirements
2- By default, you can simply run the following playbook:

---
- name: Validate AVD
  hosts: GLOBAL
  tasks:
    - name: Validate states on EOS devices
      import_role:
        name: arista.avd.anta_runner

3- Test different variables/behaviors following the example playbook in Proposed changes

To-do list

  • Add reporting using anta.reporter.csv_reporter and anta.reporter.md_reporter. We should also be able to filter statuses (from plugin arguments) using ResultManager.filter()
  • Input factory for VerifyAVTRole 4e20dbf
  • Input factory for VerifyMlagStatus
  • Input factory for VerifyRoutingProtocolModel 4e20dbf
  • Input factory for VerifyAPIHttpsSSL
  • Input factory for VerifySpecificIPSecConn 4e20dbf
  • Input factory for VerifyStunClient 4e20dbf
  • Input factory for VerifyNTP 4e20dbf
  • Input factory for VerifyReloadCause 4e20dbf
  • VerifyLLDP factory: Add support for validate_state: false configuration 4e20dbf
  • Create the Ansible role (anta_runner) that will run the action plugin anta_workflows - Similar to cv_deploy & cv_workflows 18d98be
  • Complete anta_workflow plugin documentation under plugins.modules
  • Complete README.md for anta_runner role
  • Add support for BGP VRFs (see Feat(eos_validate_state): Add validation for BGP IPv4 peers in VRFs #4538)
  • Molecule tests

Some tests don't require any inputs, in that case we just update AVD_TEST_INDEX

Phase 2:

  • Unit tests
  • Expose more variables in the structured config schema for testing (accepted_pwr_supply_states, accepted_fan_states, accepted_xcvr_manufacturers, eos_version, etc.)
  • Add more ANTA tests 🥇
  • Improve reporting (HTML) when feat(anta): add test atomic results anta#937 is merged

Sorry, something went wrong.

Copy link

github-actions bot commented Jul 9, 2024

Review docs on Read the Docs

To test this pull request:

# Create virtual environment for this testing below the current directory
python -m venv test-avd-pr-4196
# Activate the virtual environment
source test-avd-pr-4196/bin/activate
# Install all requirements including PyAVD
pip install "pyavd[ansible] @ git+https://github.com/carl-baillargeon/avd.git@feat/move_anta_to_pyavd#subdirectory=python-avd" --force
# Install Ansible collection
ansible-galaxy collection install git+https://github.com/carl-baillargeon/avd.git#/ansible_collections/arista/avd/,feat/move_anta_to_pyavd --force
# Optional: Install AVD examples
cd test-avd-pr-4196
ansible-playbook arista.avd.install_examples

@gmuloc gmuloc added this to the v5.0.0 milestone Jul 25, 2024
@carl-baillargeon carl-baillargeon force-pushed the feat/move_anta_to_pyavd branch 2 times, most recently from 8853a02 to da57595 Compare August 13, 2024 18:18
@carl-baillargeon carl-baillargeon changed the title Feat: ANTA Integration to PyAVD Feat: New anta_workflow plugin and anta_runner role to Ansible AVD collection using PyAVD Aug 13, 2024
@carl-baillargeon carl-baillargeon force-pushed the feat/move_anta_to_pyavd branch from da57595 to 7b8c139 Compare August 17, 2024 14:59
Copy link

@ClausHolbechArista ClausHolbechArista removed this from the v5.0.0 milestone Sep 20, 2024
@carl-baillargeon carl-baillargeon changed the title Feat: New anta_workflow plugin and anta_runner role to Ansible AVD collection using PyAVD Feat: New anta_workflow plugin using PyAVD Oct 31, 2024
gmuloc and others added 6 commits November 13, 2024 14:29

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
for more information, see https://pre-commit.ci

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@github-actions github-actions bot added the state: CI Updated CI scenario have been updated in the PR label Nov 25, 2024
pre-commit-ci bot and others added 4 commits November 25, 2024 11:59
for more information, see https://pre-commit.ci
@ankudinov ankudinov self-requested a review March 7, 2025 14:30
Copy link
Contributor

@ankudinov ankudinov left a comment

Choose a reason for hiding this comment

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

I've tested the PR on the following inventory and AVD dev image.

In arista.avd.eos_validate_state we used to have save_catalog. I never used it, but I find it a bit confusing that anta_runner combines that under avd_catalogs_enabled togerther with activating/deactivating default tests. That could be a good thing, but when combined with re-writing the whole anta/ directory content. After playing with avd_catalogs_enabled and avd_catalogs_dir a bit it’s easy to create quite confusing setup, that will never be auto-cleaned. I’d propose following:

  • Overwrite everything, except user_catalogs_dir on every run. Also clean any old dirs and files.
  • Dump avd catalog only when avd_catalogs_enabled: true (already the case)
  • Introduce a knob to dump the combined catalog in some different location for debugging.

AVD catalogs are JSON by default. Do we have an option to dump them as YAML?

avd_catalogs_filters - I was able to make them work for hostnames, but not for groups. I'd consider at least adding some documentation. Ideally I'd convert device_list to a list, not a string, that accepts hostnames, group names and fails if host or group is not known.

anta_report_filter_statuses: [success] has no effect.

@github-actions github-actions bot removed the state: conflict PR with conflict label Mar 10, 2025
Copy link

Conflicts have been resolved. A maintainer will review the pull request shortly.

@carl-baillargeon
Copy link
Contributor Author

carl-baillargeon commented Mar 10, 2025

I've tested the PR on the following inventory and AVD dev image.

In arista.avd.eos_validate_state we used to have save_catalog. I never used it, but I find it a bit confusing that anta_runner combines that under avd_catalogs_enabled togerther with activating/deactivating default tests. That could be a good thing, but when combined with re-writing the whole anta/ directory content. After playing with avd_catalogs_enabled and avd_catalogs_dir a bit it’s easy to create quite confusing setup, that will never be auto-cleaned. I’d propose following:

  • Overwrite everything, except user_catalogs_dir on every run. Also clean any old dirs and files.
  • Dump avd catalog only when avd_catalogs_enabled: true (already the case)
  • Introduce a knob to dump the combined catalog in some different location for debugging.

AVD catalogs are JSON by default. Do we have an option to dump them as YAML?

avd_catalogs_filters - I was able to make them work for hostnames, but not for groups. I'd consider at least adding some documentation. Ideally I'd convert device_list to a list, not a string, that accepts hostnames, group names and fails if host or group is not known.

anta_report_filter_statuses: [success] has no effect.

Thanks for the review Petr! As discussed, we will implement the following feature in future PRs:
1- Introduce a knob to dump the combined catalog
2- AVD catalogs in YAML
3- Validate host + groups in the filters

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link
Contributor

@ankudinov ankudinov left a comment

Choose a reason for hiding this comment

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

LGTM

@gmuloc
Copy link
Contributor

gmuloc commented Mar 14, 2025

we can ignore coverage here - we are not having coverage on the ansible plugins right now but are looking at it - so we will take the hit.

gmuloc and others added 2 commits March 14, 2025 14:25

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

I have not reviewed the code thoroughly but this is preview so we will need another round of review.

Lets expose this to testers in the field to get feedback

@gmuloc gmuloc merged commit e23a812 into aristanetworks:devel Mar 14, 2025
54 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn: Feat role: build_output_folders issue related to build_output_folders role state: CI Updated CI scenario have been updated in the PR state: Documentation role Updated type: code quality CI and development toolset
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants