-
Notifications
You must be signed in to change notification settings - Fork 34
feat(anta.tests): Adding the test case to verify BGP timers #510
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
Conversation
anta/tests/routing/bgp.py
Outdated
keep_alive_time = bgp_peer.keep_alive_time | ||
|
||
# Verify BGP peer | ||
if not (bgp_output := get_value(self.instance_commands[0].json_output, f"vrfs..{vrf}..peerList", separator="..")): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to use separator=".."
here?
anta/tests/routing/bgp.py
Outdated
|
||
# Verify BGP peer | ||
if not (bgp_output := get_value(self.instance_commands[0].json_output, f"vrfs..{vrf}..peerList", separator="..")): | ||
failures[str(peer_address)] = {vrf: "Not configured"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
peer_address
is already a str
no?
anta/tests/routing/bgp.py
Outdated
name = "VerifyBGPTimers" | ||
description = "Verifies if the BGP peers are configured with the correct hold and keep alive timers in the specified VRF." | ||
categories = ["routing", "bgp"] | ||
commands = [AntaCommand(command="show bgp neighbors")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
show bgp neighbors
will give you the neighbors of the default VRF only. You should use show bgp neighbors vrf all
or use AntaTemplate
and show bgp neighbors vrf {vrf}
.
anta/tests/routing/bgp.py
Outdated
failures[str(peer_address)] = {vrf: "Not configured"} | ||
continue | ||
|
||
bgp_index = create_index(bgp_output, "peerAddress") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check if the get_item function in AVD does what you want? If so, let's copy the code in anta.tools
so we can use it.
anta/tests/routing/bgp.py
Outdated
bgp_index = create_index(bgp_output, "peerAddress") | ||
bgp_output = bgp_index.get(peer_address) | ||
if not bgp_output: | ||
failures[str(peer_address)] = {vrf: "Not configured"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a second statement here if there peer is not configured?
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
c6767ef
to
d74580f
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after restricting int
inputs.
anta/tests/routing/bgp.py
Outdated
"""IPv4 address of a BGP peer""" | ||
vrf: str = "default" | ||
"""Optional VRF for BGP peer. If not provided, it defaults to `default`.""" | ||
hold_time: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hold_time: int | |
hold_time: int = Field(ge=3, le=7200) |
anta/tests/routing/bgp.py
Outdated
"""Optional VRF for BGP peer. If not provided, it defaults to `default`.""" | ||
hold_time: int | ||
"""BGP hold time in seconds""" | ||
keep_alive_time: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep_alive_time: int | |
keep_alive_time: int = Field(ge=0, le=3600) |
d74580f
to
40f4c6a
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
Description
Adding the test case to verify BGP timers
Fixes #509
Checklist:
pre-commit run
)tox -e testenv
)