Skip to content

Commit

Permalink
add tests example and address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sarunac committed Oct 24, 2024
1 parent 7e2ba9a commit 01a4ca2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
10 changes: 3 additions & 7 deletions anta/tests/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class VerifyManagementCVX(AntaTest):
"""

name = "VerifyManagementCVX"
description = "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)]

Expand All @@ -167,9 +167,5 @@ def test(self) -> None:
command_output = self.instance_commands[0].json_output
self.result.is_success()
cluster_status = command_output["clusterStatus"]
if "enabled" in cluster_status:
cluster_state = cluster_status["enabled"]
if not cluster_state if self.inputs.enabled else cluster_state:
self.result.is_failure(f"Management cvx state is not valid: {cluster_state}")
else:
self.result.is_failure(f"Management cvx state is not valid: {cluster_status}")
if (cluster_state := cluster_status.get("enabled")) != self.inputs.enabled:
self.result.is_failure(f"Management cvx state 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
7 changes: 7 additions & 0 deletions tests/units/anta_tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@
"inputs": {"enabled": False},
"expected": {"result": "success"},
},
{
"name": "failure",
"test": VerifyManagementCVX,
"eos_data": [{"clusterStatus": {}}],
"inputs": {"enabled": False},
"expected": {"result": "failure", "messages": ["Management cvx state is not valid: None"]},
},
]

0 comments on commit 01a4ca2

Please sign in to comment.