Example #1
0
def fixture_duthosts(ansible_adhoc, tbinfo):
    """
    @summary: fixture to get DUT hosts defined in testbed.
    @param ansible_adhoc: Fixture provided by the pytest-ansible package.
        Source of the various device objects. It is
        mandatory argument for the class constructors.
    @param tbinfo: fixture provides information about testbed.
    """
    return [SonicHost(ansible_adhoc, dut) for dut in tbinfo["duts"]]
Example #2
0
def duthost(ansible_adhoc, testbed, request):
    '''
    @summary: Shortcut fixture for getting DUT host. For a lengthy test case, test case module can
              pass a request to disable sh time out mechanis on dut in order to avoid ssh timeout.
              After test case completes, the fixture will restore ssh timeout.
    @param ansible_adhoc: Fixture provided by the pytest-ansible package. Source of the various device objects. It is
        mandatory argument for the class constructors.
    @param testbed: Ansible framework testbed information
    @param request: request parameters for duthost test fixture
    '''
    stop_ssh_timeout = getattr(request.session, "pause_ssh_timeout", None)
    dut_index = getattr(request.session, "dut_index", 0)
    assert dut_index < len(
        testbed["duts"]), "DUT index '{0}' is out of bound '{1}'".format(
            dut_index, len(testbed["duts"]))

    duthost = SonicHost(ansible_adhoc, testbed["duts"][dut_index])
    if stop_ssh_timeout is not None:
        disable_ssh_timout(duthost)

    yield duthost

    if stop_ssh_timeout is not None:
        enable_ssh_timout(duthost)