diff --git a/tests/common/fixtures/ptfhost_utils.py b/tests/common/fixtures/ptfhost_utils.py index 4f8d1d4fb0e..fcc347bcd36 100644 --- a/tests/common/fixtures/ptfhost_utils.py +++ b/tests/common/fixtures/ptfhost_utils.py @@ -16,6 +16,8 @@ from tests.common.dualtor.dual_tor_utils import update_linkmgrd_probe_interval, recover_linkmgrd_probe_interval from tests.common.utilities import wait_until from tests.common.dualtor.dual_tor_utils import mux_cable_server_ip +from pytest_ansible.errors import AnsibleConnectionFailure + logger = logging.getLogger(__name__) @@ -35,6 +37,7 @@ GARP_SERVICE_CONF_TEMPL = 'garp_service.conf.j2' PTF_TEST_PORT_MAP = '/root/ptf_test_port_map.json' PROBER_INTERVAL_MS = 3000 +PTFHOST_EXCEPTION_RC = 16 @pytest.fixture(scope="session", autouse=True) @@ -299,11 +302,17 @@ def ptf_portmap_file_module(rand_selected_dut, ptfhost, tbinfo): yield _ptf_portmap_file(rand_selected_dut, ptfhost, tbinfo) +def pytest_sessionfinish(session, exitstatus): + if session.config.cache.get("ptfhost_exception", None): + session.config.cache.set("ptfhost_exception", None) + session.exitstatus = PTFHOST_EXCEPTION_RC + + icmp_responder_session_started = False @pytest.fixture(scope="session", autouse=True) -def run_icmp_responder_session(duthosts, duthost, ptfhost, tbinfo): +def run_icmp_responder_session(duthosts, duthost, ptfhost, tbinfo, request): """Run icmp_responder on ptfhost session-wise on dualtor testbeds with active-active ports.""" # No vlan is available on non-t0 testbed, so skip this fixture if "dualtor-mixed" not in tbinfo["topo"]["name"] and "dualtor-aa" not in tbinfo["topo"]["name"]: @@ -319,7 +328,12 @@ def run_icmp_responder_session(duthosts, duthost, ptfhost, tbinfo): duthost = duthosts[0] logger.debug("Copy icmp_responder.py to ptfhost '{0}'".format(ptfhost.hostname)) - ptfhost.copy(src=os.path.join(SCRIPTS_SRC_DIR, ICMP_RESPONDER_PY), dest=OPT_DIR) + try: + ptfhost.copy(src=os.path.join(SCRIPTS_SRC_DIR, ICMP_RESPONDER_PY), dest=OPT_DIR) + except AnsibleConnectionFailure as e: + logger.error("Failed to copy files to ptfhost.") + request.config.cache.set("ptfhost_exception", True) + pt_assert(False, "!!! ptfhost copy file failed !!! Exception: {}".format(repr(e))) logger.info("Start running icmp_responder") templ = Template(open(os.path.join(TEMPLATES_DIR, ICMP_RESPONDER_CONF_TEMPL)).read()) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 2b818952ff7..752fc910eaf 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -364,6 +364,12 @@ function run_individual_tests() return ${ret_code} fi + # rc 16 means ptfhost is unreachable + if [ ${ret_code} -eq 16 ]; then + echo "=== ptfhost has exception for $test_script. Skip rest of the scripts if there is any. ===" + return ${ret_code} + fi + EXIT_CODE=1 if [[ ${TEST_MAX_FAIL} != 0 ]]; then return ${EXIT_CODE}