Skip to content

Commit

Permalink
Fix(eos_validate_state): ANTA Fix bug when skipping specific tests of…
Browse files Browse the repository at this point in the history
… AvdTestBGP (#3498)
  • Loading branch information
carl-baillargeon authored Jan 15, 2024
1 parent 36ff26b commit 38237ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +29,8 @@
if TYPE_CHECKING:
from .avdtestbase import AvdTestBase

LOGGER = logging.getLogger(__name__)


class Catalog:
"""
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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",
Expand Down Expand Up @@ -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

0 comments on commit 38237ed

Please sign in to comment.