Skip to content
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

feat(anta.tests): Add LANZ, PTP and GreenT #517

Merged
merged 9 commits into from
Feb 1, 2024
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
60 changes: 60 additions & 0 deletions anta/tests/greent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""
Test functions related to GreenT (Postcard Telemetry) in EOS
"""
from __future__ import annotations

from anta.models import AntaCommand, AntaTest


class VerifyGreenTCounters(AntaTest):
"""
Verifies whether GRE packets are sent.

Expected Results:
* success: if >0 gre packets are sent
* failure: if no gre packets are sent
"""

name = "VerifyGreenTCounters"
description = "Verifies if the greent counters are incremented."
categories = ["greent"]
commands = [AntaCommand(command="show monitor telemetry postcard counters")]

@AntaTest.anta_test
def test(self) -> None:
command_output = self.instance_commands[0].json_output

if command_output["grePktSent"] > 0:
self.result.is_success()
else:
self.result.is_failure("GRE packets are not sent")


class VerifyGreenT(AntaTest):
"""
Verifies whether GreenT policy is created.

Expected Results:
* success: if there exists any policy other than "default" policy.
* failure: if no policy is created.
"""

name = "VerifyGreenT"
description = "Verifies whether greent policy is created."
categories = ["greent"]
commands = [AntaCommand(command="show monitor telemetry postcard policy profile")]

@AntaTest.anta_test
def test(self) -> None:
command_output = self.instance_commands[0].json_output

out = [f"{i} policy is created" for i in command_output["profiles"].keys() if "default" not in i]

if len(out) > 0:
for i in out:
self.result.is_success(f"{i} policy is created")
else:
self.result.is_failure("policy is not created")
34 changes: 34 additions & 0 deletions anta/tests/lanz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""
Test functions related to LANZ
"""

from __future__ import annotations

from anta.models import AntaCommand, AntaTest


class VerifyLANZ(AntaTest):
"""
Verifies if LANZ is enabled

Expected results:
* success: the test will pass if lanz is enabled
* failure: the test will fail if lanz is disabled
"""

name = "VerifyLANZ"
description = "Verifies if LANZ is enabled."
categories = ["lanz"]
commands = [AntaCommand(command="show queue-monitor length status")]

@AntaTest.anta_test
def test(self) -> None:
command_output = self.instance_commands[0].json_output

if command_output["lanzEnabled"] is not True:
self.result.is_failure("LANZ is not enabled")
else:
self.result.is_success("LANZ is enabled")
33 changes: 33 additions & 0 deletions anta/tests/ptp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""
Test functions related to PTP (Precision Time Protocol) in EOS
"""
from __future__ import annotations

from anta.models import AntaCommand, AntaTest


class VerifyPtpStatus(AntaTest):
"""
Verifies whether the PTP agent is enabled globally.

Expected Results:
* success: The test will pass if the PTP agent is enabled globally.
* failure: The test will fail if the PTP agent is enabled globally.
"""

name = "VerifyPtpStatus"
description = "Verifies if the PTP agent is enabled."
categories = ["ptp"]
commands = [AntaCommand(command="show ptp")]

@AntaTest.anta_test
def test(self) -> None:
command_output = self.instance_commands[0].json_output

if "ptpMode" in command_output.keys():
self.result.is_success()
else:
self.result.is_failure("PTP agent disabled")
47 changes: 47 additions & 0 deletions tests/units/anta_tests/test_greent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Data for testing anta.tests.configuration"""
from __future__ import annotations

from typing import Any

from anta.tests.greent import VerifyGreenT, VerifyGreenTCounters

DATA: list[dict[str, Any]] = [
{
"name": "success",
"test": VerifyGreenTCounters,
"eos_data": [{"sampleRcvd": 0, "sampleDiscarded": 0, "multiDstSampleRcvd": 0, "grePktSent": 1, "sampleSent": 0}],
"inputs": None,
"expected": {"result": "success"},
},
{
"name": "failure",
"test": VerifyGreenTCounters,
"eos_data": [{"sampleRcvd": 0, "sampleDiscarded": 0, "multiDstSampleRcvd": 0, "grePktSent": 0, "sampleSent": 0}],
"inputs": None,
"expected": {"result": "failure"},
},
{
"name": "success",
"test": VerifyGreenT,
"eos_data": [{"sampleRcvd": 0, "sampleDiscarded": 0, "multiDstSampleRcvd": 0, "grePktSent": 1, "sampleSent": 0}],
"inputs": None,
"expected": {"result": "success"},
},
{
"name": "failure",
"test": VerifyGreenT,
"eos_data": [
{
"profiles": {
"default": {"interfaces": [], "appliedInterfaces": [], "samplePolicy": "default", "failures": {}, "appliedInterfaces6": [], "failures6": {}},
"testProfile": {"interfaces": [], "appliedInterfaces": [], "samplePolicy": "default", "failures": {}, "appliedInterfaces6": [], "failures6": {}},
}
}
],
"inputs": None,
"expected": {"result": "failure"},
},
]
27 changes: 27 additions & 0 deletions tests/units/anta_tests/test_lanz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Data for testing anta.tests.configuration"""
from __future__ import annotations

from typing import Any

from anta.tests.lanz import VerifyLANZ
from tests.lib.anta import test # noqa: F401; pylint: disable=W0611

DATA: list[dict[str, Any]] = [
{
"name": "success",
"test": VerifyLANZ,
"eos_data": [{"lanzEnabled": True}],
"inputs": None,
"expected": {"result": "success", "messages": ["LANZ is enabled"]},
},
{
"name": "failure",
"test": VerifyLANZ,
"eos_data": [{"lanzEnabled": False}],
"inputs": None,
"expected": {"result": "failure", "messages": ["LANZ is not enabled"]},
},
]
42 changes: 42 additions & 0 deletions tests/units/anta_tests/test_ptp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Data for testing anta.tests.configuration"""
from __future__ import annotations

from typing import Any

from anta.tests.ptp import VerifyPtpStatus

DATA: list[dict[str, Any]] = [
{
"name": "success",
"test": VerifyPtpStatus,
"eos_data": [
{
"ptpMode": "ptpBoundaryClock",
"ptpProfile": "ptpDefaultProfile",
"ptpClockSummary": {
"clockIdentity": "0xcc:1a:a3:ff:ff:c3:bf:eb",
"gmClockIdentity": "0x00:00:00:00:00:00:00:00",
"numberOfSlavePorts": 0,
"numberOfMasterPorts": 0,
"offsetFromMaster": 0,
"meanPathDelay": 0,
"stepsRemoved": 0,
"skew": 1.0,
},
"ptpIntfSummaries": {},
}
],
"inputs": None,
"expected": {"result": "success"},
},
{
"name": "failure",
"test": VerifyPtpStatus,
"eos_data": [{"ptpIntfSummaries": {}}],
"inputs": None,
"expected": {"result": "failure"},
},
]
Loading