Skip to content

Commit

Permalink
feat(anta): Management cvx enabled (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarunac authored Oct 28, 2024
1 parent a76ae07 commit fe94dfb
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
38 changes: 38 additions & 0 deletions anta/tests/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,41 @@ def test(self) -> None:
self.result.is_success()
else:
self.result.is_failure("Following patterns were not found: " + ",".join(failure_msgs))


class VerifyManagementCVX(AntaTest):
"""Verifies the management CVX global status.
Expected Results
----------------
* Success: The test will pass if the management CVX global status matches the expected status.
* Failure: The test will fail if the management CVX global status does not match the expected status.
Examples
--------
```yaml
anta.tests.configuration:
- VerifyManagementCVX:
enabled: true
```
"""

name = "VerifyManagementCVX"
description = "Verifies the management CVX global status."
categories: ClassVar[list[str]] = ["configuration"]
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show management cvx", revision=1)]

class Input(AntaTest.Input):
"""Input model for the VerifyManagementCVX test."""

enabled: bool
"""Whether management CVX must be enabled (True) or disabled (False)."""

@AntaTest.anta_test
def test(self) -> None:
"""Main test function for VerifyManagementCVX."""
command_output = self.instance_commands[0].json_output
self.result.is_success()
cluster_status = command_output["clusterStatus"]
if (cluster_state := cluster_status.get("enabled")) != self.inputs.enabled:
self.result.is_failure(f"Management CVX status is not valid: {cluster_state}")
2 changes: 2 additions & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ anta.tests.configuration:
regex_patterns:
- "^enable password.*$"
- "bla bla"
- VerifyManagementCVX:
enabled: true

anta.tests.connectivity:
- VerifyReachability:
Expand Down
35 changes: 34 additions & 1 deletion tests/units/anta_tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from typing import Any

from anta.tests.configuration import VerifyRunningConfigDiffs, VerifyRunningConfigLines, VerifyZeroTouch
from anta.tests.configuration import VerifyManagementCVX, VerifyRunningConfigDiffs, VerifyRunningConfigLines, VerifyZeroTouch
from tests.units.anta_tests import test

DATA: list[dict[str, Any]] = [
Expand Down Expand Up @@ -60,4 +60,37 @@
"inputs": {"regex_patterns": ["bla", "bleh"]},
"expected": {"result": "failure", "messages": ["Following patterns were not found: 'bla','bleh'"]},
},
{
"name": "success-enabled",
"test": VerifyManagementCVX,
"eos_data": [
{
"clusterStatus": {
"enabled": True,
}
}
],
"inputs": {"enabled": True},
"expected": {"result": "success"},
},
{
"name": "success-disabled",
"test": VerifyManagementCVX,
"eos_data": [
{
"clusterStatus": {
"enabled": False,
}
}
],
"inputs": {"enabled": False},
"expected": {"result": "success"},
},
{
"name": "failure",
"test": VerifyManagementCVX,
"eos_data": [{"clusterStatus": {}}],
"inputs": {"enabled": False},
"expected": {"result": "failure", "messages": ["Management CVX status is not valid: None"]},
},
]

0 comments on commit fe94dfb

Please sign in to comment.