-
Notifications
You must be signed in to change notification settings - Fork 764
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
Add test case for gnmi subscription of bmp table #17056
Draft
FengPan-Frank
wants to merge
1
commit into
sonic-net:master
Choose a base branch
from
FengPan-Frank:gnmi_bmp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
import re | ||
import json | ||
from bmp.helper import enable_bmp_neighbor_table, enable_bmp_rib_in_table, enable_bmp_rib_out_table | ||
from netaddr import valid_ipv4 | ||
from tests.common.helpers.gnmi_utils import GNMIEnvironment | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -13,6 +15,19 @@ | |
] | ||
|
||
|
||
def get_mgmt_ip(duthost): | ||
config_facts = duthost.get_running_config_facts() | ||
mgmt_interfaces = config_facts.get("MGMT_INTERFACE", {}) | ||
mgmt_ip = None | ||
|
||
for mgmt_interface, ip_configs in mgmt_interfaces.items(): | ||
for ip_addr_with_prefix in ip_configs.keys(): | ||
ip_addr = ip_addr_with_prefix.split("/")[0] | ||
if valid_ipv4(ip_addr): | ||
mgmt_ip = ip_addr | ||
return mgmt_ip | ||
|
||
|
||
def check_dut_bmp_neighbor_status(duthost, neighbor_addr, expected_state, max_attempts=12, retry_interval=3): | ||
for i in range(max_attempts + 1): | ||
bmp_info = duthost.shell("sonic-db-cli BMP_STATE_DB HGETALL 'BGP_NEIGHBOR_TABLE|{}'" | ||
|
@@ -126,3 +141,25 @@ def test_bmp_population(duthosts, rand_one_dut_hostname, localhost): | |
enable_bmp_rib_out_table(duthost) | ||
for idx, neighbor_v6addr in enumerate(neighbor_v6addrs): | ||
check_dut_bmp_rib_out_status(duthost, neighbor_v6addr) | ||
|
||
|
||
def test_bmp_gnmi_subscription(duthosts, rand_one_dut_hostname, localhost): | ||
duthost = duthosts[rand_one_dut_hostname] | ||
|
||
# neighbor table - ipv4 neighbor | ||
# only pick-up sent_cap attributes for typical check first. | ||
enable_bmp_neighbor_table(duthost) | ||
neighbor_addrs = get_neighbors(duthost) | ||
for idx, neighbor_addr in enumerate(neighbor_addrs): | ||
check_dut_bmp_neighbor_status(duthost, neighbor_addr, "sent_cap") | ||
env = GNMIEnvironment(duthost, GNMIEnvironment.TELEMETRY_MODE) | ||
|
||
# neighbor table subscription | ||
dut_ip = get_mgmt_ip(duthost) | ||
cmd = "~/gnmi_get -xpath_target BMP_STATE_DB -xpath BGP_NEIGHBOR_TABLE -target_addr \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
[%s]:%s -logtostderr -insecure" % (dut_ip, env.gnmi_port) | ||
|
||
gnmi_out = duthost.shell(cmd)['stdout'] | ||
result = str(gnmi_out) | ||
inerrors_match = re.search("BGP_NEIGHBOR_TABLE", result) | ||
assert inerrors_match is not None, "BGP_NEIGHBOR_TABLE not found in gnmi output" |
Oops, something went wrong.
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.
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.
There are some special DUTs:
Suggest loop all the access if available: