Skip to content

Commit

Permalink
add additional tests for failure cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sarunac committed Oct 24, 2024
1 parent 1fa755d commit 7bd330a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
7 changes: 4 additions & 3 deletions anta/tests/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
81 changes: 81 additions & 0 deletions tests/units/anta_tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]},
},
]

0 comments on commit 7bd330a

Please sign in to comment.