示例#1
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.module, "pause_ssh_timeout", None)
    dut_index = getattr(request.module, "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],
                        gather_facts=True)
    if stop_ssh_timeout is not None:
        disable_ssh_timout(duthost)

    yield duthost

    if stop_ssh_timeout is not None:
        enable_ssh_timout(duthost)
示例#2
0
def testbed_devices(ansible_adhoc, testbed, duthost):
    """
    @summary: Fixture for creating dut, localhost and other necessary objects for testing. These objects provide
        interfaces for interacting with the devices used in testing.
    @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: Fixture for parsing testbed configuration file.
    @return: Return the created device objects in a dictionary
    """

    devices = {
        "localhost":
        Localhost(ansible_adhoc),
        "duts": [
            SonicHost(ansible_adhoc, x, gather_facts=True)
            for x in testbed["duts"]
        ],
    }

    if "ptf" in testbed:
        devices["ptf"] = PTFHost(ansible_adhoc, testbed["ptf"])
    else:
        # when no ptf defined in testbed.csv
        # try to parse it from inventory
        ptf_host = duthost.host.options["inventory_manager"].get_host(
            duthost.hostname).get_vars()["ptf_host"]
        devices["ptf"] = PTFHost(ansible_adhoc, ptf_host)

    return devices
示例#3
0
def testbed_devices(ansible_adhoc, testbed):
    """
    @summary: Fixture for creating dut, localhost and other necessary objects for testing. These objects provide
        interfaces for interacting with the devices used in testing.
    @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: Fixture for parsing testbed configuration file.
    @return: Return the created device objects in a dictionary
    """

    devices = {
        "localhost": Localhost(ansible_adhoc),
        "dut": SonicHost(ansible_adhoc, testbed["dut"], gather_facts=True)
    }

    if "ptf" in testbed:
        devices["ptf"] = PTFHost(ansible_adhoc, testbed["ptf"])
    else:
        # when no ptf defined in testbed.csv
        # try to parse it from inventory
        dut = devices["dut"]
        ptf_host = dut.host.options["inventory_manager"].get_host(
            dut.hostname).get_vars()["ptf_host"]
        devices["ptf"] = PTFHost(ansible_adhoc, ptf_host)

    # In the future, we can implement more classes for interacting with other testbed devices in the lib.devices
    # module. Then, in this fixture, we can initialize more instance of the classes and store the objects in the
    # devices dict here. For example, we could have
    #       from common.devices import FanoutHost
    #       devices["fanout"] = FanoutHost(ansible_adhoc, testbed["dut"])

    return devices
示例#4
0
def testbed_devices(ansible_adhoc, testbed):
    """
    @summary: Fixture for creating dut, localhost and other necessary objects for testing. These objects provide
        interfaces for interacting with the devices used in testing.
    @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: Fixture for parsing testbed configuration file.
    @return: Return the created device objects in a dictionary
    """
    from common.devices import SonicHost, Localhost

    devices = {}
    devices["localhost"] = Localhost(ansible_adhoc)
    devices["dut"] = SonicHost(ansible_adhoc,
                               testbed["dut"],
                               gather_facts=True)
    if "ptf" in testbed:
        devices["ptf"] = PTFHost(ansible_adhoc, testbed["ptf"])

    # In the future, we can implement more classes for interacting with other testbed devices in the lib.devices
    # module. Then, in this fixture, we can initialize more instance of the classes and store the objects in the
    # devices dict here. For example, we could have
    #       from common.devices import FanoutHost
    #       devices["fanout"] = FanoutHost(ansible_adhoc, testbed["dut"])

    return devices
示例#5
0
def duthost2(ansible_adhoc, request):
    """
    Shortcut fixture for getting DUT2 host
    """
    tbname = request.config.getoption("--testbed")
    tbfile = request.config.getoption("--testbed_file")
    tbinfo = TBInfo(tbfile)
    hostname2 = tbinfo.testbed_topo[tbname + '-dut2']['dut']
    return SonicHost(ansible_adhoc, hostname2, gather_facts=True)