@@ -63,17 +63,26 @@ def show_bfd_check(router, status, type='echo', encap=None):
63
63
# check encap data if any
64
64
pattern1 = re .compile (r'encap-data {}' .format (encap ))
65
65
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
67
69
68
70
# check status
69
71
pattern2 = re .compile (r'Status: {}' .format (status ))
70
72
ret = pattern2 .findall (output )
71
- assert len (ret ) > 0 , output
73
+ if len (ret ) <= 0 :
74
+ logger .info ("Status not match" )
75
+ return False
72
76
73
77
# check type
74
78
pattern3 = re .compile (r'Peer Type: {}' .format (type ))
75
79
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
77
86
78
87
def build_topo (tgen ):
79
88
"Test topology builder"
@@ -141,15 +150,16 @@ def test_sbfd_config_check():
141
150
# config sbfd
142
151
r1 = tgen .net ['r1' ]
143
152
r1 .cmd ("ping -c 5 2001::20" )
144
- time .sleep (5 )
145
153
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'" )
146
154
147
155
r2 = tgen .net ['r2' ]
148
156
r2 .cmd ("vtysh -c 'config t' -c 'bfd' -c 'sbfd reflector source-address 2001::20 discriminator 1234'" )
149
157
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"
153
163
154
164
# step 2: shutdown if and no shutdown if then check sbfd status
155
165
def test_sbfd_updown_interface ():
@@ -163,14 +173,20 @@ def test_sbfd_updown_interface():
163
173
164
174
# shutdown interface
165
175
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"
168
182
169
183
# up interface
170
184
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"
174
190
175
191
# step 3: change transmit-interval and check sbfd status according to the interval time
176
192
def test_sbfd_change_transmit_interval ():
@@ -184,23 +200,28 @@ def test_sbfd_change_transmit_interval():
184
200
185
201
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'" )
186
202
#wait sometime for polling finish
187
- time .sleep (3 )
203
+ time .sleep (1 )
188
204
189
205
# shutdown interface
190
206
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
+
195
208
#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"
199
214
200
215
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"
204
225
205
226
# Memory leak test template
206
227
def test_memory_leak ():
0 commit comments