Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions tests/common/fixtures/ptfhost_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
GARP_SERVICE_CONF_TEMPL = 'garp_service.conf.j2'
PTF_TEST_PORT_MAP = '/root/ptf_test_port_map.json'
PROBER_INTERVAL_MS = 3000
PTFHOST_UNREACHABLE_RC = 16


@pytest.fixture(scope="session", autouse=True)
Expand Down Expand Up @@ -299,11 +300,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_unreachable", None):
session.config.cache.set("ptfhost_unreachable", None)
session.exitstatus = PTFHOST_UNREACHABLE_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"]:
Expand All @@ -319,7 +326,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 BaseException as e:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only exception AnsibleConnectionFailure means that the PTF is unreachable. It is better to capture this AnsibleConnectionFailure exception here and set "ptfhost_exception" to True. For other exceptions, they could be different issues and should not be treated as ptf unreachable.

logger.error("Failed to copy files to ptfhost.")
request.config.cache.set("ptfhost_unreachable", True)
pt_assert(False, "!!! ptfhost unreachable !!! Exception: {}".format(repr(e)))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you know the Exception is definitely PTF unreachable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wangxin most of time, the unreachable PTF to cause copy file failure, but you are right, I change words to exception.
Please review it again, thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wangxin Thank you for your suggestion.
It turns out pytest_ansible.errors.AnsibleConnectionFailure works, but ansible.errors.AnsibleConnectionFailure doesn't work.

Correct:
from pytest_ansible.errors import AnsibleConnectionFailure

Wrong:
from ansible.errors import AnsibleConnectionFailure


logger.info("Start running icmp_responder")
templ = Template(open(os.path.join(TEMPLATES_DIR, ICMP_RESPONDER_CONF_TEMPL)).read())
Expand Down
6 changes: 6 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ function run_individual_tests()
return ${ret_code}
fi

# rc 16 means ptfhost is unreachable
if [ ${ret_code} -eq 16 ]; then
echo "=== ptfhost is unreachable 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}
Expand Down
Loading