Skip to content

Commit

Permalink
Feat: Check catalog funcionality
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc committed Sep 27, 2023
1 parent 69a6ae4 commit 34864a6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
32 changes: 32 additions & 0 deletions anta/catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2023 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""
Catalog related functions
"""
from __future__ import annotations

import logging

from anta.device import AsyncEOSDevice
from anta.models import AntaTest
from anta.result_manager import ResultManager

logger = logging.getLogger(__name__)


def is_catalog_valid(catalog: list[tuple[AntaTest, AntaTest.Input]]) -> ResultManager:
"""
TODO - for now a test requires a device but this may be revisited in the future
"""
# Mock device
mock_device = AsyncEOSDevice(name="mock", host="127.0.0.1", username="mock", password="mock")

manager = ResultManager()
# Instantiate each test to verify the Inputs are correct
for test_class, test_inputs in catalog:
# TODO - this is the same code with typing as in runner.py but somehow mypy complains that test_class
# ot type AntaTest is not callable
test_instance = test_class(device=mock_device, inputs=test_inputs) # type: ignore[operator]
manager.add_test_result(test_instance.result)
return manager
12 changes: 2 additions & 10 deletions anta/cli/check/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

import click

from anta.catalog import is_catalog_valid
from anta.cli.console import console
from anta.cli.utils import parse_catalog
from anta.device import AsyncEOSDevice
from anta.models import AntaTest
from anta.result_manager import ResultManager

logger = logging.getLogger(__name__)

Expand All @@ -37,14 +36,7 @@ def catalog(ctx: click.Context, catalog: list[tuple[AntaTest, AntaTest.Input]])
Check that the catalog is valid
"""
logger.info(f"Checking syntax of catalog {ctx.obj['catalog_path']}")
mock_device = AsyncEOSDevice(name="mock", host="127.0.0.1", username="mock", password="mock")
manager = ResultManager()
# Instantiate each test to verify the Inputs are correct
for test_class, test_inputs in catalog:
# TODO - this is the same code with typing as in runner.py but somehow mypy complains that test_class
# ot type AntaTest is not callable
test_instance = test_class(device=mock_device, inputs=test_inputs) # type: ignore[operator]
manager.add_test_result(test_instance.result)
manager = is_catalog_valid(catalog)
if manager.error_status:
console.print(f"[bold][red]Catalog {ctx.obj['catalog_path']} is invalid")
# TODO print nice report
Expand Down

0 comments on commit 34864a6

Please sign in to comment.