8000 doc(anta.tests): Updated docstrings for VerifyInterfaceUtilization test by geetanjalimanegslab · Pull Request #1111 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

doc(anta.tests): Updated docstrings for VerifyInterfaceUtilization test #1111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ repos:
name: Run Ruff formatter

- repo: https://github.com/pycqa/pylint
rev: "v3.3.5"
rev: "v3.3.6"
hooks:
- id: pylint
name: Check code style with pylint
Expand Down
28 changes: 19 additions & 9 deletions anta/tests/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ class VerifyInterfaceUtilization(AntaTest):
"""Verifies that the utilization of interfaces is below a certain threshold.

Load interval (default to 5 minutes) is defined in device configuration.
This test has been implemented for full-duplex interfaces only.

!!! warning
This test has been implemented for full-duplex interfaces only.

Expected Results
----------------
* Success: The test will pass if all interfaces have a usage below the threshold.
* Failure: The test will fail if one or more interfaces have a usage above the threshold.
* Error: The test will error out if the device has at least one non full-duplex interface.
* Failure: If any of the following occur:
- One or more interfaces have a usage above the threshold.
- The device has at least one non full-duplex interface.

Examples
--------
Expand All @@ -56,7 +59,7 @@ class Input(AntaTest.Input):
"""Input model for the VerifyInterfaceUtilization test."""

threshold: Percent = 75.0
"""Interface utilization threshold above which the test will fail. Defaults to 75%."""
"""Interface utilization threshold above which the test will fail."""

@AntaTest.anta_test
def test(self) -> None:
Expand All @@ -67,12 +70,19 @@ def test(self) -> None:
interfaces = self.instance_commands[1].json_output

for intf, rate in rates["interfaces"].items():
interface_data = []
# The utilization logic has been implemented for full-duplex interfaces only
if ((duplex := (interface := interfaces["interfaces"][intf]).get("duplex", None)) is not None and duplex != duplex_full) or (
(members := interface.get("memberInterfaces", None)) is not None and any(stats["duplex"] != duplex_full for stats in members.values())
):
self.result.is_failure(f"Interface {intf} or one of its member interfaces is not Full-Duplex. VerifyInterfaceUtilization has not been implemented.")
return
if not all([duplex := (interface := interfaces["interfaces"][intf]).get("duplex", None), duplex == duplex_full]):
if (members := interface.get("memberInterfaces", None)) is None:
self.result.is_failure(f"Interface: {intf} - Test not implemented for non-full-duplex interfaces - Expected: {duplex_full} Actual: {duplex}")
continue
interface_data = [(member_interface, state) for member_interface, stats in members.items() if (state := stats["duplex"]) != duplex_full]

for member_interface in interface_data:
self.result.is_failure(
f"Interface: {intf} Member Interface: {member_interface[0]} - Test not implemented for non-full-duplex interfaces - Expected: {duplex_full}"
f" Actual: {member_interface[1]}"
)

if (bandwidth := interfaces["interfaces"][intf]["bandwidth"]) == 0:
self.logger.debug("Interface %s has been ignored due to null bandwidth value", intf)
Expand Down
9 changes: 7 additions & 2 deletions tests/units/anta_tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@
"inputs": {"threshold": 70.0},
"expected": {
"result": "failure",
"messages": ["Interface Ethernet1/1 or one of its member interfaces is not Full-Duplex. VerifyInterfaceUtilization has not been implemented"],
"messages": ["Interface: Ethernet1/1 - Test not implemented for non-full-duplex interfaces - Expected: duplexFull Actual: duplexHalf"],
},
},
{
Expand Down Expand Up @@ -801,7 +801,12 @@
"inputs": {"threshold": 70.0},
"expected": {
"result": "failure",
"messages": ["Interface Port-Channel31 or one of its member interfaces is not Full-Duplex. VerifyInterfaceUtilization has not been implemented"],
"messages": [
"Interface: Port-Channel31 Member Interface: Ethernet3/1 - Test not implemented for non-full-duplex interfaces - Expected: duplexFull "
"Actual: duplexHalf",
"Interface: Port-Channel31 Member Interface: Ethernet4/1 - Test not implemented for non-full-duplex interfaces - Expected: duplexFull "
"Actual: duplexHalf",
],
},
},
{
Expand Down
0