@@ -166,6 +166,12 @@ def _check_bgp_on_dut(*args, **kwargs):
166166 dut = kwargs ['node' ]
167167 results = kwargs ['results' ]
168168
169+ def _check_default_route (version , asichost ):
170+ # Return True if successfully get default route
171+ res = asichost .shell ("ip {} route show default" .format ("" if version == 4 else "-6" ),
172+ module_ignore_errors = True )
173+ return not res ["rc" ] and len (res ["stdout" ].strip ()) != 0
174+
169175 def _check_bgp_status_helper ():
170176 asic_check_results = []
171177 bgp_facts = dut .bgp_facts (asic_index = 'all' )
@@ -187,23 +193,32 @@ def _check_bgp_status_helper():
187193 if a_asic_neighbors is not None and len (a_asic_neighbors ) > 0 :
188194 down_neighbors = [k for k , v in list (a_asic_neighbors .items ())
189195 if v ['state' ] != 'established' ]
196+ asic_key = 'bgp' if dut .facts ['num_asic' ] == 1 else 'bgp' + str (asic_index )
190197 if down_neighbors :
191- if dut .facts ['num_asic' ] == 1 :
192- check_result ['bgp' ] = {'down_neighbors' : down_neighbors }
193- else :
194- check_result ['bgp' + str (asic_index )] = {'down_neighbors' : down_neighbors }
198+ check_result [asic_key ] = {'down_neighbors' : down_neighbors }
195199 a_asic_result = True
196200 else :
197201 a_asic_result = False
198- if dut .facts ['num_asic' ] == 1 :
199- if 'bgp' in check_result :
200- check_result ['bgp' ].pop ('down_neighbors' , None )
201- else :
202- if 'bgp' + str (asic_index ) in check_result :
203- check_result ['bgp' + str (asic_index )].pop ('down_neighbors' , None )
202+ if asic_key in check_result :
203+ check_result [asic_key ].pop ('down_neighbors' , None )
204204 else :
205205 a_asic_result = True
206206
207+ # Add default route check for default route missing issue in below scenario:
208+ # 1) Loopbackv4 ip address replace, it would cause all bgp routes missing
209+ # 2) Announce or withdraw routes in some test cases and doesn't recover it
210+ asic_host = dut .asic_instance (asic_index )
211+ if not _check_default_route (4 , asic_host ):
212+ if asic_key not in check_result :
213+ check_result [asic_key ] = {}
214+ check_result [asic_key ]["no_v4_default_route" ] = True
215+ a_asic_result = True
216+ if not _check_default_route (6 , asic_host ):
217+ if asic_key not in check_result :
218+ check_result [asic_key ] = {}
219+ check_result [asic_key ]["no_v6_default_route" ] = True
220+ a_asic_result = True
221+
207222 asic_check_results .append (a_asic_result )
208223
209224 if any (asic_check_results ):
@@ -243,8 +258,12 @@ def _check_bgp_status_helper():
243258 if 'down_neighbors' in check_result [a_result ]:
244259 logger .info ('BGP neighbors down: %s on bgp instance %s on dut %s' % (
245260 check_result [a_result ]['down_neighbors' ], a_result , dut .hostname ))
261+ if "no_v4_default_route" in check_result [a_result ]:
262+ logger .info ('Deafult v4 route for {} {} is missing' .format (dut .hostname , a_result ))
263+ if "no_v6_default_route" in check_result [a_result ]:
264+ logger .info ('Deafult v6 route for {} {} is missing' .format (dut .hostname , a_result ))
246265 else :
247- logger .info ('No BGP neighbors are down on %s' % dut .hostname )
266+ logger .info ('No BGP neighbors are down or default route missing on %s' % dut .hostname )
248267
249268 mgFacts = dut .get_extended_minigraph_facts (tbinfo )
250269 if dut .num_asics () == 1 and tbinfo ['topo' ]['type' ] != 't2' and \
0 commit comments