diff --git a/tests/acl/test_acl.py b/tests/acl/test_acl.py index dca4a7d42b7..48469315246 100644 --- a/tests/acl/test_acl.py +++ b/tests/acl/test_acl.py @@ -12,8 +12,8 @@ import ptf.mask as mask import ptf.packet as packet -from common import reboot, port_toggle -from common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError +from tests.common import reboot, port_toggle +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError logger = logging.getLogger(__name__) diff --git a/tests/arp/conftest.py b/tests/arp/conftest.py index 734ddd75c80..71ea65eeaa4 100644 --- a/tests/arp/conftest.py +++ b/tests/arp/conftest.py @@ -1,4 +1,4 @@ -from args.wr_arp_args import add_wr_arp_args +from .args.wr_arp_args import add_wr_arp_args # WR-ARP pytest arguments def pytest_addoption(parser): diff --git a/tests/arp/test_arpall.py b/tests/arp/test_arpall.py index 34826a9a726..e6d7de61166 100644 --- a/tests/arp/test_arpall.py +++ b/tests/arp/test_arpall.py @@ -3,8 +3,8 @@ import time from datetime import datetime -from ptf_runner import ptf_runner -from common.helpers.assertions import pytest_assert +from tests.ptf_runner import ptf_runner +from tests.common.helpers.assertions import pytest_assert pytestmark = [ pytest.mark.topology('t1') diff --git a/tests/arp/test_neighbor_mac_noptf.py b/tests/arp/test_neighbor_mac_noptf.py index 702ef3683c4..61075b6d1b4 100644 --- a/tests/arp/test_neighbor_mac_noptf.py +++ b/tests/arp/test_neighbor_mac_noptf.py @@ -2,8 +2,8 @@ import pytest import time -from common.helpers.assertions import pytest_assert -from common.config_reload import config_reload +from tests.common.helpers.assertions import pytest_assert +from tests.common.config_reload import config_reload logger = logging.getLogger(__name__) @@ -36,7 +36,7 @@ def restoreDutConfig(self, duthost): None """ yield - + logger.info("Reload Config DB") config_reload(duthost, config_source='config_db', wait=120) @@ -44,7 +44,7 @@ def restoreDutConfig(self, duthost): def ipVersion(self, request): """ Parameterized fixture for IP versions. This Fixture will run the test twice for both - IPv4 and IPv6 + IPv4 and IPv6 Args: request: pytest request object diff --git a/tests/arp/test_wr_arp.py b/tests/arp/test_wr_arp.py index aa9c8352508..b38a0dcac99 100644 --- a/tests/arp/test_wr_arp.py +++ b/tests/arp/test_wr_arp.py @@ -2,10 +2,10 @@ import logging import pytest -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] -from common.platform.ssh_utils import prepare_testbed_ssh_keys as prepareTestbedSshKeys -from ptf_runner import ptf_runner +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.common.platform.ssh_utils import prepare_testbed_ssh_keys as prepareTestbedSshKeys +from tests.ptf_runner import ptf_runner logger = logging.getLogger(__name__) diff --git a/tests/bgp/conftest.py b/tests/bgp/conftest.py index 7ceb77d7657..abee0fd71f1 100644 --- a/tests/bgp/conftest.py +++ b/tests/bgp/conftest.py @@ -1,6 +1,6 @@ import pytest import logging -from common.utilities import wait_until +from tests.common.utilities import wait_until logger = logging.getLogger(__name__) diff --git a/tests/bgp/test_bgp_gr_helper.py b/tests/bgp/test_bgp_gr_helper.py index 32bf6cffb08..c164183ec2e 100644 --- a/tests/bgp/test_bgp_gr_helper.py +++ b/tests/bgp/test_bgp_gr_helper.py @@ -1,8 +1,8 @@ import pytest import logging import ipaddress -from common.helpers.assertions import pytest_assert -from common.utilities import wait_until +from tests.common.helpers.assertions import pytest_assert +from tests.common.utilities import wait_until pytestmark = [ pytest.mark.topology('t1'), diff --git a/tests/bgp/test_bgp_multipath_relax.py b/tests/bgp/test_bgp_multipath_relax.py index 42e34cd0392..329b5968ae6 100644 --- a/tests/bgp/test_bgp_multipath_relax.py +++ b/tests/bgp/test_bgp_multipath_relax.py @@ -1,6 +1,6 @@ import pytest import logging -from common.helpers.assertions import pytest_assert +from tests.common.helpers.assertions import pytest_assert logger = logging.getLogger(__name__) @@ -13,7 +13,7 @@ def get_t2_neigh(testbed): def get_t0_neigh(testbed, topo_config): """ - get all t0 router names which has vips defined + get all t0 router names which has vips defined """ dut_t0_neigh = [] for vm in testbed['topo']['properties']['topology']['VMs'].keys(): @@ -47,7 +47,7 @@ def get_vips_prefix_paths(dut_t0_neigh, vips_prefix, topo_config): def get_bgp_v4_neighbors_from_minigraph(duthost, testbed): mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] - + # Find all V4 bgp neighbors from minigraph bgp_v4nei = {} for item in mg_facts['minigraph_bgp']: @@ -64,30 +64,30 @@ def test_bgp_multipath_relax(testbed, duthost): bgp_v4nei = get_bgp_v4_neighbors_from_minigraph(duthost, testbed) logger.info("bgp_v4nei {}".format(bgp_v4nei)) - + # get all t0 routers name which has vips defined dut_t0_neigh = get_t0_neigh(testbed, topo_config) # get t2 neighbors dut_t2_neigh = get_t2_neigh(testbed) - + if not dut_t0_neigh: pytest.fail("Didn't find multipath t0's") vips_prefix = get_vips_prefix(dut_t0_neigh, topo_config) - + logger.info("vips_prefix = {}".format(vips_prefix)) - # find all paths of the prefix for test + # find all paths of the prefix for test vips_t0, vips_asn = get_vips_prefix_paths(dut_t0_neigh, vips_prefix, topo_config) - + logger.info("vips_t0: {}, vips_asn: {}".format(vips_t0, vips_asn)) pytest_assert((vips_t0 > 1), "Did not find preconfigured multipath for the vips prefix under test") - + # Get the route from the DUT for the prefix bgp_route = duthost.bgp_route(prefix=vips_prefix)['ansible_facts']['bgp_route'] - + logger.info("Bgp route from DUT for prefix {} is {}".format(vips_prefix,bgp_route)) # Verify found vips prefix entry in Sonic bgp routes @@ -96,7 +96,7 @@ def test_bgp_multipath_relax(testbed, duthost): # Verify total multipath match number of t0 with vips that has prefix for test pytest_assert (int(bgp_route[vips_prefix]['path_num']) == len(vips_t0), "Path number doesnt match the T0s with VIPS") - + # verify vips asn in each path of installed BGP vips prefix for asn in vips_asn: for aspath in bgp_route[vips_prefix]['aspath']: @@ -104,7 +104,7 @@ def test_bgp_multipath_relax(testbed, duthost): # gather one t2 neighbor advertised routes to validate routes advertised to t2 are correct with relaxed multipath bgp_route_neiadv = duthost.bgp_route(neighbor=bgp_v4nei[dut_t2_neigh[0]], direction="adv")['ansible_facts']['bgp_route_neiadv'] - + logger.info("Bgp neighbor adv from DUT for neigh {} and prefix {} is {}". format(bgp_v4nei[dut_t2_neigh[0]], vips_prefix, diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index c67c495510c..7556cd0fb9f 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -4,10 +4,10 @@ import logging import requests -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] -from ptf_runner import ptf_runner -from common.utilities import wait_tcp_connection +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner +from tests.common.utilities import wait_tcp_connection pytestmark = [ pytest.mark.topology('t0'), diff --git a/tests/common/fixtures/advanced_reboot.py b/tests/common/fixtures/advanced_reboot.py index d0a8d0ca33c..99e9900d0e4 100644 --- a/tests/common/fixtures/advanced_reboot.py +++ b/tests/common/fixtures/advanced_reboot.py @@ -5,10 +5,10 @@ import pytest import time -from common.mellanox_data import is_mellanox_device as isMellanoxDevice -from common.platform.ssh_utils import prepare_testbed_ssh_keys as prepareTestbedSshKeys -from common.reboot import reboot as rebootDut -from ptf_runner import ptf_runner +from tests.common.mellanox_data import is_mellanox_device as isMellanoxDevice +from tests.common.platform.ssh_utils import prepare_testbed_ssh_keys as prepareTestbedSshKeys +from tests.common.reboot import reboot as rebootDut +from tests.ptf_runner import ptf_runner logger = logging.getLogger(__name__) diff --git a/tests/common/fixtures/pfc_asym.py b/tests/common/fixtures/pfc_asym.py index 88e3ce140d7..57b35a4459a 100755 --- a/tests/common/fixtures/pfc_asym.py +++ b/tests/common/fixtures/pfc_asym.py @@ -3,7 +3,7 @@ import time from netaddr import IPAddress -from common.helpers.generators import generate_ips +from tests.common.helpers.generators import generate_ips PFC_GEN_FILE = "pfc_gen.py" diff --git a/tests/common/fixtures/populate_fdb.py b/tests/common/fixtures/populate_fdb.py index 989e8bde4bc..c567bbbb5ba 100644 --- a/tests/common/fixtures/populate_fdb.py +++ b/tests/common/fixtures/populate_fdb.py @@ -2,7 +2,7 @@ import logging import pytest -from ptf_runner import ptf_runner +from tests.ptf_runner import ptf_runner logger = logging.getLogger(__name__) diff --git a/tests/common/helpers/pfc_storm.py b/tests/common/helpers/pfc_storm.py index 40425d43ef6..292ca7b0d2b 100644 --- a/tests/common/helpers/pfc_storm.py +++ b/tests/common/helpers/pfc_storm.py @@ -1,6 +1,6 @@ import logging import os -from common.errors import MissingInputError +from tests.common.errors import MissingInputError TEMPLATES_DIR = os.path.realpath((os.path.join(os.path.dirname(__file__), "../../common/templates"))) ANSIBLE_ROOT = os.path.realpath((os.path.join(os.path.dirname(__file__), "../../../ansible"))) diff --git a/tests/common/platform/ssh_utils.py b/tests/common/platform/ssh_utils.py index 05726e2c24c..3e9637c9d6d 100644 --- a/tests/common/platform/ssh_utils.py +++ b/tests/common/platform/ssh_utils.py @@ -1,6 +1,6 @@ import logging -from common.errors import RunAnsibleModuleFail +from tests.common.errors import RunAnsibleModuleFail logger = logging.getLogger(__name__) @@ -38,8 +38,8 @@ def prepare_testbed_ssh_keys(duthost, ptfhost, dut_username): ptfhost.file(path='/root/.ssh/id_rsa.pub', mode='u=rw,g=,o=') cmd = ''' - mkdir -p /home/{0}/.ssh && - echo "{1}" >> /home/{0}/.ssh/authorized_keys && + mkdir -p /home/{0}/.ssh && + echo "{1}" >> /home/{0}/.ssh/authorized_keys && chown -R {0}:{0} /home/{0}/.ssh/ '''.format(dut_username, result['public_key']) duthost.shell(cmd) diff --git a/tests/common/plugins/fib.py b/tests/common/plugins/fib.py index 471182258cd..e6c5419ccd2 100644 --- a/tests/common/plugins/fib.py +++ b/tests/common/plugins/fib.py @@ -5,7 +5,7 @@ import pytest import logging import ipaddr as ipaddress -from common.utilities import wait_tcp_connection +from tests.common.utilities import wait_tcp_connection logger = logging.getLogger(__name__) diff --git a/tests/common/plugins/sanity_check/checks.py b/tests/common/plugins/sanity_check/checks.py index 0c322d2901c..d21655e613b 100644 --- a/tests/common/plugins/sanity_check/checks.py +++ b/tests/common/plugins/sanity_check/checks.py @@ -3,7 +3,7 @@ import logging import time -from common.utilities import wait +from tests.common.utilities import wait logger = logging.getLogger(__name__) SYSTEM_STABILIZE_MAX_TIME = 300 diff --git a/tests/common/plugins/sanity_check/recover.py b/tests/common/plugins/sanity_check/recover.py index a0c2633cbe7..55c6eca0c52 100644 --- a/tests/common/plugins/sanity_check/recover.py +++ b/tests/common/plugins/sanity_check/recover.py @@ -3,9 +3,9 @@ import constants -from common.utilities import wait -from common.errors import RunAnsibleModuleFail -from common.platform.device_utils import fanout_switch_port_lookup +from tests.common.utilities import wait +from tests.common.errors import RunAnsibleModuleFail +from tests.common.platform.device_utils import fanout_switch_port_lookup logger = logging.getLogger(__name__) diff --git a/tests/common/system_utils/docker.py b/tests/common/system_utils/docker.py index de301e5fa94..90997b3e5d6 100644 --- a/tests/common/system_utils/docker.py +++ b/tests/common/system_utils/docker.py @@ -8,8 +8,8 @@ import time import yaml -from common.broadcom_data import is_broadcom_device -from common.mellanox_data import is_mellanox_device +from tests.common.broadcom_data import is_broadcom_device +from tests.common.mellanox_data import is_mellanox_device _LOGGER = logging.getLogger(__name__) diff --git a/tests/conftest.py b/tests/conftest.py index 67fbcb7183a..5513cffefaf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,3 @@ -# Adding pytest base dir to Python system path. -# This is required in order to import from common package including pytest_plugins within this file. -import site -from os.path import dirname, abspath -site.addsitedir(dirname(abspath(__file__))) -site.addsitedir('.') - import sys import os import glob @@ -22,20 +15,20 @@ import ipaddr as ipaddress from collections import defaultdict -from common.fixtures.conn_graph_facts import conn_graph_facts, fanout_graph_facts -from common.devices import SonicHost, Localhost, PTFHost, EosHost, FanoutHost +from tests.common.fixtures.conn_graph_facts import conn_graph_facts, fanout_graph_facts +from tests.common.devices import SonicHost, Localhost, PTFHost, EosHost, FanoutHost logger = logging.getLogger(__name__) -pytest_plugins = ('common.plugins.ptfadapter', - 'common.plugins.ansible_fixtures', - 'common.plugins.dut_monitor', - 'common.plugins.fib', - 'common.plugins.tacacs', - 'common.plugins.loganalyzer', - 'common.plugins.psu_controller', - 'common.plugins.sanity_check', - 'common.plugins.custom_markers') +pytest_plugins = ('tests.common.plugins.ptfadapter', + 'tests.common.plugins.ansible_fixtures', + 'tests.common.plugins.dut_monitor', + 'tests.common.plugins.fib', + 'tests.common.plugins.tacacs', + 'tests.common.plugins.loganalyzer', + 'tests.common.plugins.psu_controller', + 'tests.common.plugins.sanity_check', + 'tests.common.plugins.custom_markers') class TestbedInfo(object): diff --git a/tests/copp/test_copp.py b/tests/copp/test_copp.py index 4c2b02cd266..8c9fa8cba68 100644 --- a/tests/copp/test_copp.py +++ b/tests/copp/test_copp.py @@ -30,12 +30,12 @@ import pytest from collections import namedtuple -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] -from copp import copp_utils -from ptf_runner import ptf_runner -from common.system_utils import docker -from common.broadcom_data import is_broadcom_device +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.copp import copp_utils +from tests.ptf_runner import ptf_runner +from tests.common.system_utils import docker +from tests.common.broadcom_data import is_broadcom_device pytestmark = [ pytest.mark.topology('t1') diff --git a/tests/decap/test_decap.py b/tests/decap/test_decap.py index 2e3e0f6f213..91abcb6cd8b 100644 --- a/tests/decap/test_decap.py +++ b/tests/decap/test_decap.py @@ -7,10 +7,10 @@ from netaddr import IPNetwork from ansible.plugins.filter.core import to_bool -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] -from ptf_runner import ptf_runner -from common.plugins.fib import generate_routes +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner +from tests.common.plugins.fib import generate_routes logger = logging.getLogger(__name__) diff --git a/tests/dhcp_relay/test_dhcp_relay.py b/tests/dhcp_relay/test_dhcp_relay.py index f557f220467..c9694c88e4c 100644 --- a/tests/dhcp_relay/test_dhcp_relay.py +++ b/tests/dhcp_relay/test_dhcp_relay.py @@ -2,9 +2,9 @@ import pytest import time -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] -from ptf_runner import ptf_runner +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner pytestmark = [ pytest.mark.topology('t0'), diff --git a/tests/drop_counters/test_drop_counters.py b/tests/drop_counters/test_drop_counters.py index 47c8e61f11f..6baf51e1fc1 100755 --- a/tests/drop_counters/test_drop_counters.py +++ b/tests/drop_counters/test_drop_counters.py @@ -13,7 +13,7 @@ import json import netaddr -from common.utilities import wait_until +from tests.common.utilities import wait_until pytestmark = [ pytest.mark.topology('any') diff --git a/tests/everflow/test_everflow_testbed.py b/tests/everflow/test_everflow_testbed.py index ead8ae93495..b6d3dd4294b 100644 --- a/tests/everflow/test_everflow_testbed.py +++ b/tests/everflow/test_everflow_testbed.py @@ -3,9 +3,9 @@ import pytest import ipaddr as ipaddress -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import copy_acstests_directory # lgtm[py/unused-import] -from ptf_runner import ptf_runner +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import copy_acstests_directory # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner from abc import abstractmethod BASE_DIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/fdb/conftest.py b/tests/fdb/conftest.py index 0fd5f42fcc0..507a7eac371 100644 --- a/tests/fdb/conftest.py +++ b/tests/fdb/conftest.py @@ -1,4 +1,4 @@ -from args.fdb_args import add_fdb_mac_expire_args +from .args.fdb_args import add_fdb_mac_expire_args # FDB pytest arguments def pytest_addoption(parser): diff --git a/tests/fdb/test_fdb.py b/tests/fdb/test_fdb.py index ee964d5df3d..3d570d0158d 100644 --- a/tests/fdb/test_fdb.py +++ b/tests/fdb/test_fdb.py @@ -7,7 +7,7 @@ import logging import pprint -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] pytestmark = [ pytest.mark.topology('t0') diff --git a/tests/fdb/test_fdb_mac_expire.py b/tests/fdb/test_fdb_mac_expire.py index 2a64722b7fd..ae116261cbf 100644 --- a/tests/fdb/test_fdb_mac_expire.py +++ b/tests/fdb/test_fdb_mac_expire.py @@ -2,8 +2,8 @@ import pytest import time -from common.helpers.assertions import pytest_assert -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm [py/unused-import] +from tests.common.helpers.assertions import pytest_assert +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm [py/unused-import] pytestmark = [ pytest.mark.topology('t0') diff --git a/tests/fib/test_fib.py b/tests/fib/test_fib.py index fa1c7e40a2c..e1983751fbf 100644 --- a/tests/fib/test_fib.py +++ b/tests/fib/test_fib.py @@ -4,8 +4,8 @@ import logging import tempfile -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from ptf_runner import ptf_runner +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner from datetime import datetime logger = logging.getLogger(__name__) diff --git a/tests/iface_namingmode/test_iface_namingmode.py b/tests/iface_namingmode/test_iface_namingmode.py index 8cac2736f6d..a536b8b4f39 100644 --- a/tests/iface_namingmode/test_iface_namingmode.py +++ b/tests/iface_namingmode/test_iface_namingmode.py @@ -2,8 +2,8 @@ import pytest import re -from common.devices import AnsibleHostBase -from common.utilities import wait +from tests.common.devices import AnsibleHostBase +from tests.common.utilities import wait from netaddr import IPAddress pytestmark = [ diff --git a/tests/ipfwd/test_dip_sip.py b/tests/ipfwd/test_dip_sip.py index 58f2cccd7ab..95f69a233b9 100644 --- a/tests/ipfwd/test_dip_sip.py +++ b/tests/ipfwd/test_dip_sip.py @@ -3,7 +3,7 @@ from ipaddress import ip_address import logging -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] TOPO_LIST = {'t0', 't1', 't1-lag'} PORTS_TOPO = {'t1'} diff --git a/tests/ipfwd/test_dir_bcast.py b/tests/ipfwd/test_dir_bcast.py index ea831a5ae75..4caea2e6880 100644 --- a/tests/ipfwd/test_dir_bcast.py +++ b/tests/ipfwd/test_dir_bcast.py @@ -1,7 +1,7 @@ import pytest -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from ptf_runner import ptf_runner +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner from datetime import datetime pytestmark = [ diff --git a/tests/ipfwd/test_mtu.py b/tests/ipfwd/test_mtu.py index 85d4939b000..bcb716bb894 100644 --- a/tests/ipfwd/test_mtu.py +++ b/tests/ipfwd/test_mtu.py @@ -2,8 +2,8 @@ import time import logging -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from ptf_runner import ptf_runner +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner from datetime import datetime pytestmark = [ diff --git a/tests/ntp/test_ntp.py b/tests/ntp/test_ntp.py index b0660bb2eb1..ebfa1d7c92c 100644 --- a/tests/ntp/test_ntp.py +++ b/tests/ntp/test_ntp.py @@ -1,5 +1,5 @@ -from common.utilities import wait_until -from common.helpers.assertions import pytest_assert +from tests.common.utilities import wait_until +from tests.common.helpers.assertions import pytest_assert import logging logger = logging.getLogger(__name__) diff --git a/tests/pc/test_lag_2.py b/tests/pc/test_lag_2.py index 9c2ddef2637..b508f430b2e 100644 --- a/tests/pc/test_lag_2.py +++ b/tests/pc/test_lag_2.py @@ -5,11 +5,11 @@ import logging import os -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from ptf_runner import ptf_runner -from common.devices import AnsibleHostBase -from common.fixtures.conn_graph_facts import conn_graph_facts -from common.utilities import wait_until +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner +from tests.common.devices import AnsibleHostBase +from tests.common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.utilities import wait_until pytestmark = [ pytest.mark.topology('any') diff --git a/tests/pfc_asym/conftest.py b/tests/pfc_asym/conftest.py index 36e86d402bc..02bf858f5a3 100755 --- a/tests/pfc_asym/conftest.py +++ b/tests/pfc_asym/conftest.py @@ -1,9 +1,9 @@ import pytest -from common.fixtures.conn_graph_facts import fanout_graph_facts -from common.fixtures.pfc_asym import * -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import copy_saitests_directory # lgtm[py/unused-import] +from tests.common.fixtures.conn_graph_facts import fanout_graph_facts +from tests.common.fixtures.pfc_asym import * +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import copy_saitests_directory # lgtm[py/unused-import] @pytest.fixture(autouse=True) diff --git a/tests/pfc_asym/test_pfc_asym.py b/tests/pfc_asym/test_pfc_asym.py index 9efb3ceedce..ad307a5b13a 100755 --- a/tests/pfc_asym/test_pfc_asym.py +++ b/tests/pfc_asym/test_pfc_asym.py @@ -1,4 +1,4 @@ -from ptf_runner import ptf_runner +from tests.ptf_runner import ptf_runner import pytest pytestmark = [ diff --git a/tests/pfcwd/conftest.py b/tests/pfcwd/conftest.py index 6d9bd4e859a..2faffa6b81e 100644 --- a/tests/pfcwd/conftest.py +++ b/tests/pfcwd/conftest.py @@ -1,12 +1,14 @@ import logging import pytest -from common.fixtures.conn_graph_facts import conn_graph_facts -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] -from files.pfcwd_helper import TrafficPorts, set_pfc_timers, select_test_ports + +from tests.common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from .files.pfcwd_helper import TrafficPorts, set_pfc_timers, select_test_ports logger = logging.getLogger(__name__) + def pytest_addoption(parser): """ Command line args specific for the pfcwd test diff --git a/tests/pfcwd/test_pfc_config.py b/tests/pfcwd/test_pfc_config.py index 89f9da7333b..e8fd6ff83f1 100644 --- a/tests/pfcwd/test_pfc_config.py +++ b/tests/pfcwd/test_pfc_config.py @@ -3,8 +3,8 @@ import pytest import logging -from common.helpers.assertions import pytest_assert -from common.plugins.loganalyzer.loganalyzer import LogAnalyzer +from tests.common.helpers.assertions import pytest_assert +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer logger = logging.getLogger(__name__) diff --git a/tests/pfcwd/test_pfcwd_all_port_storm.py b/tests/pfcwd/test_pfcwd_all_port_storm.py index 5c0cc38d61d..3ca1d4276e8 100644 --- a/tests/pfcwd/test_pfcwd_all_port_storm.py +++ b/tests/pfcwd/test_pfcwd_all_port_storm.py @@ -2,10 +2,10 @@ import os import pytest -from common.fixtures.conn_graph_facts import fanout_graph_facts -from common.helpers.pfc_storm import PFCMultiStorm -from common.plugins.loganalyzer.loganalyzer import LogAnalyzer -from files.pfcwd_helper import start_wd_on_ports +from tests.common.fixtures.conn_graph_facts import fanout_graph_facts +from tests.common.helpers.pfc_storm import PFCMultiStorm +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer +from .files.pfcwd_helper import start_wd_on_ports TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates") EXPECT_PFC_WD_DETECT_RE = ".* detected PFC storm .*" diff --git a/tests/pfcwd/test_pfcwd_function.py b/tests/pfcwd/test_pfcwd_function.py index d6c8ddb6963..2a31cb2394c 100644 --- a/tests/pfcwd/test_pfcwd_function.py +++ b/tests/pfcwd/test_pfcwd_function.py @@ -4,12 +4,12 @@ import pytest import time -from common.fixtures.conn_graph_facts import fanout_graph_facts -from common.helpers.assertions import pytest_assert -from common.helpers.pfc_storm import PFCStorm -from common.plugins.loganalyzer.loganalyzer import LogAnalyzer -from files.pfcwd_helper import start_wd_on_ports -from ptf_runner import ptf_runner +from tests.common.fixtures.conn_graph_facts import fanout_graph_facts +from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.pfc_storm import PFCStorm +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer +from .files.pfcwd_helper import start_wd_on_ports +from tests.ptf_runner import ptf_runner TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates") EXPECT_PFC_WD_DETECT_RE = ".* detected PFC storm .*" diff --git a/tests/pfcwd/test_pfcwd_timer_accuracy.py b/tests/pfcwd/test_pfcwd_timer_accuracy.py index 93c65f86a85..4e1362efc8b 100644 --- a/tests/pfcwd/test_pfcwd_timer_accuracy.py +++ b/tests/pfcwd/test_pfcwd_timer_accuracy.py @@ -2,10 +2,10 @@ import pytest import time -from common.fixtures.conn_graph_facts import fanout_graph_facts -from common.helpers.assertions import pytest_assert -from common.helpers.pfc_storm import PFCStorm -from files.pfcwd_helper import start_wd_on_ports +from tests.common.fixtures.conn_graph_facts import fanout_graph_facts +from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.pfc_storm import PFCStorm +from .files.pfcwd_helper import start_wd_on_ports pytestmark = [ pytest.mark.topology('any') diff --git a/tests/pfcwd/test_pfcwd_warm_reboot.py b/tests/pfcwd/test_pfcwd_warm_reboot.py index 93a4805645e..3ea7519059f 100644 --- a/tests/pfcwd/test_pfcwd_warm_reboot.py +++ b/tests/pfcwd/test_pfcwd_warm_reboot.py @@ -5,12 +5,12 @@ import random import time -from common.fixtures.conn_graph_facts import fanout_graph_facts -from common.helpers.assertions import pytest_assert -from common.helpers.pfc_storm import PFCStorm -from common.plugins.loganalyzer.loganalyzer import LogAnalyzer -from common.reboot import reboot -from ptf_runner import ptf_runner +from tests.common.fixtures.conn_graph_facts import fanout_graph_facts +from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.pfc_storm import PFCStorm +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer +from tests.common.reboot import reboot +from tests.ptf_runner import ptf_runner TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates") EXPECT_PFC_WD_DETECT_RE = ".* detected PFC storm .*" diff --git a/tests/platform_tests/api/platform_api_test_base.py b/tests/platform_tests/api/platform_api_test_base.py index d79a85a0d2a..0550242eaa6 100644 --- a/tests/platform_tests/api/platform_api_test_base.py +++ b/tests/platform_tests/api/platform_api_test_base.py @@ -1,4 +1,4 @@ -from common.helpers.assertions import pytest_assert +from tests.common.helpers.assertions import pytest_assert class PlatformApiTestBase(object): diff --git a/tests/platform_tests/api/test_chassis.py b/tests/platform_tests/api/test_chassis.py index aa05d0a33db..60a6efa3f19 100644 --- a/tests/platform_tests/api/test_chassis.py +++ b/tests/platform_tests/api/test_chassis.py @@ -4,8 +4,8 @@ import pytest import yaml -from common.helpers.assertions import pytest_assert -from common.helpers.platform_api import chassis +from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.platform_api import chassis from platform_api_test_base import PlatformApiTestBase diff --git a/tests/platform_tests/api/test_module.py b/tests/platform_tests/api/test_module.py index c2bdb737f27..9dd87d9f101 100644 --- a/tests/platform_tests/api/test_module.py +++ b/tests/platform_tests/api/test_module.py @@ -4,8 +4,8 @@ import pytest import yaml -from common.helpers.assertions import pytest_assert -from common.helpers.platform_api import chassis, module +from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.platform_api import chassis, module logger = logging.getLogger(__name__) diff --git a/tests/platform_tests/api/test_psu.py b/tests/platform_tests/api/test_psu.py index 9a2246f4a6b..8f9ea30d446 100644 --- a/tests/platform_tests/api/test_psu.py +++ b/tests/platform_tests/api/test_psu.py @@ -4,8 +4,8 @@ import pytest import yaml -from common.helpers.assertions import pytest_assert -from common.helpers.platform_api import chassis, psu +from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.platform_api import chassis, psu from platform_api_test_base import PlatformApiTestBase diff --git a/tests/platform_tests/api/test_sfp.py b/tests/platform_tests/api/test_sfp.py index b6e0fdf6c1f..5a54b223992 100644 --- a/tests/platform_tests/api/test_sfp.py +++ b/tests/platform_tests/api/test_sfp.py @@ -4,8 +4,8 @@ import pytest -from common.helpers.assertions import pytest_assert -from common.helpers.platform_api import chassis, sfp +from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.platform_api import chassis, sfp from platform_api_test_base import PlatformApiTestBase diff --git a/tests/platform_tests/api/test_watchdog.py b/tests/platform_tests/api/test_watchdog.py index 62921487110..36dfe1afc05 100644 --- a/tests/platform_tests/api/test_watchdog.py +++ b/tests/platform_tests/api/test_watchdog.py @@ -3,7 +3,7 @@ import logging import yaml import pytest -from common.helpers.platform_api import watchdog +from tests.common.helpers.platform_api import watchdog pytestmark = [ pytest.mark.topology('any') diff --git a/tests/platform_tests/check_critical_services.py b/tests/platform_tests/check_critical_services.py index 0477fcbabdf..dc2e311aba6 100644 --- a/tests/platform_tests/check_critical_services.py +++ b/tests/platform_tests/check_critical_services.py @@ -6,7 +6,7 @@ import time import logging -from common.utilities import wait_until +from tests.common.utilities import wait_until def _all_critical_services_fully_started(dut): diff --git a/tests/platform_tests/conftest.py b/tests/platform_tests/conftest.py index dca5445b726..af1cca9b593 100644 --- a/tests/platform_tests/conftest.py +++ b/tests/platform_tests/conftest.py @@ -1,7 +1,9 @@ import pytest -from common.fixtures.advanced_reboot import get_advanced_reboot -from args.advanced_reboot_args import add_advanced_reboot_args -from args.cont_warm_reboot_args import add_cont_warm_reboot_args + +from tests.common.fixtures.advanced_reboot import get_advanced_reboot +from .args.advanced_reboot_args import add_advanced_reboot_args +from .args.cont_warm_reboot_args import add_cont_warm_reboot_args + @pytest.fixture(autouse=True, scope="module") def skip_on_simx(duthost): diff --git a/tests/platform_tests/mellanox/check_hw_mgmt_service.py b/tests/platform_tests/mellanox/check_hw_mgmt_service.py index c72ffff3639..649c432a9eb 100644 --- a/tests/platform_tests/mellanox/check_hw_mgmt_service.py +++ b/tests/platform_tests/mellanox/check_hw_mgmt_service.py @@ -4,7 +4,7 @@ import logging import re -from common.utilities import wait_until +from tests.common.utilities import wait_until def fan_speed_set_to_default(dut): diff --git a/tests/platform_tests/mellanox/check_sysfs.py b/tests/platform_tests/mellanox/check_sysfs.py index 4ab7e2cafc5..61e3be55dcf 100644 --- a/tests/platform_tests/mellanox/check_sysfs.py +++ b/tests/platform_tests/mellanox/check_sysfs.py @@ -26,7 +26,7 @@ def check_sysfs(dut): assert False, "Bad content in /var/run/hw-management/thermal/asic: %s" % repr(e) dut_hwsku = dut.facts["hwsku"] - from common.mellanox_data import SWITCH_MODELS + from tests.common.mellanox_data import SWITCH_MODELS fan_count = SWITCH_MODELS[dut_hwsku]["fans"]["number"] fan_speed = 0 @@ -212,7 +212,7 @@ def check_psu_sysfs(dut, psu_id, psu_state): assert psu_exist_content["stdout"] == "0", "CLI returns NOT PRESENT while %s contains %s" % \ (psu_exist, psu_exist_content["stdout"]) else: - from common.mellanox_data import SWITCH_MODELS + from tests.common.mellanox_data import SWITCH_MODELS dut_hwsku = dut.facts["hwsku"] hot_swappabe = SWITCH_MODELS[dut_hwsku]["psus"]["hot_swappable"] if hot_swappabe: diff --git a/tests/platform_tests/mellanox/mellanox_thermal_control_test_helper.py b/tests/platform_tests/mellanox/mellanox_thermal_control_test_helper.py index eff938be694..3ab8a39af4c 100644 --- a/tests/platform_tests/mellanox/mellanox_thermal_control_test_helper.py +++ b/tests/platform_tests/mellanox/mellanox_thermal_control_test_helper.py @@ -1,8 +1,8 @@ import os import random import logging -from ..thermal_control_test_helper import * -from common.mellanox_data import SWITCH_MODELS +from tests.platform_tests.thermal_control_test_helper import * +from tests.common.mellanox_data import SWITCH_MODELS from minimum_table import MINIMUM_TABLE NOT_AVAILABLE = 'N/A' @@ -472,7 +472,7 @@ def get_expect_led_color(self): return 'green' - + class TemperatureData: """ Data mocker of a thermal. @@ -608,7 +608,7 @@ def mock_data(self): fan_data.mock_speed(random.randint(0, 100)) self.expected_data[fan_data.name] = [ drawer_data.name, - 'N/A', # update this value later + 'N/A', # update this value later fan_data.name, '{}%'.format(fan_data.mocked_speed), drawer_data.mocked_direction, @@ -670,7 +670,7 @@ def check_result(self, actual_data): if name in actual_data: actual_fields = actual_data[name] for i, expected_field in enumerate(fields): - if name.find('psu') != -1 and i ==1: + if name.find('psu') != -1 and i ==1: continue # skip led status check for PSU because we don't mock it if expected_field != actual_fields[i]: logging.error('Check fan status for {} failed, ' \ @@ -985,7 +985,7 @@ def get_expect_cooling_level(self, air_flow_dir, temperature, trust_state): max_temp = int(range_str_list[1]) if min_temp <= temperature <= max_temp: return cooling_level - 10 - + return None def mock_min_table(self, air_flow_dir, temperature, trust_state): diff --git a/tests/platform_tests/mellanox/test_check_sfp_presence.py b/tests/platform_tests/mellanox/test_check_sfp_presence.py index 56f9fa6d51a..fcdec21a966 100644 --- a/tests/platform_tests/mellanox/test_check_sfp_presence.py +++ b/tests/platform_tests/mellanox/test_check_sfp_presence.py @@ -6,7 +6,7 @@ import json import pytest -from common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.fixtures.conn_graph_facts import conn_graph_facts pytestmark = [ pytest.mark.topology('any') diff --git a/tests/platform_tests/mellanox/test_check_sfp_using_ethtool.py b/tests/platform_tests/mellanox/test_check_sfp_using_ethtool.py index aab32126417..33a4e9e3c78 100644 --- a/tests/platform_tests/mellanox/test_check_sfp_using_ethtool.py +++ b/tests/platform_tests/mellanox/test_check_sfp_using_ethtool.py @@ -8,7 +8,7 @@ import os import json import pytest -from common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.fixtures.conn_graph_facts import conn_graph_facts from check_hw_mgmt_service import check_hw_management_service pytestmark = [ diff --git a/tests/platform_tests/mellanox/test_thermal_control.py b/tests/platform_tests/mellanox/test_thermal_control.py index 7afd95e43c8..73fe153ab18 100644 --- a/tests/platform_tests/mellanox/test_thermal_control.py +++ b/tests/platform_tests/mellanox/test_thermal_control.py @@ -3,10 +3,10 @@ import pytest import random import time -from common.mellanox_data import SWITCH_MODELS -from common.plugins.loganalyzer.loganalyzer import LogAnalyzer -from common.utilities import wait_until -from ..thermal_control_test_helper import * +from tests.common.mellanox_data import SWITCH_MODELS +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer +from tests.common.utilities import wait_until +from tests.platform_tests.thermal_control_test_helper import * from mellanox_thermal_control_test_helper import MockerHelper, AbnormalFanMocker pytestmark = [ diff --git a/tests/platform_tests/test_advanced_reboot.py b/tests/platform_tests/test_advanced_reboot.py index ec6b6a2f4de..466763752dc 100644 --- a/tests/platform_tests/test_advanced_reboot.py +++ b/tests/platform_tests/test_advanced_reboot.py @@ -1,7 +1,7 @@ import pytest -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] pytestmark = [ pytest.mark.topology('t0') diff --git a/tests/platform_tests/test_cont_warm_reboot.py b/tests/platform_tests/test_cont_warm_reboot.py index 9e3d2e314dd..3f317f415e2 100644 --- a/tests/platform_tests/test_cont_warm_reboot.py +++ b/tests/platform_tests/test_cont_warm_reboot.py @@ -12,14 +12,14 @@ import pytest from check_critical_services import check_critical_services -from common.helpers.assertions import pytest_assert -from common.utilities import wait -from common.utilities import wait_until -from common.reboot import check_reboot_cause, reboot_ctrl_dict, logging, reboot, REBOOT_TYPE_WARM -from common.platform.interface_utils import check_interface_information -from common.platform.daemon_utils import check_pmon_daemon_status -from common.platform.transceiver_utils import check_transceiver_basic -from common.plugins.sanity_check import checks +from tests.common.helpers.assertions import pytest_assert +from tests.common.utilities import wait +from tests.common.utilities import wait_until +from tests.common.reboot import check_reboot_cause, reboot_ctrl_dict, logging, reboot, REBOOT_TYPE_WARM +from tests.common.platform.interface_utils import check_interface_information +from tests.common.platform.daemon_utils import check_pmon_daemon_status +from tests.common.platform.transceiver_utils import check_transceiver_basic +from tests.common.plugins.sanity_check import checks pytestmark = [ pytest.mark.disable_loganalyzer, diff --git a/tests/platform_tests/test_link_flap.py b/tests/platform_tests/test_link_flap.py index 799280e9152..0d7de09276e 100644 --- a/tests/platform_tests/test_link_flap.py +++ b/tests/platform_tests/test_link_flap.py @@ -2,8 +2,8 @@ import pytest -from common.platform.device_utils import fanout_switch_port_lookup -from common.utilities import wait_until +from tests.common.platform.device_utils import fanout_switch_port_lookup +from tests.common.utilities import wait_until pytestmark = [ pytest.mark.topology('any') diff --git a/tests/platform_tests/test_platform_info.py b/tests/platform_tests/test_platform_info.py index 3e08a2ec650..f941db6a8b5 100644 --- a/tests/platform_tests/test_platform_info.py +++ b/tests/platform_tests/test_platform_info.py @@ -7,13 +7,11 @@ import logging import re import time -import os -import sys import pytest -from common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError -from common.utilities import wait_until +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError +from tests.common.utilities import wait_until from thermal_control_test_helper import * pytestmark = [ @@ -127,11 +125,7 @@ def check_vendor_specific_psustatus(dut, psu_status_line): @summary: Vendor specific psu status check """ if dut.facts["asic_type"] in ["mellanox"]: - current_file_dir = os.path.dirname(os.path.realpath(__file__)) - sub_folder_dir = os.path.join(current_file_dir, "mellanox") - if sub_folder_dir not in sys.path: - sys.path.append(sub_folder_dir) - from check_sysfs import check_psu_sysfs + from .mellanox.check_sysfs import check_psu_sysfs psu_line_pattern = re.compile(r"PSU\s+(\d)+\s+(OK|NOT OK|NOT PRESENT)") psu_match = psu_line_pattern.match(psu_status_line) diff --git a/tests/platform_tests/test_reboot.py b/tests/platform_tests/test_reboot.py index a5204f97600..f4be3fce930 100644 --- a/tests/platform_tests/test_reboot.py +++ b/tests/platform_tests/test_reboot.py @@ -9,20 +9,18 @@ """ import logging import re -import os import time -import sys from datetime import datetime import pytest -from common.fixtures.conn_graph_facts import conn_graph_facts -from common.utilities import wait_until -from common.reboot import * -from common.platform.interface_utils import check_interface_information -from common.platform.transceiver_utils import check_transceiver_basic -from common.platform.daemon_utils import check_pmon_daemon_status +from tests.common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.utilities import wait_until +from tests.common.reboot import * +from tests.common.platform.interface_utils import check_interface_information +from tests.common.platform.transceiver_utils import check_transceiver_basic +from tests.common.platform.daemon_utils import check_pmon_daemon_status from check_critical_services import check_critical_services @@ -93,12 +91,8 @@ def check_interfaces_and_services(dut, interfaces, reboot_type = None): if dut.facts["asic_type"] in ["mellanox"]: - current_file_dir = os.path.dirname(os.path.realpath(__file__)) - sub_folder_dir = os.path.join(current_file_dir, "mellanox") - if sub_folder_dir not in sys.path: - sys.path.append(sub_folder_dir) - from check_hw_mgmt_service import check_hw_management_service - from check_sysfs import check_sysfs + from .mellanox.check_hw_mgmt_service import check_hw_management_service + from .mellanox.check_sysfs import check_sysfs logging.info("Check the hw-management service") check_hw_management_service(dut) diff --git a/tests/platform_tests/test_reload_config.py b/tests/platform_tests/test_reload_config.py index 463530d3605..3c8085d4fd4 100644 --- a/tests/platform_tests/test_reload_config.py +++ b/tests/platform_tests/test_reload_config.py @@ -5,13 +5,11 @@ https://github.com/Azure/SONiC/blob/master/doc/pmon/sonic_platform_test_plan.md """ import logging -import os -import sys import pytest -from common.fixtures.conn_graph_facts import conn_graph_facts -from common.utilities import wait_until +from tests.common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.utilities import wait_until from check_critical_services import check_critical_services from check_transceiver_status import check_transceiver_basic from check_all_interface_info import check_interface_information @@ -44,12 +42,8 @@ def test_reload_configuration(duthost, conn_graph_facts): if asic_type in ["mellanox"]: - current_file_dir = os.path.dirname(os.path.realpath(__file__)) - sub_folder_dir = os.path.join(current_file_dir, "mellanox") - if sub_folder_dir not in sys.path: - sys.path.append(sub_folder_dir) - from check_hw_mgmt_service import check_hw_management_service - from check_sysfs import check_sysfs + from .mellanox.check_hw_mgmt_service import check_hw_management_service + from .mellanox.check_sysfs import check_sysfs logging.info("Check the hw-management service") check_hw_management_service(duthost) diff --git a/tests/platform_tests/test_sensors.py b/tests/platform_tests/test_sensors.py index a79980d2d7e..0043ea295ab 100644 --- a/tests/platform_tests/test_sensors.py +++ b/tests/platform_tests/test_sensors.py @@ -1,7 +1,7 @@ import pytest import logging -from common.helpers.assertions import pytest_assert +from tests.common.helpers.assertions import pytest_assert pytestmark = [ pytest.mark.topology('any') diff --git a/tests/platform_tests/test_sequential_restart.py b/tests/platform_tests/test_sequential_restart.py index fc0fa719c85..1801fe3c07a 100644 --- a/tests/platform_tests/test_sequential_restart.py +++ b/tests/platform_tests/test_sequential_restart.py @@ -5,13 +5,11 @@ https://github.com/Azure/SONiC/blob/master/doc/pmon/sonic_platform_test_plan.md """ import logging -import os -import sys import pytest -from common.fixtures.conn_graph_facts import conn_graph_facts -from common.utilities import wait_until +from tests.common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.utilities import wait_until from check_critical_services import check_critical_services from check_transceiver_status import check_transceiver_basic from check_all_interface_info import check_interface_information @@ -41,12 +39,8 @@ def restart_service_and_check(localhost, dut, service, interfaces): if dut.facts["asic_type"] in ["mellanox"]: - current_file_dir = os.path.dirname(os.path.realpath(__file__)) - sub_folder_dir = os.path.join(current_file_dir, "mellanox") - if sub_folder_dir not in sys.path: - sys.path.append(sub_folder_dir) - from check_hw_mgmt_service import check_hw_management_service - from check_sysfs import check_sysfs + from .mellanox.check_hw_mgmt_service import check_hw_management_service + from .mellanox.check_sysfs import check_sysfs logging.info("Check the hw-management service") check_hw_management_service(dut) diff --git a/tests/platform_tests/test_sfp.py b/tests/platform_tests/test_sfp.py index 90f4c182f1a..3819c54deeb 100644 --- a/tests/platform_tests/test_sfp.py +++ b/tests/platform_tests/test_sfp.py @@ -13,8 +13,8 @@ import pytest -from common.fixtures.conn_graph_facts import conn_graph_facts -from common.plugins.loganalyzer.loganalyzer import LogAnalyzer +from tests.common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer ans_host = None port_mapping = None diff --git a/tests/platform_tests/test_xcvr_info_in_db.py b/tests/platform_tests/test_xcvr_info_in_db.py index 4fc0c5a4d10..3cd79e4d6d2 100644 --- a/tests/platform_tests/test_xcvr_info_in_db.py +++ b/tests/platform_tests/test_xcvr_info_in_db.py @@ -9,7 +9,7 @@ import os import pytest from check_transceiver_status import check_transceiver_status -from common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.fixtures.conn_graph_facts import conn_graph_facts pytestmark = [ pytest.mark.topology('any') diff --git a/tests/platform_tests/thermal_control_test_helper.py b/tests/platform_tests/thermal_control_test_helper.py index b4078629de3..04d778e48a0 100644 --- a/tests/platform_tests/thermal_control_test_helper.py +++ b/tests/platform_tests/thermal_control_test_helper.py @@ -1,18 +1,17 @@ import logging import time import os -import sys + import pytest -from common.utilities import wait_until -from common.config_reload import config_reload +from tests.common.utilities import wait_until +from tests.common.config_reload import config_reload DUT_THERMAL_POLICY_FILE = '/usr/share/sonic/device/{}/thermal_policy.json' DUT_THERMAL_POLICY_BACKUP_FILE = '/usr/share/sonic/device/{}/thermal_policy.json.bak' BASE_DIR = os.path.dirname(os.path.realpath(__file__)) FILES_DIR = os.path.join(BASE_DIR, 'files') - class BaseMocker: """ @summary: Base class for thermal control data mocker @@ -105,13 +104,6 @@ def _create_mocker(dut, mocker_name): mocker_object = None if 'mlnx' in platform: - current_file_dir = os.path.dirname(os.path.realpath(__file__)) - if current_file_dir not in sys.path: - sys.path.append(current_file_dir) - sub_folder_dir = os.path.join(current_file_dir, "mellanox") - if sub_folder_dir not in sys.path: - sys.path.append(sub_folder_dir) - import mellanox_thermal_control_test_helper mocker_type = BaseMocker.get_mocker_type(mocker_name) if mocker_type: mocker_object = mocker_type(dut) @@ -265,7 +257,7 @@ def get_fields(line, field_ranges): def check_cli_output_with_mocker(dut, mocker_object, command, max_wait_time, key_index=0): """ Check the command line output matches the mocked data. - :param dut: DUT object representing a SONiC switch under test. + :param dut: DUT object representing a SONiC switch under test. :param mocker_object: A mocker instance. :param command: The command to be executed. E.g, 'show platform fan' :param max_wait_time: Max wait time. @@ -282,7 +274,7 @@ def check_cli_output_with_mocker(dut, mocker_object, command, max_wait_time, key for line in output["stdout_lines"][2:]: fields = get_fields(line, field_ranges) actual_data[fields[key_index]] = fields - + return mocker_object.check_result(actual_data) @@ -320,7 +312,7 @@ def restart_thermal_control_daemon(dut): kill_thermalctld_cmd = 'docker exec -i pmon bash -c \'kill {}\''.format(pid_to_kill) output = dut.command(kill_thermalctld_cmd) # kill thermalctld and wait supervisord auto reboot thermalctld assert output["rc"] == 0, "Run command '%s' failed" % kill_thermalctld_cmd - + # make sure thermalctld has restarted max_wait_time = 30 while max_wait_time > 0: @@ -330,11 +322,11 @@ def restart_thermal_control_daemon(dut): if len(output["stdout_lines"]) != 2: time.sleep(1) continue - + new_pid_0 = int(output["stdout_lines"][0].strip()) new_pid_1 = int(output["stdout_lines"][1].strip()) parent_pid = new_pid_0 if new_pid_0 < new_pid_1 else new_pid_1 - + if parent_pid == pid_to_kill: logging.info('Old thermal control daemon is still alive, waiting...') time.sleep(1) diff --git a/tests/portstat/test_portstat.py b/tests/portstat/test_portstat.py index 966e8f230a8..91efc918cb3 100644 --- a/tests/portstat/test_portstat.py +++ b/tests/portstat/test_portstat.py @@ -2,8 +2,8 @@ import logging import pytest -from common.helpers.assertions import pytest_assert -from common.utilities import wait +from tests.common.helpers.assertions import pytest_assert +from tests.common.utilities import wait logger = logging.getLogger('__name__') diff --git a/tests/qos/qos_fixtures.py b/tests/qos/qos_fixtures.py index de32535c323..39d7a91a775 100644 --- a/tests/qos/qos_fixtures.py +++ b/tests/qos/qos_fixtures.py @@ -1,5 +1,5 @@ import pytest -from common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.fixtures.conn_graph_facts import conn_graph_facts @pytest.fixture(scope = "module") diff --git a/tests/qos/qos_sai_base.py b/tests/qos/qos_sai_base.py index f4ec93006d9..b0aa0d6fcb7 100644 --- a/tests/qos/qos_sai_base.py +++ b/tests/qos/qos_sai_base.py @@ -4,8 +4,8 @@ import re import yaml -from common.mellanox_data import is_mellanox_device as isMellanoxDevice -from common.system_utils import docker +from tests.common.mellanox_data import is_mellanox_device as isMellanoxDevice +from tests.common.system_utils import docker logger = logging.getLogger(__name__) @@ -23,7 +23,7 @@ class QosSaiBase: def __runRedisCommandOrAssert(self, duthost, argv=[]): """ - Runs Redis command on DUT host. + Runs Redis command on DUT host. The method asserts if the command fails. @@ -208,7 +208,7 @@ def __assignTestPortIps(self, mgFacts): #TODO: handle the case when there are multiple vlans testVlan = next(iter(mgFacts["minigraph_vlans"])) testVlanMembers = mgFacts["minigraph_vlans"][testVlan]["members"] - + testVlanIp = None for vlan in mgFacts["minigraph_vlan_interfaces"]: if mgFacts["minigraph_vlans"][testVlan]["name"] in vlan["attachto"]: @@ -258,7 +258,7 @@ def __buildTestPorts(self, request, testPortIds, testPortIps): def runPtfTest(self, ptfhost, testCase='', testParams={}): """ Runs QoS SAI test case on PTF host - + Args: ptfhost (AnsibleHost): Packet Test Framework (PTF) testCase (str): SAI tests test case name @@ -540,7 +540,7 @@ def dutQosConfig(self, duthost, ingressLosslessProfile): def ptfPortMapFile(self, request, duthost, ptfhost): """ Prepare and copys port map file to PTF host - + Args: request (Fixture): pytest request object duthost (AnsibleHost): Device Under Test (DUT) @@ -573,7 +573,7 @@ def dutTestParams(self, duthost, testbed, ptfPortMapFile): Args: duthost (AnsibleHost): Device Under Test (DUT) - testbed (Fixture, dict): Map containing testbed information + testbed (Fixture, dict): Map containing testbed information ptfPortMapFile (Fxiture, str): filename residing on PTF host and contains port maps information Returns: @@ -598,11 +598,11 @@ def dutTestParams(self, duthost, testbed, ptfPortMapFile): def releaseAllPorts(self, ptfhost, dutTestParams, updateIptables): """ Release all paused ports prior to running QoS SAI test cases - + Args: ptfhost (AnsibleHost): Packet Test Framework (PTF) dutTestParams (Fixture, dict): DUT host test params - updateIptables (Fixture, dict): updateIptables to run prior to releasing paused ports + updateIptables (Fixture, dict): updateIptables to run prior to releasing paused ports Returns: None @@ -616,14 +616,14 @@ def releaseAllPorts(self, ptfhost, dutTestParams, updateIptables): def populateArpEntries(self, duthost, ptfhost, dutTestParams, dutConfig, releaseAllPorts): """ Update ARP entries of QoS SAI test ports - + Args: duthost (AnsibleHost): Device Under Test (DUT) ptfhost (AnsibleHost): Packet Test Framework (PTF) dutTestParams (Fixture, dict): DUT host test params dutConfig (Fixture, dict): Map of DUT config containing dut interfaces, test port IDs, test port IPs, and test ports - releaseAllPorts (Fixture, dict): releaseAllPorts to run prior to updating ARP entries + releaseAllPorts (Fixture, dict): releaseAllPorts to run prior to updating ARP entries Returns: None @@ -651,7 +651,7 @@ def populateArpEntries(self, duthost, ptfhost, dutTestParams, dutConfig, release def ingressLosslessProfile(self, request, duthost, dutConfig): """ Retreives ingress lossless profile - + Args: request (Fixture): pytest request object duthost (AnsibleHost): Device Under Test (DUT) @@ -673,7 +673,7 @@ def ingressLosslessProfile(self, request, duthost, dutConfig): def ingressLossyProfile(self, request, duthost, dutConfig): """ Retreives ingress lossy profile - + Args: request (Fixture): pytest request object duthost (AnsibleHost): Device Under Test (DUT) @@ -695,7 +695,7 @@ def ingressLossyProfile(self, request, duthost, dutConfig): def egressLosslessProfile(self, request, duthost, dutConfig): """ Retreives egress lossless profile - + Args: request (Fixture): pytest request object duthost (AnsibleHost): Device Under Test (DUT) @@ -717,7 +717,7 @@ def egressLosslessProfile(self, request, duthost, dutConfig): def losslessSchedProfile(self, duthost, dutConfig): """ Retreives lossless scheduler profile - + Args: duthost (AnsibleHost): Device Under Test (DUT) dutConfig (Fixture, dict): Map of DUT config containing dut interfaces, test port IDs, test port IPs, @@ -736,7 +736,7 @@ def losslessSchedProfile(self, duthost, dutConfig): def lossySchedProfile(self, duthost, dutConfig): """ Retreives lossy scheduler profile - + Args: duthost (AnsibleHost): Device Under Test (DUT) dutConfig (Fixture, dict): Map of DUT config containing dut interfaces, test port IDs, test port IPs, @@ -755,7 +755,7 @@ def lossySchedProfile(self, duthost, dutConfig): def updateSchedProfile(self, duthost, dutQosConfig, losslessSchedProfile, lossySchedProfile): """ Updates lossless/lossy scheduler profiles - + Args: duthost (AnsibleHost): Device Under Test (DUT) dutQosConfig (Fixture, dict): Map containing DUT host QoS configuration @@ -810,7 +810,7 @@ def updateRedisSchedParam(schedParam): def resetWatermark(self, duthost): """ Reset queue watermark - + Args: duthost (AnsibleHost): Device Under Test (DUT) diff --git a/tests/qos/test_pfc_counters.py b/tests/qos/test_pfc_counters.py index d2bd2237e1c..b969f295037 100644 --- a/tests/qos/test_pfc_counters.py +++ b/tests/qos/test_pfc_counters.py @@ -1,4 +1,4 @@ -from common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.fixtures.conn_graph_facts import conn_graph_facts from qos_fixtures import leaf_fanouts from qos_helpers import eos_to_linux_intf import os diff --git a/tests/qos/test_pfc_pause.py b/tests/qos/test_pfc_pause.py index 44145f80b31..cd1339dd258 100644 --- a/tests/qos/test_pfc_pause.py +++ b/tests/qos/test_pfc_pause.py @@ -5,7 +5,7 @@ import re import struct import random -from common.fixtures.conn_graph_facts import conn_graph_facts +from tests.common.fixtures.conn_graph_facts import conn_graph_facts from qos_fixtures import lossless_prio_dscp_map, leaf_fanouts from qos_helpers import ansible_stdout_to_str, eos_to_linux_intf, start_pause, stop_pause, setup_testbed, gen_testbed_t0, PFC_GEN_FILE, PFC_GEN_REMOTE_PATH diff --git a/tests/qos/test_qos_sai.py b/tests/qos/test_qos_sai.py index 8a34302cc28..ddbfccce501 100644 --- a/tests/qos/test_qos_sai.py +++ b/tests/qos/test_qos_sai.py @@ -20,9 +20,9 @@ import logging import pytest -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import copy_saitests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import copy_saitests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] from qos_sai_base import QosSaiBase logger = logging.getLogger(__name__) diff --git a/tests/route/test_default_route.py b/tests/route/test_default_route.py index 91c7b3226b1..55080a3e0ac 100644 --- a/tests/route/test_default_route.py +++ b/tests/route/test_default_route.py @@ -1,7 +1,7 @@ import pytest import ipaddress import logging -from common.helpers.assertions import pytest_assert +from tests.common.helpers.assertions import pytest_assert pytestmark = [ pytest.mark.topology('any'), diff --git a/tests/sflow/test_sflow.py b/tests/sflow/test_sflow.py index ceceb59731f..6f37bad5f7f 100644 --- a/tests/sflow/test_sflow.py +++ b/tests/sflow/test_sflow.py @@ -4,11 +4,11 @@ import json import re -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from ptf_runner import ptf_runner -from common import reboot -from common import config_reload -from common.utilities import wait_until +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner +from tests.common import reboot +from tests.common import config_reload +from tests.common.utilities import wait_until from netaddr import * pytestmark = [ diff --git a/tests/log_messages.py b/tests/show_techsupport/log_messages.py similarity index 100% rename from tests/log_messages.py rename to tests/show_techsupport/log_messages.py diff --git a/tests/show_techsupport/test_techsupport.py b/tests/show_techsupport/test_techsupport.py index 2e92225dc81..c0eb2a92e48 100644 --- a/tests/show_techsupport/test_techsupport.py +++ b/tests/show_techsupport/test_techsupport.py @@ -1,10 +1,10 @@ import pytest import os import pprint -from common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError +from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError import time from random import randint -from common.utilities import wait_until +from tests.common.utilities import wait_until from log_messages import * import logging logger = logging.getLogger(__name__) diff --git a/tests/snmp/conftest.py b/tests/snmp/conftest.py index 71fddb9f17c..8c92fa534cd 100644 --- a/tests/snmp/conftest.py +++ b/tests/snmp/conftest.py @@ -1,5 +1,5 @@ import pytest -from common.utilities import wait_until +from tests.common.utilities import wait_until @pytest.fixture(scope="module", autouse=True) def setup_check_snmp_ready(duthost): diff --git a/tests/telemetry/test_telemetry.py b/tests/telemetry/test_telemetry.py index da7aad8f699..fbb983a5ac3 100644 --- a/tests/telemetry/test_telemetry.py +++ b/tests/telemetry/test_telemetry.py @@ -1,5 +1,5 @@ import pytest -from common.helpers.assertions import pytest_assert +from tests.common.helpers.assertions import pytest_assert pytestmark = [ pytest.mark.topology('any') diff --git a/tests/test_features.py b/tests/test_features.py index 72fdc417d59..5a17e82240f 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -1,6 +1,6 @@ # Helper Functions import pytest -from common.helpers.assertions import pytest_assert +from tests.common.helpers.assertions import pytest_assert pytestmark = [ pytest.mark.topology('any') diff --git a/tests/test_mgmtvrf.py b/tests/test_mgmtvrf.py index 2d8ec035c50..aaed8d21b56 100644 --- a/tests/test_mgmtvrf.py +++ b/tests/test_mgmtvrf.py @@ -3,9 +3,9 @@ import re import logging -from common import reboot -from common.utilities import wait_until -from common.helpers.assertions import pytest_assert +from tests.common import reboot +from tests.common.utilities import wait_until +from tests.common.helpers.assertions import pytest_assert pytestmark = [ pytest.mark.topology("any") diff --git a/tests/test_procdockerstatsd.py b/tests/test_procdockerstatsd.py index b3786e44c00..7605cf6833a 100644 --- a/tests/test_procdockerstatsd.py +++ b/tests/test_procdockerstatsd.py @@ -1,4 +1,4 @@ -from common.helpers.assertions import pytest_assert +from tests.common.helpers.assertions import pytest_assert import pytest pytestmark = [ diff --git a/tests/test_vrf.py b/tests/test_vrf.py index 592697f7fa0..394e998ad3d 100644 --- a/tests/test_vrf.py +++ b/tests/test_vrf.py @@ -15,10 +15,10 @@ import pytest -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] -from ptf_runner import ptf_runner -from common.utilities import wait_until +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner +from tests.common.utilities import wait_until """ diff --git a/tests/test_vrf_attr.py b/tests/test_vrf_attr.py index f05373bd54d..73be23166a3 100644 --- a/tests/test_vrf_attr.py +++ b/tests/test_vrf_attr.py @@ -8,7 +8,7 @@ gen_vrf_neigh_file, partial_ptf_runner ) -from ptf_runner import ptf_runner +from tests.ptf_runner import ptf_runner pytestmark = [ pytest.mark.topology('any') diff --git a/tests/testbed_setup/conftest.py b/tests/testbed_setup/conftest.py index 71cf147fa7f..6412f9a1d9d 100644 --- a/tests/testbed_setup/conftest.py +++ b/tests/testbed_setup/conftest.py @@ -1,5 +1,5 @@ -from args.populate_fdb_args import add_populate_fdb_args -from common.fixtures.populate_fdb import populate_fdb +from .args.populate_fdb_args import add_populate_fdb_args +from tests.common.fixtures.populate_fdb import populate_fdb # FDB pytest arguments def pytest_addoption(parser): diff --git a/tests/testbed_setup/test_populate_fdb.py b/tests/testbed_setup/test_populate_fdb.py index 3df8c21818a..1f993af54fd 100644 --- a/tests/testbed_setup/test_populate_fdb.py +++ b/tests/testbed_setup/test_populate_fdb.py @@ -1,6 +1,6 @@ import pytest -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] pytestmark = [ pytest.mark.topology('any') diff --git a/tests/vlan/test_vlan.py b/tests/vlan/test_vlan.py index 2cc862adacc..a7acb802a4c 100644 --- a/tests/vlan/test_vlan.py +++ b/tests/vlan/test_vlan.py @@ -11,7 +11,7 @@ import logging import pprint -from common.errors import RunAnsibleModuleFail +from tests.common.errors import RunAnsibleModuleFail logger = logging.getLogger(__name__) diff --git a/tests/vxlan/test_vxlan_decap.py b/tests/vxlan/test_vxlan_decap.py index 1da94146b4b..fb00654c573 100644 --- a/tests/vxlan/test_vxlan_decap.py +++ b/tests/vxlan/test_vxlan_decap.py @@ -6,9 +6,9 @@ from jinja2 import Template from netaddr import IPAddress -from common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] -from common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] -from ptf_runner import ptf_runner +from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.ptf_runner import ptf_runner pytestmark = [ pytest.mark.topology('t0')