Skip to content

Commit 211097f

Browse files
committed
[sanity_check][bgp] Enhance sanity check recover for bgp default route missing
1 parent 169c7be commit 211097f

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

tests/common/plugins/sanity_check/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def prepare_parallel_run(request, parallel_run_context):
181181

182182

183183
@pytest.fixture(scope="module")
184-
def sanity_check_full(prepare_parallel_run, localhost, duthosts, request, fanouthosts, nbrhosts, tbinfo):
184+
def sanity_check_full(ptfhost, prepare_parallel_run, localhost, duthosts, request, fanouthosts, nbrhosts, tbinfo):
185185
logger.info("Prepare sanity check")
186186
should_skip_sanity = prepare_parallel_run
187187
if should_skip_sanity:
@@ -299,7 +299,7 @@ def sanity_check_full(prepare_parallel_run, localhost, duthosts, request, fanout
299299
pt_assert(False, "!!!!!!!!!!!!!!!!Pre-test sanity check failed: !!!!!!!!!!!!!!!!\n{}"
300300
.format(json.dumps(failed_results, indent=4, default=fallback_serializer)))
301301
else:
302-
recover_on_sanity_check_failure(duthosts, failed_results, fanouthosts, localhost, nbrhosts,
302+
recover_on_sanity_check_failure(ptfhost, duthosts, failed_results, fanouthosts, localhost, nbrhosts,
303303
pre_check_items, recover_method, request, tbinfo, STAGE_PRE_TEST)
304304

305305
logger.info("Done pre-test sanity check")
@@ -325,15 +325,16 @@ def sanity_check_full(prepare_parallel_run, localhost, duthosts, request, fanout
325325
pt_assert(False, "!!!!!!!!!!!!!!!! Post-test sanity check failed: !!!!!!!!!!!!!!!!\n{}"
326326
.format(json.dumps(post_failed_results, indent=4, default=fallback_serializer)))
327327
else:
328-
recover_on_sanity_check_failure(duthosts, post_failed_results, fanouthosts, localhost, nbrhosts,
329-
post_check_items, recover_method, request, tbinfo, STAGE_POST_TEST)
328+
recover_on_sanity_check_failure(ptfhost, duthosts, post_failed_results, fanouthosts, localhost,
329+
nbrhosts, post_check_items, recover_method, request, tbinfo,
330+
STAGE_POST_TEST)
330331

331332
logger.info("Done post-test sanity check")
332333
else:
333334
logger.info('No post-test sanity check item, skip post-test sanity check.')
334335

335336

336-
def recover_on_sanity_check_failure(duthosts, failed_results, fanouthosts, localhost, nbrhosts, check_items,
337+
def recover_on_sanity_check_failure(ptfhost, duthosts, failed_results, fanouthosts, localhost, nbrhosts, check_items,
337338
recover_method, request, tbinfo, sanity_check_stage: str):
338339
cache_key = "pre_sanity_check_failed"
339340
recovery_cache_key = "pre_sanity_recovered"
@@ -363,7 +364,7 @@ def recover_on_sanity_check_failure(duthosts, failed_results, fanouthosts, local
363364
else:
364365
for dut_name, dut_results in list(dut_failed_results.items()):
365366
# Attempt to restore DUT state
366-
recover(duthosts[dut_name], localhost, fanouthosts, nbrhosts, tbinfo, dut_results,
367+
recover(ptfhost, duthosts[dut_name], localhost, fanouthosts, nbrhosts, tbinfo, dut_results,
367368
recover_method)
368369

369370
except BaseException as e:

tests/common/plugins/sanity_check/recover.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
import time
34

45
from tests.common import config_reload
56
from tests.common.devices.sonic import SonicHost
@@ -147,13 +148,21 @@ def _recover_with_command(dut, cmd, wait_time):
147148
wait(wait_time, msg="Wait {} seconds for system to be stable.".format(wait_time))
148149

149150

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/")
151+
def re_announce_routes(ptfhost, localhost, topo_name, ptf_ip):
152+
ptfhost.shell("supervisorctl restart exabgpv4:*", module_ignore_errors=True)
153+
ptfhost.shell("supervisorctl restart exabgpv6:*", module_ignore_errors=True)
154+
# Wait exabgp to be ready
155+
time.sleep(60)
156+
try:
157+
localhost.announce_routes(topo_name=topo_name, ptf_ip=ptf_ip, action="withdraw", path="../ansible/")
158+
time.sleep(2)
159+
localhost.announce_routes(topo_name=topo_name, ptf_ip=ptf_ip, action="announce", path="../ansible/")
160+
except Exception as e:
161+
logger.error("Failed to re-announce routes with: {}".format(e))
153162
return None
154163

155164

156-
def adaptive_recover(dut, localhost, fanouthosts, nbrhosts, tbinfo, check_results, wait_time):
165+
def adaptive_recover(ptfhost, dut, localhost, fanouthosts, nbrhosts, tbinfo, check_results, wait_time):
157166
outstanding_action = None
158167
for result in check_results:
159168
if result['failed']:
@@ -169,7 +178,7 @@ def adaptive_recover(dut, localhost, fanouthosts, nbrhosts, tbinfo, check_result
169178
"no_v6_default_route" in result['bgp'] and len(result['bgp']) == 1 or
170179
("no_v4_default_route" in result['bgp'] and "no_v6_default_route" in result['bgp'] and
171180
len(result['bgp']) == 2))):
172-
action = re_announce_routes(localhost, tbinfo["topo"]["name"], tbinfo["ptf_ip"])
181+
action = re_announce_routes(ptfhost, localhost, tbinfo["topo"]["name"], tbinfo["ptf_ip"])
173182
else:
174183
action = neighbor_vm_restore(dut, nbrhosts, tbinfo, result)
175184
elif result['check_item'] == "neighbor_macsec_empty":
@@ -199,13 +208,13 @@ def adaptive_recover(dut, localhost, fanouthosts, nbrhosts, tbinfo, check_result
199208
_recover_with_command(dut, method['cmd'], wait_time)
200209

201210

202-
def recover(dut, localhost, fanouthosts, nbrhosts, tbinfo, check_results, recover_method):
211+
def recover(ptfhost, dut, localhost, fanouthosts, nbrhosts, tbinfo, check_results, recover_method):
203212
logger.warning("Try to recover %s using method %s" % (dut.hostname, recover_method))
204213

205214
method = constants.RECOVER_METHODS[recover_method]
206215
wait_time = method['recover_wait']
207216
if method["adaptive"]:
208-
adaptive_recover(dut, localhost, fanouthosts, nbrhosts, tbinfo, check_results, wait_time)
217+
adaptive_recover(ptfhost, dut, localhost, fanouthosts, nbrhosts, tbinfo, check_results, wait_time)
209218
elif method["reload"]:
210219
config_reload(dut, config_source='running_golden_config',
211220
safe_reload=True, check_intf_up_ports=True, wait_for_bgp=True)

0 commit comments

Comments
 (0)