8000 fix(anta.tests): Update STP AntaTemplate tests by carl-baillargeon · Pull Request #351 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(anta.tests): Update STP AntaTemplate tests #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions anta/tests/stp.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,26 @@ def test(self, mode: str = "mstp") -> None:

self._check_stp_mode(mode)

self.result.is_success()
not_configured = []
wrong_stp_mode = []

for command in self.instance_commands:
if command.params and "vlan" in command.params:
vlan_id = command.params["vlan"]
if not (stp_mode := get_value(command.json_output, f"spanningTreeVlanInstances.{vlan_id}.spanningTreeVlanInstance.protocol")):
self.result.is_failure(f"STP mode '{mode}' not configured for VLAN {vlan_id}")
not_configured.append(vlan_id)

elif stp_mode != mode:
self.result.is_failure(f"Wrong STP mode configured for VLAN {vlan_id}")
wrong_stp_mode.append(vlan_id)

if not_configured:
self.result.is_failure(f"STP mode '{mode}' not configured for the following VLAN(s): {not_configured}")

if wrong_stp_mode:
self.result.is_failure(f"Wrong STP mode configured for the following VLAN(s): {wrong_stp_mode}")

if not not_configured and not wrong_stp_mode:
self.result.is_success()


class VerifySTPBlockedPorts(AntaTest):
Expand Down Expand Up @@ -147,22 +157,31 @@ def test(self) -> None:
Run VerifySTPForwardingPorts validation.
"""

self.result.is_success()
not_configured = []
not_forwarding = []

for command in self.instance_commands:
if command.params and "vlan" in command.params:
vlan_id = command.params["vlan"]

if not (topologies := get_value(command.json_output, "topologies")):
self.result.is_failure(f"STP instance for VLAN {vlan_id} is not configured")

not_configured.append(vlan_id)
else:
for value in topologies.values():
if int(vlan_id) in value["vlans"]:
interfaces_not_forwarding = [interface for interface, state in value["interfaces"].items() if state["state"] != "forwarding"]

if interfaces_not_forwarding:
self.result.is_failure(f"The following interface(s) are not in a forwarding state for VLAN {vlan_id}: {interfaces_not_forwarding}")
not_forwarding.append({f"VLAN {vlan_id}": interfaces_not_forwarding})

if not_configured:
self.result.is_failure(f"STP instance is not configured for the following VLAN(s): {not_configured}")

if not_forwarding:
self.result.is_failure(f"The following VLAN(s) have interface(s) that are not in a fowarding state: {not_forwarding}")

if not not_configured and not interfaces_not_forwarding:
self.result.is_success()


class VerifySTPRootPriority(AntaTest):
Expand Down
68 changes: 67 additions & 1 deletion tests/units/anta_tests/interfaces/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@
"expected_messages": ["The following interface(s) have Proxy-ARP disabled: ['Ethernet2']"],
},
{
"name": "error",
"name": "error-no-params",
"eos_data": [
{
"interfaces": {
Expand Down Expand Up @@ -1225,4 +1225,70 @@
"expected_result": "error",
"expected_messages": ["Command has template but no params were given"],
},
{
"name": "error-wrong-params",
"eos_data": [
{
"interfaces": {
"Ethernet1": {
"name": "Ethernet1",
"lineProtocolStatus": "up",
"interfaceStatus": "connected",
"mtu": 1500,
"interfaceAddressBrief": {
"ipAddr": {
"address": "10.1.0.0",
"maskLen": 31
}
},
"ipv4Routable240": False,
"ipv4Routable0": False,
"enabled": True,
"description": "P2P_LINK_TO_NW-CORE_Ethernet1",
"proxyArp": True,
"localProxyArp": False,
"gratuitousArp": False,
"vrf": "default",
"urpf": "disable",
"addresslessForwarding": "isInvalid",
"directedBroadcastEnabled": False,
"maxMssIngress": 0,
"maxMssEgress": 0
}
}
},
{
"interfaces": {
"Ethernet2": {
"name": "Ethernet2",
"lineProtocolStatus": "up",
"interfaceStatus": "connected",
"mtu": 1500,
"interfaceAddressBrief": {
"ipAddr": {
"address": "10.1.0.2",
"maskLen": 31
}
},
"ipv4Routable240": False,
"ipv4Routable0": False,
"enabled": True,
"description": "P2P_LINK_TO_SW-CORE_Ethernet1",
"proxyArp": True,
"localProxyArp": False,
"gratuitousArp": False,
"vrf": "default",
"urpf": "disable",
"addresslessForwarding": "isInvalid",
"directedBroadcastEnabled": False,
"maxMssIngress": 0,
"maxMssEgress": 0
}
}
}
],
"side_effect": {"template_params": [{'wrong': 'Ethernet1'}]},
"expected_result": "error",
"expected_messages": ["Cannot render template 'show ip interface {intf}': wrong parameters"],
},
]
86 changes: 76 additions & 10 deletions tests/units/anta_tests/stp/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
],
"side_effect": {"mode": "rstp", "template_params": [{"vlan": 10}, {"vlan": 20}]},
"expected_result": "failure",
"expected_messages": ["STP mode 'rstp' not configured for VLAN 10", "STP mode 'rstp' not configured for VLAN 20"]
"expected_messages": ["STP mode 'rstp' not configured for the following VLAN(s): [10, 20]"]
},
{
"name": "failure-wrong-mode",
Expand All @@ -67,10 +67,33 @@
],
"side_effect": {"mode": "rstp", "template_params": [{"vlan": 10}, {"vlan": 20}]},
"expected_result": "failure",
"expected_messages": ["Wrong STP mode configured for VLAN 10", "Wrong STP mode configured for VLAN 20"]
"expected_messages": ["Wrong STP mode configured for the following VLAN(s): [10, 20]"]
},
{
"name": "error",
"name": "failure-both",
"eos_data": [
{
"spanningTreeVlanInstances": {}
},
{
"spanningTreeVlanInstances": {
"20": {
"spanningTreeVlanInstance": {
"protocol": "mstp"
}
}
}
},
],
"side_effect": {"mode": "rstp", "template_params": [{"vlan": 10}, {"vlan": 20}]},
"expected_result": "failure",
"expected_messages": [
"STP mode 'rstp' not configured for the following VLAN(s): [10]",
"Wrong STP mode configured for the following VLAN(s): [20]"
]
},
{
"name": "error-wrong-mode",
"eos_data": [
{
"spanningTreeVlanInstances": {
Expand All @@ -96,7 +119,7 @@
"expected_messages": ["ValueError (Wrong STP mode provided. Valid modes are: ['mstp', 'rstp', 'rapidPvst'])"]
},
{
"name": "error",
"name": "error-no-params",
"eos_data": [
{
"spanningTreeVlanInstances": {
Expand All @@ -122,7 +145,7 @@
"expected_messages": ["Command has template but no params were given"]
},
{
"name": "error",
"name": "error-wrong-params",
"eos_data": [
{
"spanningTreeVlanInstances": {
Expand Down Expand Up @@ -318,8 +341,7 @@
],
"side_effect": {"template_params": [{"vlan": 10}, {"vlan": 20}]},
"expected_result": "failure",
"expected_messages": ["STP instance for VLAN 10 is not configured",
"STP instance for VLAN 20 is not configured"]
"expected_messages": ["STP instance is not configured for the following VLAN(s): [10, 20]"]
},
{
"name": "failure",
Expand Down Expand Up @@ -363,11 +385,11 @@
],
"side_effect": {"template_params": [{"vlan": 10}, {"vlan": 20}]},
"expected_result": "failure",
"expected_messages": ["The following interface(s) are not in a forwarding state for VLAN 10: ['Ethernet10']",
"The following interface(s) are not in a forwarding state for VLAN 20: ['Ethernet10']"]
"expected_messages": ["The following VLAN(s) have interface(s) that are not in a fowarding state: "
"[{'VLAN 10': ['Ethernet10']}, {'VLAN 20': ['Ethernet10']}]"]
},
{
"name": "error",
"name": "error-no-params",
"eos_data": [
{
"unmappedVlans": [],
Expand Down Expand Up @@ -409,6 +431,50 @@
"side_effect": {"template_params": None},
"expected_result": "error",
"expected_messages": ["Command has template but no params were given"]
},
{
"name": "error-wrong-params",
"eos_data": [
{
"unmappedVlans": [],
"topologies": {
"Mst10": {
"vlans": [
10
],
"interfaces": {
"Ethernet10": {
"state": "forwarding"
},
"MplsTrunk1": {
"state": "forwarding"
}
}
}
}
},
{
"unmappedVlans": [],
"topologies": {
"Mst20": {
"vlans": [
20
],
"interfaces": {
"Ethernet10": {
"state": "forwarding"
},
"MplsTrunk1": {
"state": "forwarding"
}
}
}
}
},
],
"side_effect": {"template_params": [{"wrong": 10}, {"wrong": 20}]},
"expected_result": "error",
"expected_messages": ["Cannot render template 'show spanning-tree topology vlan {vlan} status': wrong parameters"]
}
]

Expand Down
0