Skip to content

Commit 6a166f8

Browse files
committed
[sanity_check][bgp] Add default route check in sanity
1 parent ea2c292 commit 6a166f8

2 files changed

Lines changed: 46 additions & 12 deletions

File tree

tests/common/plugins/sanity_check/checks.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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 \

tests/common/plugins/sanity_check/recover.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ def _recover_with_command(dut, cmd, wait_time):
147147
wait(wait_time, msg="Wait {} seconds for system to be stable.".format(wait_time))
148148

149149

150+
def re_announce_routes(localhost, topo_name, ptf_ip):
151+
localhost.announce_routes(topo_name=topo_name, ptf_ip=ptf_ip, action="withdraw", path="../ansible/")
152+
localhost.announce_routes(topo_name=topo_name, ptf_ip=ptf_ip, action="announce", path="../ansible/")
153+
return None
154+
155+
150156
def adaptive_recover(dut, localhost, fanouthosts, nbrhosts, tbinfo, check_results, wait_time):
151157
outstanding_action = None
152158
for result in check_results:
@@ -155,7 +161,16 @@ def adaptive_recover(dut, localhost, fanouthosts, nbrhosts, tbinfo, check_result
155161
action = _recover_interfaces(dut, fanouthosts, result, wait_time)
156162
elif result['check_item'] == 'services':
157163
action = _recover_services(dut, result)
158-
elif result['check_item'] == 'bgp' or result['check_item'] == "neighbor_macsec_empty":
164+
elif result['check_item'] == 'bgp':
165+
# If there is only default route missing issue, only need to re-announce routes to recover
166+
if ("no_v4_default_route" in result['bgp'] and len(result['bgp']) == 1 or
167+
"no_v6_default_route" in result['bgp'] and len(result['bgp']) == 1 or
168+
("no_v4_default_route" in result['bgp'] and "no_v6_default_route" in result['bgp'] and
169+
len(result['bgp']) == 2)):
170+
action = re_announce_routes(localhost, tbinfo["topo"]["name"], tbinfo["ptf_ip"])
171+
else:
172+
action = neighbor_vm_restore(dut, nbrhosts, tbinfo, result)
173+
elif result['check_item'] == "neighbor_macsec_empty":
159174
action = neighbor_vm_restore(dut, nbrhosts, tbinfo, result)
160175
elif result['check_item'] in ['processes', 'mux_simulator']:
161176
action = 'config_reload'

0 commit comments

Comments
 (0)