Skip to content

Commit 0367217

Browse files
addressed review comments: updated failure msga, test doc
1 parent d456acd commit 0367217

File tree

4 files changed

+44
-41
lines changed

4 files changed

+44
-41
lines changed

anta/input_models/flow_tracking.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023-2024 Arista Networks, Inc.
1+
# Copyright (c) 2023-2025 Arista Networks, Inc.
22
# Use of this source code is governed by the Apache License 2.0
33
# that can be found in the LICENSE file.
44
"""Module containing input models for flow tracking tests."""
@@ -44,10 +44,10 @@ def __str__(self) -> str:
4444
4545
Examples
4646
--------
47-
InActive Timeout: 60000 Active Interval: 300000
47+
Inactive Timeout: 60000, Active Interval: 300000
4848
4949
"""
50-
return f"InActive Timeout: {self.on_inactive_timeout} Active Interval: {self.on_interval}"
50+
return f"Inactive Timeout: {self.on_inactive_timeout}, Active Interval: {self.on_interval}"
5151

5252

5353
class Exporter(BaseModel):

anta/tests/flow_tracking.py

+24-21
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,51 @@ def validate_exporters(exporters: list[dict[str, str]], tracker_info: dict[str,
2828
Returns
2929
-------
3030
list
31-
Failure message if any exporter configuration does not match.
31+
List of failure messages for any exporter configuration that does not match.
3232
"""
33-
failed_log = []
33+
failure_messages = []
3434
for exporter in exporters:
3535
exporter_name = exporter.name
3636
actual_exporter_info = tracker_info["exporters"].get(exporter_name)
3737
if not actual_exporter_info:
38-
failed_log.append(f"Exporter: {exporter_name} - Not configured")
38+
failure_messages.append(f"Exporter: {exporter_name} - Not configured")
3939
continue
4040
local_interface = actual_exporter_info["localIntf"]
4141
template_interval = actual_exporter_info["templateInterval"]
4242

4343
if local_interface != exporter.local_interface:
44-
failed_log.append(f"Exporter: {exporter_name} - Incorrect local interface - Expected: {exporter.local_interface} Actual: {local_interface}")
44+
failure_messages.append(f"Exporter: {exporter_name} - Incorrect local interface - Expected: {exporter.local_interface}, Actual: {local_interface}")
4545

4646
if template_interval != exporter.template_interval:
47-
failed_log.append(f"Exporter: {exporter_name} - Incorrect template interval - Expected: {exporter.template_interval} Actual: {template_interval}")
48-
return failed_log
47+
failure_messages.append(f"Exporter: {exporter_name} - Incorrect template interval - Expected: {exporter.template_interval}, Actual: {template_interval}")
48+
return failure_messages
4949

5050

5151
class VerifyHardwareFlowTrackerStatus(AntaTest):
52-
"""Verifies the hardware flow tracking.
52+
"""Verifies the hardware flow tracking configuration.
5353
5454
This test performs the following checks:
5555
5656
1. Confirms that hardware flow tracking is running.
57-
2. Confirms that the specified input tracker is active.
58-
3. Optionally, checks the tracker interval/timeout configuration.
59-
4. Optionally, verifies the tracker exporter configuration
57+
2. For each specified flow tracker:
58+
- Confirms that the specified input tracker is active.
59+
- Optionally, checks the tracker interval/timeout configuration.
60+
- Optionally, verifies the tracker exporter configuration
6061
6162
Expected Results
6263
----------------
6364
* Success: The test will pass if all of the following conditions are met:
64-
- All Hardware flow tracking is running.
65-
- The specified input tracker is active.
66-
- The tracker interval/timeout matches the expected values, if provided.
67-
- The exporter configuration matches the expected values, if provided.
65+
- Hardware flow tracking is running.
66+
- For each specified flow tracker:
67+
- The flow tracker is active.
68+
- The tracker interval/timeout matches the expected values, if provided.
69+
- The exporter configuration matches the expected values, if provided.
6870
* Failure: The test will fail if any of the following conditions are met:
6971
- Hardware flow tracking is not running.
70-
- The specified input tracker is not active.
71-
- The tracker interval/timeout does not match the expected values, if provided.
72-
- The exporter configuration does not match the expected values, if provided.
72+
- For each specified flow tracker:
73+
- The flow tracker is not active.
74+
- The tracker interval/timeout does not match the expected values, if provided.
75+
- The exporter configuration does not match the expected values, if provided.
7376
7477
Examples
7578
--------
@@ -128,11 +131,11 @@ def test(self) -> None:
128131
act_interval = tracker_info.get("activeInterval")
129132
if not all([inactive_interval == act_inactive, on_interval == act_interval]):
130133
self.result.is_failure(
131-
f"{tracker} {tracker.record_export} - Incorrect durations - InActive Timeout: {act_inactive} OnActive Interval: {act_interval}"
134+
f"{tracker}, {tracker.record_export} - Incorrect durations - Inactive Timeout: {act_inactive}, OnActive Interval: {act_interval}"
132135
)
133136

134137
# Check the input hardware tracker exporters configuration
135138
if tracker.exporters:
136-
failed_log = validate_exporters(tracker.exporters, tracker_info)
137-
for log in failed_log:
138-
self.result.is_failure(f"{tracker} {log}")
139+
failure_messages = validate_exporters(tracker.exporters, tracker_info)
140+
for message in failure_messages:
141+
self.result.is_failure(f"{tracker}, {message}")

examples/tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ anta.tests.field_notices:
162162
# Verifies if the device is exposed to FN0072, and if the issue has been mitigated.
163163
anta.tests.flow_tracking:
164164
- VerifyHardwareFlowTrackerStatus:
165-
# Verifies the hardware flow tracking.
165+
# Verifies the hardware flow tracking configuration.
166166
trackers:
167167
- name: FLOW-TRACKER
168168
record_export:

tests/units/anta_tests/test_flow_tracking.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@
184184
"expected": {
185185
"result": "failure",
186186
"messages": [
187-
"Flow Tracker: FLOW-TRACKER InActive Timeout: 6000 Active Interval: 30000 - Incorrect durations - "
188-
"InActive Timeout: 60000 OnActive Interval: 300000",
189-
"Flow Tracker: HARDWARE-TRACKER InActive Timeout: 60000 Active Interval: 300000 - Incorrect durations - "
190-
"InActive Timeout: 6000 OnActive Interval: 30000",
187+
"Flow Tracker: FLOW-TRACKER, Inactive Timeout: 6000, Active Interval: 30000 - Incorrect durations - "
188+
"Inactive Timeout: 60000, OnActive Interval: 300000",
189+
"Flow Tracker: HARDWARE-TRACKER, Inactive Timeout: 60000, Active Interval: 300000 - Incorrect durations - "
190+
"Inactive Timeout: 6000, OnActive Interval: 30000",
191191
],
192192
},
193193
},
@@ -240,11 +240,11 @@
240240
"expected": {
241241
"result": "failure",
242242
"messages": [
243-
"Flow Tracker: FLOW-TRACKER Exporter: CVP-FLOW - Incorrect local interface - Expected: Loopback10 Actual: Loopback0",
244-
"Flow Tracker: FLOW-TRACKER Exporter: CVP-FLOW - Incorrect template interval - Expected: 3500000 Actual: 3600000",
245-
"Flow Tracker: HARDWARE-TRACKER Exporter: Hardware-flow - Incorrect local interface - Expected: Loopback99 Actual: Loopback10",
246-
"Flow Tracker: HARDWARE-TRACKER Exporter: Hardware-flow - Incorrect template interval - Expected: 3000000 Actual: 3600000",
247-
"Flow Tracker: HARDWARE-TRACKER Exporter: Reverse-flow - Not configured",
243+
"Flow Tracker: FLOW-TRACKER, Exporter: CVP-FLOW - Incorrect local interface - Expected: Loopback10, Actual: Loopback0",
244+
"Flow Tracker: FLOW-TRACKER, Exporter: CVP-FLOW - Incorrect template interval - Expected: 3500000, Actual: 3600000",
245+
"Flow Tracker: HARDWARE-TRACKER, Exporter: Hardware-flow - Incorrect local interface - Expected: Loopback99, Actual: Loopback10",
246+
"Flow Tracker: HARDWARE-TRACKER, Exporter: Hardware-flow - Incorrect template interval - Expected: 3000000, Actual: 3600000",
247+
"Flow Tracker: HARDWARE-TRACKER, Exporter: Reverse-flow - Not configured",
248248
],
249249
},
250250
},
@@ -327,13 +327,13 @@
327327
"messages": [
328328
"Flow Tracker: FLOW-Sample - Not found",
329329
"Flow Tracker: FLOW-TRIGGER - Disabled",
330-
"Flow Tracker: HARDWARE-FLOW InActive Timeout: 60000 Active Interval: 300000 - Incorrect durations - "
331-
"InActive Timeout: 6000 OnActive Interval: 30000",
332-
"Flow Tracker: FLOW-TRACKER2 Exporter: CVP-FLOW - Incorrect local interface - Expected: Loopback10 Actual: Loopback0",
333-
"Flow Tracker: FLOW-TRACKER2 Exporter: CVP-FLOW - Incorrect template interval - Expected: 3500000 Actual: 3600000",
334-
"Flow Tracker: HARDWARE-TRACKER2 Exporter: Hardware-flow - Incorrect local interface - Expected: Loopback99 Actual: Loopback10",
335-
"Flow Tracker: HARDWARE-TRACKER2 Exporter: Hardware-flow - Incorrect template interval - Expected: 3000000 Actual: 3600000",
336-
"Flow Tracker: HARDWARE-TRACKER2 Exporter: Reverse-flow - Not configured",
330+
"Flow Tracker: HARDWARE-FLOW, Inactive Timeout: 60000, Active Interval: 300000 - Incorrect durations - "
331+
"Inactive Timeout: 6000, OnActive Interval: 30000",
332+
"Flow Tracker: FLOW-TRACKER2, Exporter: CVP-FLOW - Incorrect local interface - Expected: Loopback10, Actual: Loopback0",
333+
"Flow Tracker: FLOW-TRACKER2, Exporter: CVP-FLOW - Incorrect template interval - Expected: 3500000, Actual: 3600000",
334+
"Flow Tracker: HARDWARE-TRACKER2, Exporter: Hardware-flow - Incorrect local interface - Expected: Loopback99, Actual: Loopback10",
335+
"Flow Tracker: HARDWARE-TRACKER2, Exporter: Hardware-flow - Incorrect template interval - Expected: 3000000, Actual: 3600000",
336+
"Flow Tracker: HARDWARE-TRACKER2, Exporter: Reverse-flow - Not configured",
337337
],
338338
},
339339
},

0 commit comments

Comments
 (0)