Skip to content

Commit

Permalink
issue_781 Handling review comments: updated strict check
Browse files Browse the repository at this point in the history
  • Loading branch information
VitthalMagadum committed Aug 16, 2024
1 parent 0f74a59 commit da4447e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions anta/tests/routing/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _add_bgp_routes_failure(
return failure_routes


def _check_peer_cpabilities(bgp_output: dict[str, Any], capabilities: list[MultiProtocolCaps], *, strict: bool = False) -> dict[str, Any]:
def _check_peer_capabilities(bgp_output: dict[str, Any], capabilities: list[MultiProtocolCaps], *, strict: bool = False) -> dict[str, Any]:
"""Check for issues in BGP output for multiprotocol capabilities.
- Checks the only mentioned capabilities should be listed when strict is True.
Expand All @@ -170,7 +170,12 @@ def _check_peer_cpabilities(bgp_output: dict[str, Any], capabilities: list[Multi
# Verifies the only mentioned capabilities should be listed when strict is True.
if strict and not set(bgp_output).issubset(set(capabilities)):
other_capabilities = ", ".join(list(set(bgp_output) - set(capabilities)))
failure["status"] = f"Other than mentioned capabilities following capability(s) are listed: {other_capabilities}"
failure["strict"] = f"Other than mentioned BGP peer multiprotocol capabilities following capability(s) are listed: {other_capabilities}"

# Verifying the mentioned capabilities.
failure_msg = _check_peer_capabilities(bgp_output, capabilities, strict=False)
if failure_msg:
failure.update(failure_msg)
return failure

# Check each capability
Expand Down Expand Up @@ -799,7 +804,7 @@ def test(self) -> None:
bgp_output = get_value(bgp_output, "neighborCapabilities.multiprotocolCaps")

# Collecting the failure logs if any.
failure_log = _check_peer_cpabilities(bgp_output, capabilities, strict=bgp_peer.strict)
failure_log = _check_peer_capabilities(bgp_output, capabilities, strict=bgp_peer.strict)
if failure_log:
failure["bgp_peers"][peer][vrf] = failure_log
failures = deep_update(failures, failure)
Expand Down
9 changes: 6 additions & 3 deletions tests/units/anta_tests/routing/test_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2306,7 +2306,7 @@
"enabled": True,
},
"ipv4MplsVpn": {
"advertised": True,
"advertised": False,
"received": True,
"enabled": True,
},
Expand Down Expand Up @@ -2338,8 +2338,11 @@
"result": "failure",
"messages": [
"Following BGP peer multiprotocol capabilities are not found or not ok:\n"
"{'bgp_peers': {'172.30.11.1': {'default': {'status': 'Other than mentioned capabilities following capability(s) are listed: ipv4MplsLabels'}}, "
"'172.30.11.10': {'MGMT': {'status': 'Other than mentioned capabilities following capability(s) are listed: ipv4Unicast'}}}}"
"{'bgp_peers': {'172.30.11.1': {'default': {'strict': "
"'Other than mentioned BGP peer multiprotocol capabilities following capability(s) are listed: ipv4MplsLabels'}}, "
"'172.30.11.10': {'MGMT': {'strict': "
"'Other than mentioned BGP peer multiprotocol capabilities following capability(s) are listed: ipv4Unicast', "
"'ipv4MplsVpn': {'advertised': False, 'received': True, 'enabled': True}}}}}"
],
},
},
Expand Down

0 comments on commit da4447e

Please sign in to comment.