From 01a4ca24efe08ba9a96b6e4749fa64b4b553695c Mon Sep 17 00:00:00 2001 From: sakti Date: Wed, 23 Oct 2024 21:43:15 -0700 Subject: [PATCH] add tests example and address review comments --- anta/tests/configuration.py | 10 +++------- examples/tests.yaml | 2 ++ tests/units/anta_tests/test_configuration.py | 7 +++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/anta/tests/configuration.py b/anta/tests/configuration.py index 0dab07a33..e2fa9083e 100644 --- a/anta/tests/configuration.py +++ b/anta/tests/configuration.py @@ -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)] @@ -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}") diff --git a/examples/tests.yaml b/examples/tests.yaml index d8f3332ae..167824757 100644 --- a/examples/tests.yaml +++ b/examples/tests.yaml @@ -98,6 +98,8 @@ anta.tests.configuration: regex_patterns: - "^enable password.*$" - "bla bla" + - VerifyManagementCVX: + enabled: True anta.tests.connectivity: - VerifyReachability: diff --git a/tests/units/anta_tests/test_configuration.py b/tests/units/anta_tests/test_configuration.py index 4bc44a16e..bf7c75262 100644 --- a/tests/units/anta_tests/test_configuration.py +++ b/tests/units/anta_tests/test_configuration.py @@ -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"]}, + }, ]