From 7bd330a39b49f2ec7d37d8d1983c6445a0382a7b Mon Sep 17 00:00:00 2001 From: sakti Date: Wed, 23 Oct 2024 21:28:00 -0700 Subject: [PATCH] add additional tests for failure cases --- anta/tests/configuration.py | 7 +- tests/units/anta_tests/test_configuration.py | 81 ++++++++++++++++++++ 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/anta/tests/configuration.py b/anta/tests/configuration.py index 17c35ba05..c1bf0c983 100644 --- a/anta/tests/configuration.py +++ b/anta/tests/configuration.py @@ -164,8 +164,9 @@ def test(self) -> None: for mount_state in mount_states: if mount_state["type"].startswith("Mcs"): mcs_mount_state_detected = True - if mount_state["state"] != "mountStateMountComplete": - self.result.is_failure(f"MCS Client mount states are not valid: {mount_states}") + state = mount_state["state"] + if state != "mountStateMountComplete": + self.result.is_failure(f"MCS Client mount states are not valid: {state}") if len(mount_states) == 0 or not mcs_mount_state_detected: - self.result.is_failure(f"MCS Client mount states are not present: {mount_states}") + self.result.is_failure("MCS Client mount states are not present") diff --git a/tests/units/anta_tests/test_configuration.py b/tests/units/anta_tests/test_configuration.py index ce2d47c7a..152e42446 100644 --- a/tests/units/anta_tests/test_configuration.py +++ b/tests/units/anta_tests/test_configuration.py @@ -81,4 +81,85 @@ "inputs": None, "expected": {"result": "success"}, }, + { + "name": "success-partial-non-mcs", + "test": VerifyMcsClientMounts, + "eos_data": [ + { + "mountStates": [ + {"path": "blah/blah/blah", "type": "blah::blah", "state": "mountStatePreservedUnmounted"}, + {"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStateMountComplete"}, + ] + }, + ], + "inputs": None, + "expected": {"result": "success"}, + }, + { + "name": "failure-nomounts", + "test": VerifyMcsClientMounts, + "eos_data": [ + {"mountStates": []}, + ], + "inputs": None, + "expected": {"result": "failure", "messages": ["MCS Client mount states are not present"]}, + }, + { + "name": "failure-mountStatePreservedUnmounted", + "test": VerifyMcsClientMounts, + "eos_data": [{"mountStates": [{"path": "mcs/v1/toSwitch/28-99-3a-8f-93-7b", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"}]}], + "inputs": None, + "expected": {"result": "failure", "messages": ["MCS Client mount states are not valid: mountStatePreservedUnmounted"]}, + }, + { + "name": "failure-partial-haclient", + "test": VerifyMcsClientMounts, + "eos_data": [ + { + "mountStates": [ + {"path": "mcs/v1/apiCfgRedState", "type": "Mcs::ApiConfigRedundancyState", "state": "mountStateMountComplete"}, + {"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"}, + ] + }, + ], + "inputs": None, + "expected": {"result": "failure", "messages": ["MCS Client mount states are not valid: mountStatePreservedUnmounted"]}, + }, + { + "name": "failure-full-haclient", + "test": VerifyMcsClientMounts, + "eos_data": [ + { + "mountStates": [ + {"path": "blah/blah/blah", "type": "blah::blahState", "state": "mountStatePreservedUnmounted"}, + {"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"}, + ] + }, + ], + "inputs": None, + "expected": {"result": "failure", "messages": ["MCS Client mount states are not valid: mountStatePreservedUnmounted"]}, + }, + { + "name": "failure-non-mcs-client", + "test": VerifyMcsClientMounts, + "eos_data": [ + {"mountStates": [{"path": "blah/blah/blah", "type": "blah::blahState", "state": "mountStatePreservedUnmounted"}]}, + ], + "inputs": None, + "expected": {"result": "failure", "messages": ["MCS Client mount states are not present"]}, + }, + { + "name": "failure-partial-mcs-client", + "test": VerifyMcsClientMounts, + "eos_data": [ + { + "mountStates": [ + {"path": "blah/blah/blah", "type": "blah::blahState", "state": "mountStatePreservedUnmounted"}, + {"path": "blah/blah/blah", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"}, + ] + }, + ], + "inputs": None, + "expected": {"result": "failure", "messages": ["MCS Client mount states are not valid: mountStatePreservedUnmounted"]}, + }, ]