Skip to content

Commit 53a3ecf

Browse files
authored
Merge branch 'main' into feat/bgp_modules
2 parents 8142645 + 2931fe1 commit 53a3ecf

6 files changed

Lines changed: 262 additions & 72 deletions

File tree

anta/tests/configuration.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -126,41 +126,3 @@ def test(self) -> None:
126126
self.result.is_success()
127127
else:
128128
self.result.is_failure("Following patterns were not found: " + ",".join(failure_msgs))
129-
130-
131-
class VerifyManagementCVX(AntaTest):
132-
"""Verifies the management CVX global status.
133-
134-
Expected Results
135-
----------------
136-
* Success: The test will pass if the management CVX global status matches the expected status.
137-
* Failure: The test will fail if the management CVX global status does not match the expected status.
138-
139-
Examples
140-
--------
141-
```yaml
142-
anta.tests.configuration:
143-
- VerifyManagementCVX:
144-
enabled: true
145-
```
146-
"""
147-
148-
name = "VerifyManagementCVX"
149-
description = "Verifies the management CVX global status."
150-
categories: ClassVar[list[str]] = ["configuration"]
151-
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show management cvx", revision=1)]
152-
153-
class Input(AntaTest.Input):
154-
"""Input model for the VerifyManagementCVX test."""
155-
156-
enabled: bool
157-
"""Whether management CVX must be enabled (True) or disabled (False)."""
158-
159-
@AntaTest.anta_test
160-
def test(self) -> None:
161-
"""Main test function for VerifyManagementCVX."""
162-
command_output = self.instance_commands[0].json_output
163-
self.result.is_success()
164-
cluster_status = command_output["clusterStatus"]
165-
if (cluster_state := cluster_status.get("enabled")) != self.inputs.enabled:
166-
self.result.is_failure(f"Management CVX status is not valid: {cluster_state}")

anta/tests/cvx.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright (c) 2023-2024 Arista Networks, Inc.
2+
# Use of this source code is governed by the Apache License 2.0
3+
# that can be found in the LICENSE file.
4+
"""Module related to the CVX tests."""
5+
6+
# Mypy does not understand AntaTest.Input typing
7+
# mypy: disable-error-code=attr-defined
8+
from __future__ import annotations
9+
10+
from typing import TYPE_CHECKING, ClassVar
11+
12+
from anta.models import AntaCommand, AntaTest
13+
14+
if TYPE_CHECKING:
15+
from anta.models import AntaTemplate
16+
17+
18+
class VerifyMcsClientMounts(AntaTest):
19+
"""Verify if all MCS client mounts are in mountStateMountComplete.
20+
21+
Expected Results
22+
----------------
23+
* Success: The test will pass if the MCS mount status on MCS Clients are mountStateMountComplete.
24+
* Failure: The test will fail even if one switch's MCS client mount status is not mountStateMountComplete.
25+
26+
Examples
27+
--------
28+
```yaml
29+
anta.tests.cvx:
30+
- VerifyMcsClientMounts:
31+
```
32+
"""
33+
34+
categories: ClassVar[list[str]] = ["cvx"]
35+
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show management cvx mounts", revision=1)]
36+
37+
@AntaTest.anta_test
38+
def test(self) -> None:
39+
"""Main test function for VerifyMcsClientMounts."""
40+
command_output = self.instance_commands[0].json_output
41+
self.result.is_success()
42+
mount_states = command_output["mountStates"]
43+
mcs_mount_state_detected = False
44+
for mount_state in mount_states:
45+
if not mount_state["type"].startswith("Mcs"):
46+
continue
47+
mcs_mount_state_detected = True
48+
if (state := mount_state["state"]) != "mountStateMountComplete":
49+
self.result.is_failure(f"MCS Client mount states are not valid: {state}")
50+
51+
if not mcs_mount_state_detected:
52+
self.result.is_failure("MCS Client mount states are not present")
53+
54+
55+
class VerifyManagementCVX(AntaTest):
56+
"""Verifies the management CVX global status.
57+
58+
Expected Results
59+
----------------
60+
* Success: The test will pass if the management CVX global status matches the expected status.
61+
* Failure: The test will fail if the management CVX global status does not match the expected status.
62+
63+
64+
Examples
65+
--------
66+
```yaml
67+
anta.tests.cvx:
68+
- VerifyManagementCVX:
69+
enabled: true
70+
```
71+
"""
72+
73+
categories: ClassVar[list[str]] = ["cvx"]
74+
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show management cvx", revision=1)]
75+
76+
class Input(AntaTest.Input):
77+
"""Input model for the VerifyManagementCVX test."""
78+
79+
enabled: bool
80+
"""Whether management CVX must be enabled (True) or disabled (False)."""
81+
82+
@AntaTest.anta_test
83+
def test(self) -> None:
84+
"""Main test function for VerifyManagementCVX."""
85+
command_output = self.instance_commands[0].json_output
86+
self.result.is_success()
87+
cluster_status = command_output["clusterStatus"]
88+
if (cluster_state := cluster_status.get("enabled")) != self.inputs.enabled:
89+
self.result.is_failure(f"Management CVX status is not valid: {cluster_state}")

docs/api/test.cvx.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
anta_title: ANTA catalog for CVX tests
3+
---
4+
<!--
5+
~ Copyright (c) 2023-2024 Arista Networks, Inc.
6+
~ Use of this source code is governed by the Apache License 2.0
7+
~ that can be found in the LICENSE file.
8+
-->
9+
10+
::: anta.tests.cvx
11+
options:
12+
show_root_heading: false
13+
show_root_toc_entry: false
14+
show_bases: false
15+
merge_init_into_class: false
16+
anta_hide_test_module_description: true
17+
show_labels: true
18+
filters:
19+
- "!test"
20+
- "!render"

examples/tests.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ anta.tests.configuration:
9898
regex_patterns:
9999
- "^enable password.*$"
100100
- "bla bla"
101+
102+
anta.tests.cvx:
103+
- VerifyMcsClientMounts:
101104
- VerifyManagementCVX:
102105
enabled: true
103106

tests/units/anta_tests/test_configuration.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from typing import Any
99

10-
from anta.tests.configuration import VerifyManagementCVX, VerifyRunningConfigDiffs, VerifyRunningConfigLines, VerifyZeroTouch
10+
from anta.tests.configuration import VerifyRunningConfigDiffs, VerifyRunningConfigLines, VerifyZeroTouch
1111
from tests.units.anta_tests import test
1212

1313
DATA: list[dict[str, Any]] = [
@@ -60,37 +60,4 @@
6060
"inputs": {"regex_patterns": ["bla", "bleh"]},
6161
"expected": {"result": "failure", "messages": ["Following patterns were not found: 'bla','bleh'"]},
6262
},
63-
{
64-
"name": "success-enabled",
65-
"test": VerifyManagementCVX,
66-
"eos_data": [
67-
{
68-
"clusterStatus": {
69-
"enabled": True,
70-
}
71-
}
72-
],
73-
"inputs": {"enabled": True},
74-
"expected": {"result": "success"},
75-
},
76-
{
77-
"name": "success-disabled",
78-
"test": VerifyManagementCVX,
79-
"eos_data": [
80-
{
81-
"clusterStatus": {
82-
"enabled": False,
83-
}
84-
}
85-
],
86-
"inputs": {"enabled": False},
87-
"expected": {"result": "success"},
88-
},
89-
{
90-
"name": "failure",
91-
"test": VerifyManagementCVX,
92-
"eos_data": [{"clusterStatus": {}}],
93-
"inputs": {"enabled": False},
94-
"expected": {"result": "failure", "messages": ["Management CVX status is not valid: None"]},
95-
},
9663
]

tests/units/anta_tests/test_cvx.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Copyright (c) 2023-2024 Arista Networks, Inc.
2+
# Use of this source code is governed by the Apache License 2.0
3+
# that can be found in the LICENSE file.
4+
"""Data for testing anta.tests.cvx."""
5+
6+
from __future__ import annotations
7+
8+
from typing import Any
9+
10+
from anta.tests.cvx import VerifyManagementCVX, VerifyMcsClientMounts
11+
from tests.units.anta_tests import test
12+
13+
DATA: list[dict[str, Any]] = [
14+
{
15+
"name": "success",
16+
"test": VerifyMcsClientMounts,
17+
"eos_data": [{"mountStates": [{"path": "mcs/v1/toSwitch/28-99-3a-8f-93-7b", "type": "Mcs::DeviceConfigV1", "state": "mountStateMountComplete"}]}],
18+
"inputs": None,
19+
"expected": {"result": "success"},
20+
},
21+
{
22+
"name": "success-haclient",
23+
"test": VerifyMcsClientMounts,
24+
"eos_data": [
25+
{
26+
"mountStates": [
27+
{"path": "mcs/v1/apiCfgRedState", "type": "Mcs::ApiConfigRedundancyState", "state": "mountStateMountComplete"},
28+
{"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStateMountComplete"},
29+
]
30+
},
31+
],
32+
"inputs": None,
33+
"expected": {"result": "success"},
34+
},
35+
{
36+
"name": "success-partial-non-mcs",
37+
"test": VerifyMcsClientMounts,
38+
"eos_data": [
39+
{
40+
"mountStates": [
41+
{"path": "blah/blah/blah", "type": "blah::blah", "state": "mountStatePreservedUnmounted"},
42+
{"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStateMountComplete"},
43+
]
44+
},
45+
],
46+
"inputs": None,
47+
"expected": {"result": "success"},
48+
},
49+
{
50+
"name": "failure-nomounts",
51+
"test": VerifyMcsClientMounts,
52+
"eos_data": [
53+
{"mountStates": []},
54+
],
55+
"inputs": None,
56+
"expected": {"result": "failure", "messages": ["MCS Client mount states are not present"]},
57+
},
58+
{
59+
"name": "failure-mountStatePreservedUnmounted",
60+
"test": VerifyMcsClientMounts,
61+
"eos_data": [{"mountStates": [{"path": "mcs/v1/toSwitch/28-99-3a-8f-93-7b", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"}]}],
62+
"inputs": None,
63+
"expected": {"result": "failure", "messages": ["MCS Client mount states are not valid: mountStatePreservedUnmounted"]},
64+
},
65+
{
66+
"name": "failure-partial-haclient",
67+
"test": VerifyMcsClientMounts,
68+
"eos_data": [
69+
{
70+
"mountStates": [
71+
{"path": "mcs/v1/apiCfgRedState", "type": "Mcs::ApiConfigRedundancyState", "state": "mountStateMountComplete"},
72+
{"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"},
73+
]
74+
},
75+
],
76+
"inputs": None,
77+
"expected": {"result": "failure", "messages": ["MCS Client mount states are not valid: mountStatePreservedUnmounted"]},
78+
},
79+
{
80+
"name": "failure-full-haclient",
81+
"test": VerifyMcsClientMounts,
82+
"eos_data": [
83+
{
84+
"mountStates": [
85+
{"path": "blah/blah/blah", "type": "blah::blahState", "state": "mountStatePreservedUnmounted"},
86+
{"path": "mcs/v1/toSwitch/00-1c-73-74-c0-8b", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"},
87+
]
88+
},
89+
],
90+
"inputs": None,
91+
"expected": {"result": "failure", "messages": ["MCS Client mount states are not valid: mountStatePreservedUnmounted"]},
92+
},
93+
{
94+
"name": "failure-non-mcs-client",
95+
"test": VerifyMcsClientMounts,
96+
"eos_data": [
97+
{"mountStates": [{"path": "blah/blah/blah", "type": "blah::blahState", "state": "mountStatePreservedUnmounted"}]},
98+
],
99+
"inputs": None,
100+
"expected": {"result": "failure", "messages": ["MCS Client mount states are not present"]},
101+
},
102+
{
103+
"name": "failure-partial-mcs-client",
104+
"test": VerifyMcsClientMounts,
105+
"eos_data": [
106+
{
107+
"mountStates": [
108+
{"path": "blah/blah/blah", "type": "blah::blahState", "state": "mountStatePreservedUnmounted"},
109+
{"path": "blah/blah/blah", "type": "Mcs::DeviceConfigV1", "state": "mountStatePreservedUnmounted"},
110+
]
111+
},
112+
],
113+
"inputs": None,
114+
"expected": {"result": "failure", "messages": ["MCS Client mount states are not valid: mountStatePreservedUnmounted"]},
115+
},
116+
{
117+
"name": "success-enabled",
118+
"test": VerifyManagementCVX,
119+
"eos_data": [
120+
{
121+
"clusterStatus": {
122+
"enabled": True,
123+
}
124+
}
125+
],
126+
"inputs": {"enabled": True},
127+
"expected": {"result": "success"},
128+
},
129+
{
130+
"name": "success-disabled",
131+
"test": VerifyManagementCVX,
132+
"eos_data": [
133+
{
134+
"clusterStatus": {
135+
"enabled": False,
136+
}
137+
}
138+
],
139+
"inputs": {"enabled": False},
140+
"expected": {"result": "success"},
141+
},
142+
{
143+
"name": "failure",
144+
"test": VerifyManagementCVX,
145+
"eos_data": [{"clusterStatus": {}}],
146+
"inputs": {"enabled": False},
147+
"expected": {"result": "failure", "messages": ["Management CVX status is not valid: None"]},
148+
},
149+
]

0 commit comments

Comments
 (0)