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
4 changes: 2 additions & 2 deletions tests/acl/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
2 changes: 1 addition & 1 deletion tests/arp/conftest.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/arp/test_arpall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions tests/arp/test_neighbor_mac_noptf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -36,15 +36,15 @@ def restoreDutConfig(self, duthost):
None
"""
yield

logger.info("Reload Config DB")
config_reload(duthost, config_source='config_db', wait=120)

@pytest.fixture(params=[4, 6])
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
Expand Down
8 changes: 4 additions & 4 deletions tests/arp/test_wr_arp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
2 changes: 1 addition & 1 deletion tests/bgp/conftest.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down
4 changes: 2 additions & 2 deletions tests/bgp/test_bgp_gr_helper.py
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down
24 changes: 12 additions & 12 deletions tests/bgp/test_bgp_multipath_relax.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand All @@ -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():
Expand Down Expand Up @@ -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']:
Expand All @@ -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
Expand All @@ -96,15 +96,15 @@ 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']:
pytest_assert((str(asn) in aspath))

# 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,
Expand Down
8 changes: 4 additions & 4 deletions tests/bgp/test_bgp_speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
8 changes: 4 additions & 4 deletions tests/common/fixtures/advanced_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
2 changes: 1 addition & 1 deletion tests/common/fixtures/pfc_asym.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/common/fixtures/populate_fdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
2 changes: 1 addition & 1 deletion tests/common/helpers/pfc_storm.py
Original file line number Diff line number Diff line change
@@ -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")))
Expand Down
6 changes: 3 additions & 3 deletions tests/common/platform/ssh_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from common.errors import RunAnsibleModuleFail
from tests.common.errors import RunAnsibleModuleFail

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/common/plugins/fib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
2 changes: 1 addition & 1 deletion tests/common/plugins/sanity_check/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/common/plugins/sanity_check/recover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
4 changes: 2 additions & 2 deletions tests/common/system_utils/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
29 changes: 11 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions tests/copp/test_copp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions tests/decap/test_decap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
6 changes: 3 additions & 3 deletions tests/dhcp_relay/test_dhcp_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion tests/drop_counters/test_drop_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading