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(anta): add AntaCatalog.dump() and AntaCatalog.merge() #657

Merged
merged 10 commits into from
Apr 29, 2024

Conversation

mtache
Copy link
Collaborator

@mtache mtache commented Apr 26, 2024

  • feat: add AntaCatalog.dump() and AntaCatalog.merge()
  • ci: add unit tests for anta.catalog module

Description

This PR also includes functions to merge AntaCatalog instances and dump as a YAML file:

  • AntaCatalog.merge() -> AntaCatalog
  • AntaCatalog.dump() -> AntaCatalogFile
  • AntaCatalogFile.yaml()

Script example:

#!/usr/bin/env python
from anta.catalog import AntaCatalog

from pathlib import Path
from anta.models import AntaTest


CATALOG_SUFFIX = '-catalog.yml'
CATALOG_DIR = 'intended/test_catalogs/'

if __name__ == "__main__":
    catalog = AntaCatalog()
    for file in Path(CATALOG_DIR).glob('*'+CATALOG_SUFFIX):
        c = AntaCatalog.parse(file)
        device = str(file).removesuffix(CATALOG_SUFFIX).removeprefix(CATALOG_DIR)
        print(f"Merging test catalog for device {device}")
        # Apply filters to all tests for this device
        for test in c.tests:
            test.inputs.filters = AntaTest.Input.Filters(tags=[device])
        catalog.merge(c)
    with open(Path('anta-catalog.yml'), "w") as f:
        f.write(catalog.dump().yaml())

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)

anta/catalog.py Outdated Show resolved Hide resolved
anta/catalog.py Outdated Show resolved Hide resolved
anta/catalog.py Outdated Show resolved Hide resolved
tests/units/test_catalog.py Show resolved Hide resolved
Copy link
Collaborator

@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 think we should put back the ValueError we had as it is a bit clearer than the cryptic pydantic error.

@gmuloc gmuloc merged commit ad126e8 into aristanetworks:main Apr 29, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants