Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 12 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from ansible_host import AnsibleHost
from loganalyzer import LogAnalyzer

from common.devices import SonicHost, Localhost, PTFHost


pytest_plugins = ('ptf_fixtures', 'ansible_fixtures', 'plugins.dut_monitor.pytest_dut_monitor')

Expand Down Expand Up @@ -76,14 +78,19 @@ def testbed_devices(ansible_adhoc, testbed):
@param testbed: Fixture for parsing testbed configuration file.
@return: Return the created device objects in a dictionary
"""
from common.devices import SonicHost, Localhost, PTFHost

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_vars(dut.hostname)["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
Expand All @@ -95,23 +102,21 @@ def testbed_devices(ansible_adhoc, testbed):


@pytest.fixture(scope="module")
def duthost(ansible_adhoc, testbed):
def duthost(testbed_devices):
"""
Shortcut fixture for getting DUT host
"""

hostname = testbed['dut']
return AnsibleHost(ansible_adhoc, hostname)
return testbed_devices["dut"]


@pytest.fixture(scope="module")
def ptfhost(ansible_adhoc, testbed):
def ptfhost(testbed_devices):
"""
Shortcut fixture for getting PTF host
"""

hostname = testbed['ptf']
return AnsibleHost(ansible_adhoc, hostname)
return testbed_devices["ptf"]


@pytest.fixture(scope='session')
Expand Down
3 changes: 1 addition & 2 deletions tests/ptf_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_ifaces(netdev_output):


@pytest.fixture(scope='module')
def ptfadapter(ansible_adhoc, testbed):
def ptfadapter(ptfhost, testbed):
"""return ptf test adapter object.
The fixture is module scope, because usually there is not need to
restart PTF nn agent and reinitialize data plane thread on every
Expand All @@ -43,7 +43,6 @@ def ptfadapter(ansible_adhoc, testbed):
to restart PTF before proceeding running other test modules
"""

ptfhost = AnsibleHost(ansible_adhoc, testbed['ptf'])
# get the eth interfaces from PTF and initialize ifaces_map
res = ptfhost.command('cat /proc/net/dev')
ifaces = get_ifaces(res['stdout'])
Expand Down