Skip to content
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
13 changes: 13 additions & 0 deletions tests/common/configlet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,19 @@ def db_comp(duthost, test_db_dir, ref_db_dir, ctx):
return True


def is_bgp_session_established(duthost, ip):
"""Check if BGP session is established. Returns True/False for use with wait_until."""
if sys.version_info[0] > 2:
info = duthost.get_bgp_neighbor_info(ip)
else:
info = duthost.get_bgp_neighbor_info(ip.decode('utf-8'))
bgp_state = info.get("bgpState", "")
if bgp_state != "Established":
log_info("BGP session for {} is '{}', waiting for 'Established'".format(ip, bgp_state))
return False
return True


def chk_bgp_session(duthost, ip, msg):
if sys.version_info[0] > 2:
info = duthost.get_bgp_neighbor_info(ip)
Expand Down
16 changes: 11 additions & 5 deletions tests/configlet/util/generic_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from tests.common.configlet.utils import orig_db_dir, no_t0_db_dir, patch_add_t0_dir, patch_rm_t0_dir, tor_data,\
RELOAD_WAIT_TIME, PAUSE_INTF_DOWN, PAUSE_INTF_UP, PAUSE_CLET_APPLY, DB_COMP_WAIT_TIME,\
do_pause, db_comp, chk_bgp_session
do_pause, db_comp, is_bgp_session_established

if os.path.exists("/etc/sonic/sonic-environment"):
from mock_for_switch import config_reload, wait_until
Expand Down Expand Up @@ -166,14 +166,20 @@ def generic_patch_add_t0(duthost, skip_load=False, hack_apply=False):
duthost.shell("config interface startup {}".format(tor_ifname))
do_pause(PAUSE_INTF_UP, "pause upon i/f {} startup after add patch".format(tor_ifname))

# Wait for BGP sessions to establish BEFORE DB comparison.
# After adding T0 config, BGP needs to converge and populate app-db route entries.
# Comparing DBs before BGP convergence causes spurious mismatches in app-db.
assert wait_until(DB_COMP_WAIT_TIME, 20, 0, is_bgp_session_established,
duthost, tor_data["ip"]["remote"]), \
"BGP IPv4 session for {} not established before DB comparison".format(tor_data["ip"]["remote"])
assert wait_until(DB_COMP_WAIT_TIME, 20, 0, is_bgp_session_established,
duthost, tor_data["ipv6"]["remote"].lower()), \
"BGP IPv6 session for {} not established before DB comparison".format(tor_data["ipv6"]["remote"].lower())

assert wait_until(DB_COMP_WAIT_TIME, 20, 0, db_comp, duthost, patch_add_t0_dir,
orig_db_dir, "generic_patch_add_t0"), \
"DB compare failed after adding T0 via generic patch updater"

# Ensure BGP session is up
chk_bgp_session(duthost, tor_data["ip"]["remote"], "post-patch-add test")
chk_bgp_session(duthost, tor_data["ipv6"]["remote"].lower(), "post-patch-add test")


def generic_patch_rm_t0(duthost, skip_load=False, hack_apply=False):
# Load config with T0
Expand Down
Loading