diff --git a/anta/tests/routing/bgp.py b/anta/tests/routing/bgp.py index 9a0813ab0..79e9d7107 100644 --- a/anta/tests/routing/bgp.py +++ b/anta/tests/routing/bgp.py @@ -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 @@ -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)] @@ -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 diff --git a/tests/units/anta_tests/routing/test_bgp.py b/tests/units/anta_tests/routing/test_bgp.py index 97bcfe071..30dff20dd 100644 --- a/tests/units/anta_tests/routing/test_bgp.py +++ b/tests/units/anta_tests/routing/test_bgp.py @@ -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": [ { @@ -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": [ { @@ -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'}}" ], }, },