Skip to content

Fix flakiness with poll mode tests when client has not connected yet or default route has not populated yet #19316

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions tests/telemetry/telemetry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def skip_201911_and_older(duthost):
pytest.skip("Test not supported for 201911 images. Skipping the test")


def check_gnmi_cli_running(ptfhost):
program_list = ptfhost.shell("pgrep -f 'python /root/gnxi/gnmi_cli_py/py_gnmicli.py'")["stdout"]
return len(program_list) > 0
def check_gnmi_cli_running(duthost, ptfhost):
env = GNMIEnvironment(duthost, GNMIEnvironment.TELEMETRY_MODE)
res = ptfhost.shell(f"netstat -tn | grep \":{env.gnmi_port} .*ESTABLISHED\"")
return res and res["rc"] == 0


def parse_gnmi_output(gnmi_output, match_no, find_data):
Expand Down
2 changes: 1 addition & 1 deletion tests/telemetry/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def callback(result):
client_thread = threading.Thread(target=invoke_py_cli_from_ptf, args=(ptfhost, cmd, callback,))
client_thread.start()

wait_until(5, 1, 0, check_gnmi_cli_running, ptfhost)
wait_until(5, 1, 0, check_gnmi_cli_running, duthost, ptfhost)
cmd = "sonic-db-cli STATE_DB HSET \"NEIGH_STATE_TABLE|{}\" \"state\" {}".format(bgp_neighbor,
new_state)
cmd = duthost.get_cli_cmd_for_namespace(cmd, ns)
Expand Down
13 changes: 7 additions & 6 deletions tests/telemetry/test_telemetry_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def callback(show_gnmi_out):
client_thread = InterruptableThread(target=invoke_py_cli_from_ptf, args=(ptfhost, cmd, callback,))
client_thread.start()

wait_until(5, 1, 0, check_gnmi_cli_running, ptfhost)
wait_until(5, 1, 0, check_gnmi_cli_running, duthost, ptfhost)

modify_fake_appdb_table(duthost, True, 2) # Add second table data
client_thread.join(30)
Expand Down Expand Up @@ -148,7 +148,7 @@ def callback(show_gnmi_out):
client_thread = InterruptableThread(target=invoke_py_cli_from_ptf, args=(ptfhost, cmd, callback,))
client_thread.start()

wait_until(5, 1, 0, check_gnmi_cli_running, ptfhost)
wait_until(5, 1, 0, check_gnmi_cli_running, duthost, ptfhost)

modify_fake_appdb_table(duthost, False, 2) # Remove all added tables
client_thread.join(30)
Expand Down Expand Up @@ -189,9 +189,9 @@ def test_poll_mode_default_route(duthosts, enum_rand_one_per_hwsku_hostname, ptf
pytest_assert(len(update_responses_match) == 5, "Missing update responses")

cmd = generate_client_cli(duthost=duthost, gnxi_path=gnxi_path, method=METHOD_SUBSCRIBE,
subscribe_mode=SUBSCRIBE_MODE_POLL, polling_interval=2,
subscribe_mode=SUBSCRIBE_MODE_POLL, polling_interval=10,
xpath="\"FAKE_APPL_DB_TABLE_0\" \"ROUTE_TABLE/0.0.0.0\/0\"", # noqa: W605
target="APPL_DB", max_sync_count=-1, update_count=10, timeout=60, namespace=namespace)
target="APPL_DB", max_sync_count=-1, update_count=10, timeout=120, namespace=namespace)

def callback(show_gnmi_out):
result = str(show_gnmi_out)
Expand All @@ -202,14 +202,15 @@ def callback(show_gnmi_out):
client_thread = InterruptableThread(target=invoke_py_cli_from_ptf, args=(ptfhost, cmd, callback,))
client_thread.start()

wait_until(5, 1, 0, check_gnmi_cli_running, ptfhost)
wait_until(5, 1, 0, check_gnmi_cli_running, duthost, ptfhost)

# Add back default route
duthost.shell("config bgp startup all")
pytest_assert(wait_until(60, 5, 0, verify_route_table_status, duthost, namespace, "1"),
"ROUTE_TABLE default route missing")

client_thread.join(60)
# Give 60 seconds for client to connect to server and then 60 for default route to populate after bgp session start
client_thread.join(120)
Copy link
Contributor

Choose a reason for hiding this comment

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

after this statement, will you check if it timeout at 120 second or successfully join earlier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we still do

"target="APPL_DB", max_sync_count=-1, update_count=10, timeout=120, namespace=namespace)"

This lets the query run up to a maximum of 120 seconds, but if we get 10 update count successfully before then, the ptf call will return early and we will join the thread earlier. This is a max allotted time for 120, ideally we will always join earlier than that.


modify_fake_appdb_table(duthost, False, 1) # Remove all added tables

Expand Down
Loading