Skip to content
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
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/bmp/test_bmp_statedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid_ipv4

There are some special DUTs:

  1. M0 do not have mgmt port at all, expecting to query loop IP address
  2. Some device only has ipv6 mgmt address

Suggest loop all the access if available:

  1. mgmt port ipv4
  2. mgmt port ipv6
  3. loopback ipv4
  4. loopback ipv6

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|{}'"
Expand Down Expand Up @@ -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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gnmi_get

this is get, not subscribe. right?

[%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"
Loading