Skip to content

Commit f80b6f5

Browse files
committed
tests: update sbfd test cases for code review comments
Signed-off-by: wumu.zsl <[email protected]>
1 parent 5ef3c7b commit f80b6f5

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

tests/topotests/sbfd_topo1/test_sbfd_topo1.py

+44-23
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,26 @@ def show_bfd_check(router, status, type='echo', encap=None):
6363
# check encap data if any
6464
pattern1 = re.compile(r'encap-data {}'.format(encap))
6565
ret = pattern1.findall(output)
66-
assert len(ret) > 0, output
66+
if len(ret) <= 0:
67+
logger.info("encap-data not match")
68+
return False
6769

6870
# check status
6971
pattern2 = re.compile(r'Status: {}'.format(status))
7072
ret = pattern2.findall(output)
71-
assert len(ret) > 0, output
73+
if len(ret) <= 0:
74+
logger.info("Status not match")
75+
return False
7276

7377
# check type
7478
pattern3 = re.compile(r'Peer Type: {}'.format(type))
7579
ret = pattern3.findall(output)
76-
assert len(ret) > 0, output
80+
if len(ret) <= 0:
81+
logger.info("Peer Type not match")
82+
return False
83+
84+
logger.info("all check passed")
85+
return True
7786

7887
def build_topo(tgen):
7988
"Test topology builder"
@@ -141,15 +150,16 @@ def test_sbfd_config_check():
141150
# config sbfd
142151
r1 = tgen.net['r1']
143152
r1.cmd("ping -c 5 2001::20")
144-
time.sleep(5)
145153
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'")
146154

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

150-
logger.info('waiting 5 sec ... for sbfd up')
151-
time.sleep(5)
152-
show_bfd_check(r1, 'up', type='sbfd initiator')
158+
check_func = partial(
159+
show_bfd_check, r1, 'up', type='sbfd initiator'
160+
)
161+
success, _ = topotest.run_and_expect(check_func, True, count=15, wait=1)
162+
assert success is True, "sbfd not up in 15 seconds"
153163

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

164174
# shutdown interface
165175
r2.cmd("vtysh -c 'config t' -c 'interface r2-eth0' -c 'shutdown'")
166-
time.sleep(5)
167-
show_bfd_check(r1, 'down', type='sbfd initiator')
176+
177+
check_func = partial(
178+
show_bfd_check, r1, 'down', type='sbfd initiator'
179+
)
180+
success, _ = topotest.run_and_expect(check_func, True, count=15, wait=1)
181+
assert success is True, "sbfd not down in 15 seconds after shut"
168182

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

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

185201
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'")
186202
#wait sometime for polling finish
187-
time.sleep(3)
203+
time.sleep(1)
188204

189205
# shutdown interface
190206
r2.cmd("vtysh -c 'config t' -c 'interface r2-eth0' -c 'shutdown'")
191-
logger.info('waiting 5 sec ... for sbfd still up after shutdown')
192-
time.sleep(5)
193-
#sbfd is still up
194-
show_bfd_check(r1, 'up', type='sbfd initiator')
207+
195208
#wait enough time for timeout
196-
logger.info('waiting 10 sec ... for sbfd down after shutdown')
197-
time.sleep(10)
198-
show_bfd_check(r1, 'down', type='sbfd initiator')
209+
check_func = partial(
210+
show_bfd_check, r1, 'down', type='sbfd initiator'
211+
)
212+
success, _ = topotest.run_and_expect(check_func, True, count=5, wait=3)
213+
assert success is True, "sbfd not down as expected"
199214

200215
r2.cmd("vtysh -c 'config t' -c 'interface r2-eth0' -c 'no shutdown'")
201-
logger.info('waiting 5 sec ... for sbfd up after no shutdown')
202-
time.sleep(5)
203-
show_bfd_check(r1, 'up', type='sbfd initiator')
216+
check_func = partial(
217+
show_bfd_check, r1, 'up', type='sbfd initiator'
218+
)
219+
success, _ = topotest.run_and_expect(check_func, True, count=15, wait=1)
220+
assert success is True, "sbfd not up in 15 seconds after no shut"
221+
222+
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'")
223+
success = show_bfd_check(r1, 'up', type='sbfd initiator')
224+
assert success is False, "sbfd not deleted as unexpected"
204225

205226
# Memory leak test template
206227
def test_memory_leak():

0 commit comments

Comments
 (0)