Skip to content

Commit

Permalink
addressed review comments: updated failure msga, test doc
Browse files Browse the repository at this point in the history
  • Loading branch information
vitthalmagadum committed Jan 15, 2025
1 parent d456acd commit 0367217
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 41 deletions.
6 changes: 3 additions & 3 deletions anta/input_models/flow_tracking.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down Expand Up @@ -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):
Expand Down
45 changes: 24 additions & 21 deletions anta/tests/flow_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down Expand Up @@ -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}")
2 changes: 1 addition & 1 deletion examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 16 additions & 16 deletions tests/units/anta_tests/test_flow_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
},
},
Expand Down Expand Up @@ -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",
],
},
},
Expand Down Expand Up @@ -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",
],
},
},
Expand Down

0 comments on commit 0367217

Please sign in to comment.