Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate fixture testbed_devices #1665

Merged
merged 1 commit into from
May 15, 2020
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
3 changes: 1 addition & 2 deletions tests/acl/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def teardown_rules(self, dut, setup):
dut.command('config acl update full {}'.format(remove_rules_dut_path))

@pytest.fixture(scope='class', autouse=True)
def acl_rules(self, duthost, testbed_devices, setup, acl_table):
def acl_rules(self, duthost, localhost, setup, acl_table):
"""
setup/teardown ACL rules based on test class requirements
:param duthost: DUT host object
Expand All @@ -266,7 +266,6 @@ def acl_rules(self, duthost, testbed_devices, setup, acl_table):
:param acl_table: table creating fixture
:return:
"""
localhost = testbed_devices['localhost']
loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='acl_rules')
loganalyzer.load_common_config()

Expand Down
18 changes: 10 additions & 8 deletions tests/common/fixtures/advanced_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ class AdvancedReboot:
inboot/preboot list. The class transfers number of configuration files to the dut/ptf in preparation for reboot test.
Test cases can trigger test start utilizing runRebootTestcase API.
'''
def __init__(self, request, duthost, testbed_devices, testbed, **kwargs):
def __init__(self, request, duthost, ptfhost, localhost, testbed, **kwargs):
'''
Class contructor.
@param request: pytest request object
@param duthost: AnsibleHost instance of DUT
@param testbed_devices: fixture provides information about testbed devices
@param ptfhost: PTFHost for interacting with PTF through ansible
@param localhost: Localhost for interacting with localhost through ansible
@param testbed: fixture provides information about testbed
@param kwargs: extra parameters including reboot type
'''
Expand All @@ -40,8 +41,8 @@ def __init__(self, request, duthost, testbed_devices, testbed, **kwargs):

self.request = request
self.duthost = duthost
self.ptfhost = testbed_devices['ptf']
self.localhost = testbed_devices['localhost']
self.ptfhost = ptfhost
self.localhost = localhost
self.testbed = testbed
self.__dict__.update(kwargs)
self.__extractTestParam()
Expand Down Expand Up @@ -454,7 +455,7 @@ def __restorePrevImage(self):
if currentImage != self.currentImage:
logger.info('Restore current image')
self.duthost.shell('sonic_installer set_default {0}'.format(self.currentImage))

rebootDut(
self.duthost,
self.localhost,
Expand All @@ -480,12 +481,13 @@ def tearDown(self):
self.__restorePrevImage()

@pytest.fixture
def get_advanced_reboot(request, duthost, testbed_devices, testbed):
def get_advanced_reboot(request, duthost, ptfhost, localhost, testbed):
'''
Pytest test fixture that provides access to AdvancedReboot test fixture
@param request: pytest request object
@param duthost: AnsibleHost instance of DUT
@param testbed_devices: fixture provides information about testbed devices
@param ptfhost: PTFHost for interacting with PTF through ansible
@param localhost: Localhost for interacting with localhost through ansible
@param testbed: fixture provides information about testbed
'''
instances = []
Expand All @@ -495,7 +497,7 @@ def get_advanced_reboot(**kwargs):
API that returns instances of AdvancedReboot class
'''
assert len(instances) == 0, "Only one instance of reboot data is allowed"
advancedReboot = AdvancedReboot(request, duthost, testbed_devices, testbed, **kwargs)
advancedReboot = AdvancedReboot(request, duthost, ptfhost, localhost, testbed, **kwargs)
instances.append(advancedReboot)
return advancedReboot

Expand Down
3 changes: 1 addition & 2 deletions tests/common/fixtures/conn_graph_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import json

@pytest.fixture(scope="module")
def conn_graph_facts(duthost, testbed_devices):
def conn_graph_facts(duthost, localhost):
conn_graph_facts = dict()
localhost = testbed_devices["localhost"]

base_path = os.path.dirname(os.path.realpath(__file__))
# json file contains mapping from inventory file name to its corresponding graph file
Expand Down
2 changes: 1 addition & 1 deletion tests/common/plugins/sanity_check/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pytest_plugins = [
sonic-mgmt/tests/common/plugins/sanity_check:
```
@pytest.fixture(scope="module", autouse=True)
def sanity_check(testbed_devices, request):
def sanity_check(localhost, duthost, request, fanouthosts):
...
```

Expand Down
4 changes: 1 addition & 3 deletions tests/common/plugins/sanity_check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ def _update_check_items(old_items, new_items, supported_items):


@pytest.fixture(scope="module", autouse=True)
def sanity_check(testbed_devices, duthost, request, fanouthosts):
def sanity_check(localhost, duthost, request, fanouthosts):
logger.info("Start pre-test sanity check")

localhost = testbed_devices["localhost"]

skip_sanity = False
allow_recover = False
recover_method = "adaptive"
Expand Down
29 changes: 1 addition & 28 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,6 @@ def testbed(request):
return tbinfo.testbed_topo[tbname]


@pytest.fixture(scope="module")
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 disable_ssh_timout(dut):
'''
@summary disable ssh session on target dut
Expand Down Expand Up @@ -218,7 +191,7 @@ def localhost(ansible_adhoc):


@pytest.fixture(scope="module")
def ptfhost(ansible_adhoc, testbed):
def ptfhost(ansible_adhoc, testbed, duthost):
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a miss?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. Calling fixture duthost was missed in another PR #1658. So I added it here.

if "ptf" in testbed:
return PTFHost(ansible_adhoc, testbed["ptf"])
else:
Expand Down
5 changes: 3 additions & 2 deletions tests/drop_counters/fanout/mellanox/mellanox_fanout.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest
from ..fanout_base import BaseFanoutHandler

Expand All @@ -13,11 +14,11 @@


class FanoutHandler(BaseFanoutHandler):
def __init__(self, duthost, testbed_devices):
def __init__(self, duthost, localhost):
self.initialized = False
self.rule_id = MAX_OPENFLOW_RULE_ID
# Ansible localhost fixture which calls ansible playbook on the local host
self.ansible_localhost = testbed_devices["localhost"]
self.ansible_localhost = localhost

dut_facts = self.ansible_localhost.conn_graph_facts(host=duthost.hostname, filename=LAB_CONNECTION_GRAPH)["ansible_facts"]
self.fanout_host = dut_facts["device_conn"]["Ethernet0"]["peerdevice"]
Expand Down
4 changes: 2 additions & 2 deletions tests/drop_counters/test_drop_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def rif_port_down(duthost, setup, loganalyzer):


@pytest.fixture
def fanouthost(request, duthost, testbed_devices):
def fanouthost(request, duthost, localhost):
"""
Fixture that allows to update Fanout configuration if there is a need to send incorrect packets.
Added possibility to create vendor specific logic to handle fanout configuration.
Expand All @@ -285,7 +285,7 @@ def fanouthost(request, duthost, testbed_devices):
# Import fanout configuration handler based on vendor name
if "mellanox" in file_name:
module = importlib.import_module("fanout.{0}.{0}_fanout".format(file_name.strip(".py")))
fanout = module.FanoutHandler(duthost, testbed_devices)
fanout = module.FanoutHandler(duthost, localhost)
break

yield fanout
Expand Down
11 changes: 5 additions & 6 deletions tests/ipfwd/test_dip_sip.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@


@pytest.fixture(scope='function', autouse=True)
def prepare_ptf(testbed_devices):
ptfhost = testbed_devices["ptf"]
def prepare_ptf(ptfhost):
# remove existing IPs from ptf host
ptfhost.script('scripts/remove_ip.sh')
# set unique MACs to ptf interfaces
Expand Down Expand Up @@ -110,7 +109,7 @@ def run_test_ipv6(ptfadapter, gather_facts):
logger.info("\nSend Packet:\neth_dst: {}, eth_src: {}, ipv6 ip: {}".format(
gather_facts['src_router_mac'], gather_facts['src_host_mac'], dst_host_ipv6)
)

testutils.send(ptfadapter, int(gather_facts['src_port_ids'][0]), pkt)

pkt = testutils.simple_udpv6_packet(
Expand All @@ -123,7 +122,7 @@ def run_test_ipv6(ptfadapter, gather_facts):
logger.info("\nExpect Packet:\neth_dst: {}, eth_src: {}, ipv6 ip: {}".format(
gather_facts['dst_host_mac'], gather_facts['dst_router_mac'], dst_host_ipv6)
)

port_list = [int(port) for port in gather_facts['dst_port_ids']]
testutils.verify_packet_any_port(ptfadapter, pkt, port_list, timeout=WAIT_EXPECTED_PACKET_TIMEOUT)

Expand All @@ -141,7 +140,7 @@ def run_test_ipv4(ptfadapter, gather_facts):
logger.info("\nSend Packet:\neth_dst: {}, eth_src: {}, ipv6 ip: {}".format(
gather_facts['src_router_mac'], gather_facts['src_host_mac'], dst_host_ipv4)
)

testutils.send(ptfadapter, int(gather_facts['src_port_ids'][0]), pkt)

pkt = testutils.simple_udp_packet(
Expand All @@ -154,7 +153,7 @@ def run_test_ipv4(ptfadapter, gather_facts):
logger.info("\nExpect Packet:\neth_dst: {}, eth_src: {}, ipv6 ip: {}".format(
gather_facts['dst_host_mac'], gather_facts['dst_router_mac'], dst_host_ipv4)
)

port_list = [int(port) for port in gather_facts['dst_port_ids']]
testutils.verify_packet_any_port(ptfadapter, pkt, port_list, timeout=WAIT_EXPECTED_PACKET_TIMEOUT)

Expand Down
3 changes: 1 addition & 2 deletions tests/platform_tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
SERVER_PORT = 8000

@pytest.fixture(scope='function')
def start_platform_api_service(duthost, testbed_devices):
localhost = testbed_devices['localhost']
def start_platform_api_service(duthost, localhost):
res = localhost.wait_for(host=duthost.hostname, port=SERVER_PORT, state='started', delay=1, timeout=5)
if 'exception' in res:
supervisor_conf = [
Expand Down
9 changes: 2 additions & 7 deletions tests/platform_tests/api/test_watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,10 @@ def conf(self, request, duthost):
return config


def test_arm_disarm_states(self, duthost, testbed_devices, platform_api_conn, conf):
def test_arm_disarm_states(self, duthost, localhost, platform_api_conn, conf):
''' arm watchdog with a valid timeout value, verify it is in armed state,
disarm watchdog and verify it is in disarmed state
'''

localhost = testbed_devices['localhost']

watchdog_timeout = conf['valid_timeout']
actual_timeout = watchdog.arm(platform_api_conn, watchdog_timeout)

Expand Down Expand Up @@ -160,11 +157,9 @@ def test_arm_negative_timeout(self, duthost, platform_api_conn):
assert actual_timeout == -1

@pytest.mark.disable_loganalyzer
def test_reboot(self, duthost, testbed_devices, platform_api_conn, conf):
def test_reboot(self, duthost, localhost, platform_api_conn, conf):
''' arm the watchdog and verify it did its job after timeout expiration '''

localhost = testbed_devices['localhost']

watchdog_timeout = conf['valid_timeout']
actual_timeout = watchdog.arm(platform_api_conn, watchdog_timeout)

Expand Down
25 changes: 7 additions & 18 deletions tests/platform_tests/test_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,24 @@ def check_interfaces_and_services(dut, interfaces, reboot_type = None):
check_sysfs(dut)


def test_cold_reboot(duthost, testbed_devices, conn_graph_facts):
def test_cold_reboot(duthost, localhost, conn_graph_facts):
"""
@summary: This test case is to perform cold reboot and check platform status
"""
localhost = testbed_devices["localhost"]

reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_COLD)


def test_fast_reboot(duthost, testbed_devices, conn_graph_facts):
def test_fast_reboot(duthost, localhost, conn_graph_facts):
"""
@summary: This test case is to perform cold reboot and check platform status
"""
localhost = testbed_devices["localhost"]

reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_FAST)


def test_warm_reboot(duthost, testbed_devices, conn_graph_facts):
def test_warm_reboot(duthost, localhost, conn_graph_facts):
"""
@summary: This test case is to perform cold reboot and check platform status
"""
localhost = testbed_devices["localhost"]
asic_type = duthost.facts["asic_type"]

if asic_type in ["mellanox"]:
Expand Down Expand Up @@ -167,17 +162,15 @@ def _power_off_reboot_helper(kwargs):
psu_ctrl.turn_on_psu(psu["psu_id"])


def test_power_off_reboot(duthost, testbed_devices, conn_graph_facts, psu_controller, power_off_delay):
def test_power_off_reboot(duthost, localhost, conn_graph_facts, psu_controller, power_off_delay):
"""
@summary: This test case is to perform reboot via powercycle and check platform status
@param testbed_devices: Fixture initialize devices in testbed
@param duthost: Fixture for DUT AnsibleHost object
@param localhost: Fixture for interacting with localhost through ansible
@param conn_graph_facts: Fixture parse and return lab connection graph
@param psu_controller: The python object of psu controller
@param power_off_delay: Pytest fixture. The delay between turning off and on the PSU
"""
localhost = testbed_devices["localhost"]

psu_ctrl = psu_controller
if psu_ctrl is None:
pytest.skip("No PSU controller for %s, skip rest of the testing in this case" % duthost.hostname)
Expand Down Expand Up @@ -207,12 +200,10 @@ def test_power_off_reboot(duthost, testbed_devices, conn_graph_facts, psu_contro
_power_off_reboot_helper, poweroff_reboot_kwargs)


def test_watchdog_reboot(duthost, testbed_devices, conn_graph_facts):
def test_watchdog_reboot(duthost, localhost, conn_graph_facts):
"""
@summary: This test case is to perform reboot via watchdog and check platform status
"""
localhost = testbed_devices["localhost"]

test_watchdog_supported = "python -c \"import sonic_platform.platform as P; P.Platform().get_chassis().get_watchdog(); exit()\""

watchdog_supported = duthost.command(test_watchdog_supported,module_ignore_errors=True)["stderr"]
Expand All @@ -222,11 +213,9 @@ def test_watchdog_reboot(duthost, testbed_devices, conn_graph_facts):
reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"], REBOOT_TYPE_WATCHDOG)


def test_continuous_reboot(duthost, testbed_devices, conn_graph_facts):
def test_continuous_reboot(duthost, localhost, conn_graph_facts):
"""
@summary: This test case is to perform 3 cold reboot in a row
"""
localhost = testbed_devices["localhost"]

for i in range(3):
reboot_and_check(localhost, duthost, conn_graph_facts["device_conn"], reboot_type=REBOOT_TYPE_COLD)
6 changes: 2 additions & 4 deletions tests/platform_tests/test_sequential_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ def restart_service_and_check(localhost, dut, service, interfaces):
check_sysfs(dut)


def test_restart_swss(duthost, testbed_devices, conn_graph_facts):
def test_restart_swss(duthost, localhost, conn_graph_facts):
"""
@summary: This test case is to restart the swss service and check platform status
"""
localhost = testbed_devices["localhost"]
restart_service_and_check(localhost, duthost, "swss", conn_graph_facts["device_conn"])


@pytest.mark.skip(reason="Restarting syncd is not supported yet")
def test_restart_syncd(duthost, testbed_devices, conn_graph_facts):
def test_restart_syncd(duthost, localhost, conn_graph_facts):
"""
@summary: This test case is to restart the syncd service and check platform status
"""
localhost = testbed_devices["localhost"]
restart_service_and_check(localhost, duthost, "syncd", conn_graph_facts["device_conn"])
Loading