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
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
def ptfhost(ansible_adhoc, testbed): if "ptf" in testbed: return 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"] return PTFHost(ansible_adhoc, ptf_host)