Skip to content

Commit

Permalink
tests: update sbfd test cases for code review comments
Browse files Browse the repository at this point in the history
Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
  • Loading branch information
forrestchu committed Jan 20, 2025
1 parent 661aba7 commit 68a9774
Showing 1 changed file with 44 additions and 23 deletions.
67 changes: 44 additions & 23 deletions tests/topotests/sbfd_topo1/test_sbfd_topo1.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,26 @@ def show_bfd_check(router, status, type='echo', encap=None):
# check encap data if any
pattern1 = re.compile(r'encap-data {}'.format(encap))
ret = pattern1.findall(output)
assert len(ret) > 0, output
if len(ret) <= 0:
logger.info("encap-data not match")
return False

# check status
pattern2 = re.compile(r'Status: {}'.format(status))
ret = pattern2.findall(output)
assert len(ret) > 0, output
if len(ret) <= 0:
logger.info("Status not match")
return False

# check type
pattern3 = re.compile(r'Peer Type: {}'.format(type))
ret = pattern3.findall(output)
assert len(ret) > 0, output
if len(ret) <= 0:
logger.info("Peer Type not match")
return False

logger.info("all check passed")
return True

def build_topo(tgen):
"Test topology builder"
Expand Down Expand Up @@ -141,15 +150,16 @@ def test_sbfd_config_check():
# config sbfd
r1 = tgen.net['r1']
r1.cmd("ping -c 5 2001::20")
time.sleep(5)
r1.cmd("vtysh -c 'config t' -c 'bfd' -c 'peer 2001::20 bfd-mode sbfd-init bfd-name 2-44 local-address 2001::10 remote-discr 1234'")

r2 = tgen.net['r2']
r2.cmd("vtysh -c 'config t' -c 'bfd' -c 'sbfd reflector source-address 2001::20 discriminator 1234'")

logger.info('waiting 5 sec ... for sbfd up')
time.sleep(5)
show_bfd_check(r1, 'up', type='sbfd initiator')
check_func = partial(
show_bfd_check, r1, 'up', type='sbfd initiator'
)
success, _ = topotest.run_and_expect(check_func, True, count=15, wait=1)
assert success is True, "sbfd not up in 15 seconds"

# step 2: shutdown if and no shutdown if then check sbfd status
def test_sbfd_updown_interface():
Expand All @@ -163,14 +173,20 @@ def test_sbfd_updown_interface():

# shutdown interface
r2.cmd("vtysh -c 'config t' -c 'interface r2-eth0' -c 'shutdown'")
time.sleep(5)
show_bfd_check(r1, 'down', type='sbfd initiator')

check_func = partial(
show_bfd_check, r1, 'down', type='sbfd initiator'
)
success, _ = topotest.run_and_expect(check_func, True, count=15, wait=1)
assert success is True, "sbfd not down in 15 seconds after shut"

# up interface
r2.cmd("vtysh -c 'config t' -c 'interface r2-eth0' -c 'no shutdown'")
logger.info('waiting 5 sec ... for sbfd up after no shutdown')
time.sleep(5)
show_bfd_check(r1, 'up', type='sbfd initiator')
check_func = partial(
show_bfd_check, r1, 'up', type='sbfd initiator'
)
success, _ = topotest.run_and_expect(check_func, True, count=15, wait=1)
assert success is True, "sbfd not up in 15 seconds after no shut"

# step 3: change transmit-interval and check sbfd status according to the interval time
def test_sbfd_change_transmit_interval():
Expand All @@ -184,23 +200,28 @@ def test_sbfd_change_transmit_interval():

r1.cmd("vtysh -c 'config t' -c 'bfd' -c 'peer 2001::20 bfd-mode sbfd-init bfd-name 2-44 local-address 2001::10 remote-discr 1234' -c 'transmit-interval 3000'")
#wait sometime for polling finish
time.sleep(3)
time.sleep(1)

# shutdown interface
r2.cmd("vtysh -c 'config t' -c 'interface r2-eth0' -c 'shutdown'")
logger.info('waiting 5 sec ... for sbfd still up after shutdown')
time.sleep(5)
#sbfd is still up
show_bfd_check(r1, 'up', type='sbfd initiator')

#wait enough time for timeout
logger.info('waiting 10 sec ... for sbfd down after shutdown')
time.sleep(10)
show_bfd_check(r1, 'down', type='sbfd initiator')
check_func = partial(
show_bfd_check, r1, 'down', type='sbfd initiator'
)
success, _ = topotest.run_and_expect(check_func, True, count=5, wait=3)
assert success is True, "sbfd not down as expected"

r2.cmd("vtysh -c 'config t' -c 'interface r2-eth0' -c 'no shutdown'")
logger.info('waiting 5 sec ... for sbfd up after no shutdown')
time.sleep(5)
show_bfd_check(r1, 'up', type='sbfd initiator')
check_func = partial(
show_bfd_check, r1, 'up', type='sbfd initiator'
)
success, _ = topotest.run_and_expect(check_func, True, count=15, wait=1)
assert success is True, "sbfd not up in 15 seconds after no shut"

r1.cmd("vtysh -c 'config t' -c 'bfd' -c 'no peer 2001::20 bfd-mode sbfd-init bfd-name 2-44 local-address 2001::10 remote-discr 1234'")
success = show_bfd_check(r1, 'up', type='sbfd initiator')
assert success is False, "sbfd not deleted as unexpected"

# Memory leak test template
def test_memory_leak():
Expand Down

0 comments on commit 68a9774

Please sign in to comment.