Skip to content

Commit

Permalink
Merge branch 'main' into fix/verify_ssh_status
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc authored Oct 10, 2024
2 parents 1d80c56 + 86e8602 commit 1f0fa4b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
11 changes: 2 additions & 9 deletions anta/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,11 @@ def __init__(

self.indexes_built: bool
self.tag_to_tests: defaultdict[str | None, set[AntaTestDefinition]]
self._tests_without_tags: set[AntaTestDefinition]
self._init_indexes()

def _init_indexes(self) -> None:
"""Init indexes related variables."""
self.tag_to_tests = defaultdict(set)
self._tests_without_tags = set()
self.indexes_built = False

@property
Expand Down Expand Up @@ -486,11 +484,7 @@ def build_indexes(self, filtered_tests: set[str] | None = None) -> None:
If a `filtered_tests` set is provided, only the tests in this set will be indexed.
This method populates two attributes:
- tag_to_tests: A dictionary mapping each tag to a set of tests that contain it.
- _tests_without_tags: A set of tests that do not have any tags.
This method populates the tag_to_tests attribute, which is a dictionary mapping tags to sets of tests.
Once the indexes are built, the `indexes_built` attribute is set to True.
"""
Expand All @@ -504,9 +498,8 @@ def build_indexes(self, filtered_tests: set[str] | None = None) -> None:
for tag in test_tags:
self.tag_to_tests[tag].add(test)
else:
self._tests_without_tags.add(test)
self.tag_to_tests[None].add(test)

self.tag_to_tests[None] = self._tests_without_tags
self.indexes_built = True

def clear_indexes(self) -> None:
Expand Down
5 changes: 1 addition & 4 deletions anta/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def prepare_tests(
# Using a set to avoid inserting duplicate tests
device_to_tests: defaultdict[AntaDevice, set[AntaTestDefinition]] = defaultdict(set)

# Create AntaTestRunner tuples from the tags
final_tests_count = 0
# Create the device to tests mapping from the tags
for device in inventory.devices:
if tags:
if not any(tag in device.tags for tag in tags):
Expand All @@ -160,8 +159,6 @@ def prepare_tests(
# Add the tests with matching tags from device tags
device_to_tests[device].update(catalog.get_tests_by_tags(device.tags))

final_tests_count += len(device_to_tests[device])

if len(device_to_tests.values()) == 0:
msg = (
f"There are no tests{f' matching the tags {tags} ' if tags else ' '}to run in the current test catalog and device inventory, please verify your inputs."
Expand Down
2 changes: 2 additions & 0 deletions anta/tests/flow_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pydantic import BaseModel

from anta.decorators import skip_on_platforms
from anta.models import AntaCommand, AntaTemplate, AntaTest
from anta.tools import get_failed_logs

Expand Down Expand Up @@ -151,6 +152,7 @@ def render(self, template: AntaTemplate) -> list[AntaCommand]:
"""Render the template for each hardware tracker."""
return [template.render(name=tracker.name) for tracker in self.inputs.trackers]

@skip_on_platforms(["cEOSLab", "vEOS-lab"])
@AntaTest.anta_test
def test(self) -> None:
"""Main test function for VerifyHardwareFlowTrackerStatus."""
Expand Down
8 changes: 4 additions & 4 deletions tests/units/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ def test_build_indexes_all(self) -> None:
"""Test AntaCatalog.build_indexes()."""
catalog: AntaCatalog = AntaCatalog.parse(DATA_DIR / "test_catalog_with_tags.yml")
catalog.build_indexes()
assert len(catalog._tests_without_tags) == 6
assert len(catalog.tag_to_tests[None]) == 6
assert "leaf" in catalog.tag_to_tests
assert len(catalog.tag_to_tests["leaf"]) == 3
all_unique_tests = catalog._tests_without_tags
all_unique_tests = catalog.tag_to_tests[None]
for tests in catalog.tag_to_tests.values():
all_unique_tests.update(tests)
assert len(all_unique_tests) == 11
Expand All @@ -275,8 +275,8 @@ def test_build_indexes_filtered(self) -> None:
catalog.build_indexes({"VerifyUptime", "VerifyCoredump", "VerifyL3MTU"})
assert "leaf" in catalog.tag_to_tests
assert len(catalog.tag_to_tests["leaf"]) == 1
assert len(catalog._tests_without_tags) == 1
all_unique_tests = catalog._tests_without_tags
assert len(catalog.tag_to_tests[None]) == 1
all_unique_tests = catalog.tag_to_tests[None]
for tests in catalog.tag_to_tests.values():
all_unique_tests.update(tests)
assert len(all_unique_tests) == 4
Expand Down

0 comments on commit 1f0fa4b

Please sign in to comment.