From 0367217395bac5ae992f4adc6162387fec6a6121 Mon Sep 17 00:00:00 2001 From: vitthalmagadum Date: Wed, 15 Jan 2025 04:59:58 -0500 Subject: [PATCH] addressed review comments: updated failure msga, test doc --- anta/input_models/flow_tracking.py | 6 +-- anta/tests/flow_tracking.py | 45 +++++++++++--------- examples/tests.yaml | 2 +- tests/units/anta_tests/test_flow_tracking.py | 32 +++++++------- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/anta/input_models/flow_tracking.py b/anta/input_models/flow_tracking.py index f0ced4693..79676d937 100644 --- a/anta/input_models/flow_tracking.py +++ b/anta/input_models/flow_tracking.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024 Arista Networks, Inc. +# Copyright (c) 2023-2025 Arista Networks, Inc. # Use of this source code is governed by the Apache License 2.0 # that can be found in the LICENSE file. """Module containing input models for flow tracking tests.""" @@ -44,10 +44,10 @@ def __str__(self) -> str: Examples -------- - InActive Timeout: 60000 Active Interval: 300000 + Inactive Timeout: 60000, Active Interval: 300000 """ - return f"InActive Timeout: {self.on_inactive_timeout} Active Interval: {self.on_interval}" + return f"Inactive Timeout: {self.on_inactive_timeout}, Active Interval: {self.on_interval}" class Exporter(BaseModel): diff --git a/anta/tests/flow_tracking.py b/anta/tests/flow_tracking.py index 8767e9aa4..8b3450a09 100644 --- a/anta/tests/flow_tracking.py +++ b/anta/tests/flow_tracking.py @@ -28,48 +28,51 @@ def validate_exporters(exporters: list[dict[str, str]], tracker_info: dict[str, Returns ------- list - Failure message if any exporter configuration does not match. + List of failure messages for any exporter configuration that does not match. """ - failed_log = [] + failure_messages = [] for exporter in exporters: exporter_name = exporter.name actual_exporter_info = tracker_info["exporters"].get(exporter_name) if not actual_exporter_info: - failed_log.append(f"Exporter: {exporter_name} - Not configured") + failure_messages.append(f"Exporter: {exporter_name} - Not configured") continue local_interface = actual_exporter_info["localIntf"] template_interval = actual_exporter_info["templateInterval"] if local_interface != exporter.local_interface: - failed_log.append(f"Exporter: {exporter_name} - Incorrect local interface - Expected: {exporter.local_interface} Actual: {local_interface}") + failure_messages.append(f"Exporter: {exporter_name} - Incorrect local interface - Expected: {exporter.local_interface}, Actual: {local_interface}") if template_interval != exporter.template_interval: - failed_log.append(f"Exporter: {exporter_name} - Incorrect template interval - Expected: {exporter.template_interval} Actual: {template_interval}") - return failed_log + failure_messages.append(f"Exporter: {exporter_name} - Incorrect template interval - Expected: {exporter.template_interval}, Actual: {template_interval}") + return failure_messages class VerifyHardwareFlowTrackerStatus(AntaTest): - """Verifies the hardware flow tracking. + """Verifies the hardware flow tracking configuration. This test performs the following checks: 1. Confirms that hardware flow tracking is running. - 2. Confirms that the specified input tracker is active. - 3. Optionally, checks the tracker interval/timeout configuration. - 4. Optionally, verifies the tracker exporter configuration + 2. For each specified flow tracker: + - Confirms that the specified input tracker is active. + - Optionally, checks the tracker interval/timeout configuration. + - Optionally, verifies the tracker exporter configuration Expected Results ---------------- * Success: The test will pass if all of the following conditions are met: - - All Hardware flow tracking is running. - - The specified input tracker is active. - - The tracker interval/timeout matches the expected values, if provided. - - The exporter configuration matches the expected values, if provided. + - Hardware flow tracking is running. + - For each specified flow tracker: + - The flow tracker is active. + - The tracker interval/timeout matches the expected values, if provided. + - The exporter configuration matches the expected values, if provided. * Failure: The test will fail if any of the following conditions are met: - Hardware flow tracking is not running. - - The specified input tracker is not active. - - The tracker interval/timeout does not match the expected values, if provided. - - The exporter configuration does not match the expected values, if provided. + - For each specified flow tracker: + - The flow tracker is not active. + - The tracker interval/timeout does not match the expected values, if provided. + - The exporter configuration does not match the expected values, if provided. Examples -------- @@ -128,11 +131,11 @@ def test(self) -> None: act_interval = tracker_info.get("activeInterval") if not all([inactive_interval == act_inactive, on_interval == act_interval]): self.result.is_failure( - f"{tracker} {tracker.record_export} - Incorrect durations - InActive Timeout: {act_inactive} OnActive Interval: {act_interval}" + f"{tracker}, {tracker.record_export} - Incorrect durations - Inactive Timeout: {act_inactive}, OnActive Interval: {act_interval}" ) # Check the input hardware tracker exporters configuration if tracker.exporters: - failed_log = validate_exporters(tracker.exporters, tracker_info) - for log in failed_log: - self.result.is_failure(f"{tracker} {log}") + failure_messages = validate_exporters(tracker.exporters, tracker_info) + for message in failure_messages: + self.result.is_failure(f"{tracker}, {message}") diff --git a/examples/tests.yaml b/examples/tests.yaml index ad344293e..973a1e010 100644 --- a/examples/tests.yaml +++ b/examples/tests.yaml @@ -162,7 +162,7 @@ anta.tests.field_notices: # Verifies if the device is exposed to FN0072, and if the issue has been mitigated. anta.tests.flow_tracking: - VerifyHardwareFlowTrackerStatus: - # Verifies the hardware flow tracking. + # Verifies the hardware flow tracking configuration. trackers: - name: FLOW-TRACKER record_export: diff --git a/tests/units/anta_tests/test_flow_tracking.py b/tests/units/anta_tests/test_flow_tracking.py index 8ab1bc3c7..6f7ed0a78 100644 --- a/tests/units/anta_tests/test_flow_tracking.py +++ b/tests/units/anta_tests/test_flow_tracking.py @@ -184,10 +184,10 @@ "expected": { "result": "failure", "messages": [ - "Flow Tracker: FLOW-TRACKER InActive Timeout: 6000 Active Interval: 30000 - Incorrect durations - " - "InActive Timeout: 60000 OnActive Interval: 300000", - "Flow Tracker: HARDWARE-TRACKER InActive Timeout: 60000 Active Interval: 300000 - Incorrect durations - " - "InActive Timeout: 6000 OnActive Interval: 30000", + "Flow Tracker: FLOW-TRACKER, Inactive Timeout: 6000, Active Interval: 30000 - Incorrect durations - " + "Inactive Timeout: 60000, OnActive Interval: 300000", + "Flow Tracker: HARDWARE-TRACKER, Inactive Timeout: 60000, Active Interval: 300000 - Incorrect durations - " + "Inactive Timeout: 6000, OnActive Interval: 30000", ], }, }, @@ -240,11 +240,11 @@ "expected": { "result": "failure", "messages": [ - "Flow Tracker: FLOW-TRACKER Exporter: CVP-FLOW - Incorrect local interface - Expected: Loopback10 Actual: Loopback0", - "Flow Tracker: FLOW-TRACKER Exporter: CVP-FLOW - Incorrect template interval - Expected: 3500000 Actual: 3600000", - "Flow Tracker: HARDWARE-TRACKER Exporter: Hardware-flow - Incorrect local interface - Expected: Loopback99 Actual: Loopback10", - "Flow Tracker: HARDWARE-TRACKER Exporter: Hardware-flow - Incorrect template interval - Expected: 3000000 Actual: 3600000", - "Flow Tracker: HARDWARE-TRACKER Exporter: Reverse-flow - Not configured", + "Flow Tracker: FLOW-TRACKER, Exporter: CVP-FLOW - Incorrect local interface - Expected: Loopback10, Actual: Loopback0", + "Flow Tracker: FLOW-TRACKER, Exporter: CVP-FLOW - Incorrect template interval - Expected: 3500000, Actual: 3600000", + "Flow Tracker: HARDWARE-TRACKER, Exporter: Hardware-flow - Incorrect local interface - Expected: Loopback99, Actual: Loopback10", + "Flow Tracker: HARDWARE-TRACKER, Exporter: Hardware-flow - Incorrect template interval - Expected: 3000000, Actual: 3600000", + "Flow Tracker: HARDWARE-TRACKER, Exporter: Reverse-flow - Not configured", ], }, }, @@ -327,13 +327,13 @@ "messages": [ "Flow Tracker: FLOW-Sample - Not found", "Flow Tracker: FLOW-TRIGGER - Disabled", - "Flow Tracker: HARDWARE-FLOW InActive Timeout: 60000 Active Interval: 300000 - Incorrect durations - " - "InActive Timeout: 6000 OnActive Interval: 30000", - "Flow Tracker: FLOW-TRACKER2 Exporter: CVP-FLOW - Incorrect local interface - Expected: Loopback10 Actual: Loopback0", - "Flow Tracker: FLOW-TRACKER2 Exporter: CVP-FLOW - Incorrect template interval - Expected: 3500000 Actual: 3600000", - "Flow Tracker: HARDWARE-TRACKER2 Exporter: Hardware-flow - Incorrect local interface - Expected: Loopback99 Actual: Loopback10", - "Flow Tracker: HARDWARE-TRACKER2 Exporter: Hardware-flow - Incorrect template interval - Expected: 3000000 Actual: 3600000", - "Flow Tracker: HARDWARE-TRACKER2 Exporter: Reverse-flow - Not configured", + "Flow Tracker: HARDWARE-FLOW, Inactive Timeout: 60000, Active Interval: 300000 - Incorrect durations - " + "Inactive Timeout: 6000, OnActive Interval: 30000", + "Flow Tracker: FLOW-TRACKER2, Exporter: CVP-FLOW - Incorrect local interface - Expected: Loopback10, Actual: Loopback0", + "Flow Tracker: FLOW-TRACKER2, Exporter: CVP-FLOW - Incorrect template interval - Expected: 3500000, Actual: 3600000", + "Flow Tracker: HARDWARE-TRACKER2, Exporter: Hardware-flow - Incorrect local interface - Expected: Loopback99, Actual: Loopback10", + "Flow Tracker: HARDWARE-TRACKER2, Exporter: Hardware-flow - Incorrect template interval - Expected: 3000000, Actual: 3600000", + "Flow Tracker: HARDWARE-TRACKER2, Exporter: Reverse-flow - Not configured", ], }, },