Skip to content

Commit

Permalink
issue_785 Handling review comments: updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VitthalMagadum committed Aug 23, 2024
1 parent ab44d24 commit ddbbfc5
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 22 deletions.
17 changes: 7 additions & 10 deletions anta/tests/routing/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,14 +1407,11 @@ def test(self) -> None:


class VerifyBgpRouteMaps(AntaTest):
"""Verifies BGP Inbound Outbound route-maps of BGP IPv4 peer(s).
Checks whether the correct route maps are applied in the correct direction
(inbound or outbound) on the specified IPv4 BGP neighbors.
"""Verifies BGP inbound and outbound route-maps of BGP IPv4 peer(s).
Expected Results
----------------
* Success: The test will pass if the route map names applied on each neighbor match the expected configuration.
* Success: The test will pass if the correct route maps are applied in the correct direction(inbound or outbound) on the specified IPv4 BGP neighbors..
* Failure: The test will fail if BGP peers are not configured or any neighbor has an incorrect or missing route map in either the inbound or outbound direction.
Examples
Expand All @@ -1432,7 +1429,7 @@ class VerifyBgpRouteMaps(AntaTest):
"""

name = "VerifyBgpRouteMaps"
description = "Verifies BGP Inbound Outbound route-maps of BGP IPv4 peer(s)."
description = "Verifies BGP inbound and outbound route-maps of BGP IPv4 peer(s)."
categories: ClassVar[list[str]] = ["bgp"]
commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaTemplate(template="show bgp neighbors {peer} vrf {vrf}", revision=3)]

Expand Down Expand Up @@ -1487,12 +1484,12 @@ def test(self) -> None:
continue

# Verify Inbound route-map
if inbound_route_map and (inbound_map := peer_detail.get("routeMapInbound")) != inbound_route_map:
failure[vrf].update({"routeMapInbound": inbound_map})
if inbound_route_map and (inbound_map := peer_detail.get("routeMapInbound", "Not Configured")) != inbound_route_map:
failure[vrf].update({"Inbound route-map": inbound_map})

# Verify Outbound route-map
if outbound_route_map and (outbound_map := peer_detail.get("routeMapOutbound")) != outbound_route_map:
failure[vrf].update({"routeMapOutbound": outbound_map})
if outbound_route_map and (outbound_map := peer_detail.get("routeMapOutbound", "Not Configured")) != outbound_route_map:
failure[vrf].update({"Outbound route-map": outbound_map})

if failure[vrf]:
failures[peer] = failure
Expand Down
125 changes: 113 additions & 12 deletions tests/units/anta_tests/routing/test_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4375,14 +4375,30 @@
},
},
},
{
"vrfs": {
"MGMT": {
"peerList": [
{
"peerAddress": "10.100.0.10",
"routeMapInbound": "RM-MLAG-PEER-IN",
"routeMapOutbound": "RM-MLAG-PEER-OUT",
}
]
},
},
},
],
"inputs": {
"bgp_peers": [{"peer_address": "10.100.0.8", "vrf": "default", "inbound_route_map": "RM-MLAG-PEER-IN", "outbound_route_map": "RM-MLAG-PEER-OUT"}]
"bgp_peers": [
{"peer_address": "10.100.0.8", "vrf": "default", "inbound_route_map": "RM-MLAG-PEER-IN", "outbound_route_map": "RM-MLAG-PEER-OUT"},
{"peer_address": "10.100.0.10", "vrf": "MGMT", "inbound_route_map": "RM-MLAG-PEER-IN", "outbound_route_map": "RM-MLAG-PEER-OUT"},
]
},
"expected": {"result": "success"},
},
{
"name": "failure",
"name": "failure-incorrect-route-map",
"test": VerifyBgpRouteMaps,
"eos_data": [
{
Expand All @@ -4398,20 +4414,37 @@
},
},
},
{
"vrfs": {
"MGMT": {
"peerList": [
{
"peerAddress": "10.100.0.10",
"routeMapInbound": "RM-MLAG-PEER",
"routeMapOutbound": "RM-MLAG-PEER",
}
]
},
},
},
],
"inputs": {
"bgp_peers": [{"peer_address": "10.100.0.8", "vrf": "default", "inbound_route_map": "RM-MLAG-PEER-IN", "outbound_route_map": "RM-MLAG-PEER-OUT"}]
"bgp_peers": [
{"peer_address": "10.100.0.8", "vrf": "default", "inbound_route_map": "RM-MLAG-PEER-IN", "outbound_route_map": "RM-MLAG-PEER-OUT"},
{"peer_address": "10.100.0.10", "vrf": "MGMT", "inbound_route_map": "RM-MLAG-PEER-IN", "outbound_route_map": "RM-MLAG-PEER-OUT"},
]
},
"expected": {
"result": "failure",
"messages": [
"The following BGP peers are not configured or has an incorrect or missing route map in either the inbound or outbound direction:\n"
"{'10.100.0.8': {'default': {'routeMapInbound': 'RM-MLAG-PEER', 'routeMapOutbound': 'RM-MLAG-PEER'}}}"
"{'10.100.0.8': {'default': {'Inbound route-map': 'RM-MLAG-PEER', 'Outbound route-map': 'RM-MLAG-PEER'}}, "
"'10.100.0.10': {'MGMT': {'Inbound route-map': 'RM-MLAG-PEER', 'Outbound route-map': 'RM-MLAG-PEER'}}}"
],
},
},
{
"name": "failure-inbound-map",
"name": "failure-incorrect-inbound-map",
"test": VerifyBgpRouteMaps,
"eos_data": [
{
Expand All @@ -4427,34 +4460,102 @@
},
},
},
{
"vrfs": {
"MGMT": {
"peerList": [
{
"peerAddress": "10.100.0.10",
"routeMapInbound": "RM-MLAG-PEER",
"routeMapOutbound": "RM-MLAG-PEER",
}
]
},
},
},
],
"inputs": {"bgp_peers": [{"peer_address": "10.100.0.8", "vrf": "default", "inbound_route_map": "RM-MLAG-PEER-IN"}]},
"inputs": {
"bgp_peers": [
{"peer_address": "10.100.0.8", "vrf": "default", "inbound_route_map": "RM-MLAG-PEER-IN"},
{"peer_address": "10.100.0.10", "vrf": "MGMT", "inbound_route_map": "RM-MLAG-PEER-IN"},
]
},
"expected": {
"result": "failure",
"messages": [
"The following BGP peers are not configured or has an incorrect or missing route map in either the inbound or outbound direction:\n"
"{'10.100.0.8': {'default': {'routeMapInbound': 'RM-MLAG-PEER'}}}"
"{'10.100.0.8': {'default': {'Inbound route-map': 'RM-MLAG-PEER'}}, '10.100.0.10': {'MGMT': {'Inbound route-map': 'RM-MLAG-PEER'}}}"
],
},
},
{
"name": "failure-not-found",
"name": "failure-route-maps-not-configured",
"test": VerifyBgpRouteMaps,
"eos_data": [
{
"vrfs": {
"default": {
"peerList": [],
}
"peerList": [
{
"peerAddress": "10.100.0.8",
}
]
},
},
},
{
"vrfs": {
"MGMT": {
"peerList": [
{
"peerAddress": "10.100.0.10",
}
]
},
},
},
],
"inputs": {
"bgp_peers": [
{"peer_address": "10.100.0.8", "vrf": "default", "inbound_route_map": "RM-MLAG-PEER-IN", "outbound_route_map": "RM-MLAG-PEER-OUT"},
{"peer_address": "10.100.0.10", "vrf": "MGMT", "inbound_route_map": "RM-MLAG-PEER-IN", "outbound_route_map": "RM-MLAG-PEER-OUT"},
]
},
"expected": {
"result": "failure",
"messages": [
"The following BGP peers are not configured or has an incorrect or missing route map in either the inbound or outbound direction:\n"
"{'10.100.0.8': {'default': {'Inbound route-map': 'Not Configured', 'Outbound route-map': 'Not Configured'}}, "
"'10.100.0.10': {'MGMT': {'Inbound route-map': 'Not Configured', 'Outbound route-map': 'Not Configured'}}}"
],
},
},
{
"name": "failure-not-found",
"test": VerifyBgpRouteMaps,
"eos_data": [
{
"vrfs": {
"default": {"peerList": []},
},
},
{
"vrfs": {
"MGMT": {"peerList": []},
},
},
],
"inputs": {"bgp_peers": [{"peer_address": "10.100.0.8", "vrf": "default", "inbound_route_map": "RM-MLAG-PEER-IN"}]},
"inputs": {
"bgp_peers": [
{"peer_address": "10.100.0.8", "vrf": "default", "inbound_route_map": "RM-MLAG-PEER-IN"},
{"peer_address": "10.100.0.10", "vrf": "MGMT", "inbound_route_map": "RM-MLAG-PEER-IN"},
]
},
"expected": {
"result": "failure",
"messages": [
"The following BGP peers are not configured or has an incorrect or missing route map in either the inbound or outbound direction:\n"
"{'10.100.0.8': {'default': 'Not configured'}}"
"{'10.100.0.8': {'default': 'Not configured'}, '10.100.0.10': {'MGMT': 'Not configured'}}"
],
},
},
Expand Down

0 comments on commit ddbbfc5

Please sign in to comment.