From 38237edd294f62a445dd7fe172d2cf0cfbeda907 Mon Sep 17 00:00:00 2001 From: Carl Baillargeon Date: Mon, 15 Jan 2024 17:01:56 -0500 Subject: [PATCH] Fix(eos_validate_state): ANTA Fix bug when skipping specific tests of AvdTestBGP (#3498) --- .../plugin_utils/eos_validate_state_utils/catalog.py | 10 +++++++++- .../python_modules/tests/avdtestrouting.py | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_validate_state_utils/catalog.py b/ansible_collections/arista/avd/plugins/plugin_utils/eos_validate_state_utils/catalog.py index 7f116788368..40e191376b5 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_validate_state_utils/catalog.py +++ b/ansible_collections/arista/avd/plugins/plugin_utils/eos_validate_state_utils/catalog.py @@ -3,6 +3,7 @@ # that can be found in the LICENSE file. from __future__ import annotations +import logging from typing import TYPE_CHECKING, Mapping from yaml import Dumper, dump, safe_load @@ -28,6 +29,8 @@ if TYPE_CHECKING: from .avdtestbase import AvdTestBase +LOGGER = logging.getLogger(__name__) + class Catalog: """ @@ -112,6 +115,8 @@ def _default_catalog(self) -> dict: # Check if the whole class is to be skipped class_skip_config = get_item(self.skipped_tests, "category", avd_test_class.__name__) if class_skip_config is not None and not class_skip_config.get("tests"): + msg = f"Skipping all tests of {avd_test_class.__name__} per the `skipped_tests` input variable." + LOGGER.info(msg) continue # Initialize the test class @@ -120,8 +125,11 @@ def _default_catalog(self) -> dict: # Remove the individual tests that are to be skipped if class_skip_config is not None and (avd_test_class_skipped_tests := class_skip_config.get("tests")) is not None: + msg = f"Skipping the following tests of {avd_test_class.__name__} per the `skipped_tests` input variable: " + msg += ", ".join(avd_test_class_skipped_tests) + LOGGER.info(msg) for anta_tests in generated_tests.values(): - anta_tests[:] = [test for test in anta_tests if list(test.keys())[0] not in avd_test_class_skipped_tests] + anta_tests[:] = [test for test in anta_tests if next(iter(test.keys())) not in avd_test_class_skipped_tests] default_catalog = self.merge_catalogs(default_catalog, generated_tests) diff --git a/ansible_collections/arista/avd/roles/eos_validate_state/python_modules/tests/avdtestrouting.py b/ansible_collections/arista/avd/roles/eos_validate_state/python_modules/tests/avdtestrouting.py index 8b71e63050c..34d0a93b9f6 100644 --- a/ansible_collections/arista/avd/roles/eos_validate_state/python_modules/tests/avdtestrouting.py +++ b/ansible_collections/arista/avd/roles/eos_validate_state/python_modules/tests/avdtestrouting.py @@ -90,7 +90,7 @@ def add_test(description: str, afi: str, bgp_neighbor_ip: str, safi: str = None) if safi: address_family["safi"] = safi - anta_tests.setdefault("bgp", []).append( + anta_tests.setdefault(f"{self.anta_module}.bgp", []).append( { "VerifyBGPSpecificPeers": { "address_families": [address_family], @@ -102,7 +102,7 @@ def add_test(description: str, afi: str, bgp_neighbor_ip: str, safi: str = None) if self.logged_get(key="router_bgp") is None or not self.validate_data(service_routing_protocols_model="multi-agent", logging_level="WARNING"): return None - anta_tests.setdefault("generic", []).append( + anta_tests.setdefault(f"{self.anta_module}.generic", []).append( { "VerifyRoutingProtocolModel": { "model": "multi-agent", @@ -134,4 +134,4 @@ def add_test(description: str, afi: str, bgp_neighbor_ip: str, safi: str = None) elif neighbor_peer_group["type"] == "evpn": add_test(description="bgp evpn peer state established (evpn)", afi="evpn", bgp_neighbor_ip=str(bgp_neighbor["ip_address"])) - return {self.anta_module: anta_tests} if anta_tests.get("bgp") else None + return anta_tests if anta_tests.get(f"{self.anta_module}.bgp") else None