Skip to content

Commit

Permalink
Update tests for new AntaTemplate rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
mtache committed Jul 4, 2023
1 parent 80cd97f commit 8058801
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
13 changes: 8 additions & 5 deletions anta/tests/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import annotations

import logging
from typing import Any, Dict, cast

from anta.models import AntaTest, AntaTemplate

Expand Down Expand Up @@ -34,11 +33,15 @@ def test(self) -> None:

failures = []

for index, command in enumerate(self.instance_commands):
src, dst = (cast(Dict[str, str], command.template_params)["src"], cast(Dict[str, str], command.template_params)["dst"])
for command in self.instance_commands:
if command.template and command.template.vars and \
('src' and 'dst') in command.template.vars:
src, dst = command.template.vars["src"], command.template.vars["dst"]
else:
self.result.is_error('The destination IP(s) or the source interface/IP(s) are not provided as template_params')
return

command_output = cast(Dict[str, Dict[Any, Any]], self.instance_commands[index].output)
if "2 received" not in command_output["messages"][0]:
if "2 received" not in command.json_output["messages"][0]:
failures.append((src, dst))

if not failures:
Expand Down
15 changes: 9 additions & 6 deletions anta/tests/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,15 @@ def test(self) -> None:
"""

disabled_intf = []

for index, command in enumerate(self.instance_commands):
intf = cast(Dict[str, str], command.template_params).get("intf")
command_output = cast(Dict[str, Dict[Any, Any]], self.instance_commands[index].output)

if not command_output["interfaces"][intf]["proxyArp"]:
for command in self.instance_commands:
if command.template and command.template.vars and \
'intf' in command.template.vars:
intf = command.template.vars['intf']
else:
self.result.is_error('A list of interface(s) is not provided as template_params')
return
logger.debug(command)
if not command.json_output["interfaces"][intf]["proxyArp"]:
disabled_intf.append(intf)

if disabled_intf:
Expand Down
16 changes: 10 additions & 6 deletions anta/tests/routing/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,16 @@ def test(self, number: Optional[int] = None) -> None:

self.result.is_success()

for index, command in enumerate(self.instance_commands):
vrf = cast(Dict[str, str], command.template_params).get("vrf")
command_output = cast(Dict[str, Dict[Any, Any]], self.instance_commands[index].output)

peers = command_output["vrfs"][vrf]["peers"]
state_issue = _check_bgp_vrfs(command_output["vrfs"])
for command in self.instance_commands:
if command.template and command.template.vars and \
"vrf" in command.template.vars:
vrf = command.template.vars['vrf']
else:
self.result.is_error('A list of VRF(s) is not provided as template_params')
return

peers = command.json_output["vrfs"][vrf]["peers"]
state_issue = _check_bgp_vrfs(command.json_output["vrfs"])

if len(peers) != number:
self.result.is_failure(f"Expecting {number} BGP peer in vrf {vrf} and got {len(peers)}")
Expand Down
25 changes: 16 additions & 9 deletions anta/tests/stp.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ def test(self, mode: str = "mstp") -> None:

self.result.is_success()

for index, command in enumerate(self.instance_commands):
vlan_id = cast(Dict[str, str], command.template_params).get("vlan")
command_output = cast(Dict[str, Dict[Any, Any]], self.instance_commands[index].output)

if not (stp_mode := get_value(command_output, f"spanningTreeVlanInstances.{vlan_id}.spanningTreeVlanInstance.protocol")):
for command in self.instance_commands:
if command.template and command.template.vars and \
"vlan" in command.template.vars:
vlan_id = command.template.vars['vlan']
else:
self.result.is_error('A list of VLAN(s) is not provided as template_params')
return
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}")

elif stp_mode != mode:
Expand Down Expand Up @@ -153,11 +156,15 @@ def test(self) -> None:

self.result.is_success()

for index, command in enumerate(self.instance_commands):
vlan_id = cast(Dict[str, str], command.template_params)["vlan"]
command_output = cast(Dict[str, Dict[Any, Any]], self.instance_commands[index].output)
for command in self.instance_commands:
if command.template and command.template.vars and \
"vlan" in command.template.vars:
vlan_id = command.template.vars['vlan']
else:
self.result.is_error('A list of VLAN(s) is not provided as template_params')
return

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

else:
Expand Down

0 comments on commit 8058801

Please sign in to comment.