Fix handling of optional fields in get_bgp_peer function#3565
Closed
matofeder wants to merge 2 commits intosonic-net:masterfrom
Closed
Fix handling of optional fields in get_bgp_peer function#3565matofeder wants to merge 2 commits intosonic-net:masterfrom
matofeder wants to merge 2 commits intosonic-net:masterfrom
Conversation
This commit fixes an issue in get_bgp_peer function where `local_addr` and `name` were treated as mandatory. However, `local_addr` and `name` fields are not required in BGP neighbor configuration. Fixes #19930 Signed-off-by: Matej Feder <[email protected]>
This was referenced Oct 3, 2024
This was referenced Oct 4, 2024
bradh352
suggested changes
Dec 22, 2024
Contributor
bradh352
left a comment
There was a problem hiding this comment.
I too hit this issue when using BGP Unnumbered. I'm not sure why no one else commented on this issue.
| for neighbor_ip in data.keys(): | ||
| local_addr = data[neighbor_ip]['local_addr'] | ||
| neighbor_name = data[neighbor_ip]['name'] | ||
| local_addr = data[neighbor_ip].get('local_addr', "") |
Contributor
There was a problem hiding this comment.
might be better to just put the whole block inside the for loop inside:
try:
...
except KeyError:
passYour current solution adds a blank entry to bgp_peer which doesn't do anything for us...
Should probably also put a comment that this get_bgp_peer is for retrieving manually specified BGP peers only, not BGP Unnumbered peers (like when specifying an interface)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
This commit fixes an issue in get_bgp_peer function where
local_addrandnamewere treated as mandatory. However,local_addrandnamefields are not required in BGP neighbor configuration.How I did it
The local_addr and name fields are no longer mandatory in the get_bgp_peer function.
How to verify it
Apply BGP neighbor configuration like below (utilizing BGP_PEER_GROUP), where fields such as local_addr or name are omitted:
{ "BGP_GLOBALS": { "default": { "local_asn": "65001", "log_nbr_state_changes": "true", "router_id": "10.0.0.1" } }, "BGP_PEER_GROUP": { "default|core": { "peer_group_name": "core", "admin_status": "true", "asn": "65002", "peer_type": "external" } }, "BGP_NEIGHBOR": { "default|Ethernet4": { "peer_group_name": "core" } }, "BGP_NEIGHBOR_AF": { "default|core|ipv4_unicast": { "admin_status": "true", "route_map_in": [ "ALLOW" ], "route_map_out": [ "ALLOW" ] } }, "ROUTE_MAP": { "ALLOW|1": { "route_operation": "permit" } } }Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)
Fixes #19930