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
2 changes: 1 addition & 1 deletion tests/acl/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import ptf.packet as packet

from common import reboot, port_toggle
from loganalyzer import LogAnalyzer, LogAnalyzerError
from common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError

logger = logging.getLogger(__name__)

Expand Down
31 changes: 31 additions & 0 deletions tests/common/plugins/ansible_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
""" This module provides few pytest-ansible fixtures overridden """

import pytest

# Here we override ansible_adhoc fixture from pytest-ansible plugin to overcome
# scope limitation issue; since we want to be able to use ansible_adhoc in module/class scope
# fixtures we have to override the scope here in global conftest.py
# Let's have it with module scope for now, so if something really breaks next test module run will have
# this fixture reevaluated
@pytest.fixture(scope='module')
def ansible_adhoc(request):
"""Return an inventory initialization method."""
plugin = request.config.pluginmanager.getplugin("ansible")

def init_host_mgr(**kwargs):
return plugin.initialize(request.config, request, **kwargs)
return init_host_mgr


# Same as for ansible_adhoc, let's have localhost fixture with session scope
# as it feels that during session run the localhost object should persist unchanged.
# Also, we have autouse=True here to force pytest to evaluate localhost fixture to overcome
# some hidden dependency between localhost and ansible_adhoc (even with default scope) (FIXME)
@pytest.fixture(scope='session', autouse=True)
def localhost(request):
"""Return a host manager representing localhost."""
# NOTE: Do not use ansible_adhoc as a dependent fixture since that will assert specific command-line parameters have
# been supplied. In the case of localhost, the parameters are provided as kwargs below.
plugin = request.config.pluginmanager.getplugin("ansible")
return plugin.initialize(request.config, request, inventory='localhost,', connection='local',
host_pattern='localhost').localhost
File renamed without changes.
26 changes: 26 additions & 0 deletions tests/common/plugins/dut_monitor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import pytest

from pytest_dut_monitor import DUTMonitorPlugin


def pytest_addoption(parser):
"""Describe plugin specified options"""
parser.addoption("--dut_monitor", action="store_true", default=False,
help="Enable DUT hardware resources monitoring")
parser.addoption("--thresholds_file", action="store", default=None, help="Path to the custom thresholds file")


def pytest_configure(config):
if config.option.dut_monitor:
thresholds = os.path.join(os.path.split(__file__)[0], "thresholds.yml")
if config.option.thresholds_file:
thresholds = config.option.thresholds_file
config.pluginmanager.register(DUTMonitorPlugin(thresholds), "dut_monitor")


def pytest_unconfigure(config):
dut_monitor = getattr(config, "dut_monitor", None)
if dut_monitor:
del config.dut_monitor
config.pluginmanager.unregister(dut_monitor)
File renamed without changes.
File renamed without changes.
29 changes: 4 additions & 25 deletions ...plugins/dut_monitor/pytest_dut_monitor.py → ...plugins/dut_monitor/pytest_dut_monitor.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@
DUT_CPU_LOG = "/tmp/cpu.log"
DUT_RAM_LOG = "/tmp/ram.log"
DUT_HDD_LOG = "/tmp/hdd.log"
THRESHOLDS = os.path.join(os.path.split(__file__)[0], "thresholds.yml")


def pytest_addoption(parser):
"""Describe plugin specified options"""
parser.addoption("--dut_monitor", action="store_true", default=False,
help="Enable DUT hardware resources monitoring")
parser.addoption("--thresholds_file", action="store", default=None, help="Path to the custom thresholds file")


def pytest_configure(config):
if config.option.dut_monitor:
config.pluginmanager.register(DUTMonitorPlugin(), "dut_monitor")
if config.option.thresholds_file:
global THRESHOLDS
THRESHOLDS = config.option.thresholds_file


def pytest_unconfigure(config):
dut_monitor = getattr(config, "dut_monitor", None)
if dut_monitor:
del config.dut_monitor
config.pluginmanager.unregister(dut_monitor)


class DUTMonitorPlugin(object):
Expand All @@ -48,6 +25,8 @@ class DUTMonitorPlugin(object):
- handlers to verify that measured CPU, RAM and HDD values during each test item execution
does not exceed defined threshold
"""
def __init__(self, thresholds):
self.thresholds = thresholds

@pytest.fixture(autouse=True, scope="session")
def dut_ssh(self, testbed, creds):
Expand All @@ -67,7 +46,7 @@ def dut_monitor(self, dut_ssh, localhost, duthost, testbed_devices):
dut_ssh.start()

# Read file with defined thresholds
with open(THRESHOLDS) as stream:
with open(self.thresholds) as stream:
general_thresholds = yaml.safe_load(stream)
dut_thresholds = general_thresholds["default"]

Expand Down Expand Up @@ -359,7 +338,7 @@ def read_yml(self, file_pointer):
measurements = yaml.safe_load("".join(fp))
if measurements is None:
return {}
# Sort json data to process logs chronologically
# Sort json data to process logs chronologically
keys = measurements.keys()
keys.sort()
key_value_pairs = [(item, measurements[item]) for item in keys]
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions tests/fib.py → tests/common/plugins/fib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import pytest
import ipaddr as ipaddress

def announce_routes(ptfip, port, family, podset_number, tor_number, tor_subnet_number,
spine_asn, leaf_asn_start, tor_asn_start,
def announce_routes(ptfip, port, family, podset_number, tor_number, tor_subnet_number,
spine_asn, leaf_asn_start, tor_asn_start,
nexthop, nexthop_v6,
tor_subnet_size = 128, max_tor_subnet_number = 16):
messages = []
Expand All @@ -29,15 +29,15 @@ def announce_routes(ptfip, port, family, podset_number, tor_number, tor_subnet_n
suffix = ( (podset * tor_number * max_tor_subnet_number * tor_subnet_size) + \
(tor * max_tor_subnet_number * tor_subnet_size) + \
(subnet * tor_subnet_size) )
octet2 = (168 + (suffix / (256 ** 2)))
octet2 = (168 + (suffix / (256 ** 2)))
octet1 = (192 + (octet2 / 256))
octet2 = (octet2 % 256)
octet3 = ((suffix / 256) % 256)
octet4 = (suffix % 256)
prefixlen_v4 = (32 - int(math.log(tor_subnet_size, 2)))

prefix = "{}.{}.{}.{}/{}".format(octet1, octet2, octet3, octet4, prefixlen_v4)
prefix_v6 = "20%02X:%02X%02X:0:%02X::/64" % (octet1, octet2, octet3, octet4)
prefix_v6 = "20%02X:%02X%02X:0:%02X::/64" % (octet1, octet2, octet3, octet4)

leaf_asn = leaf_asn_start + podset
tor_asn = tor_asn_start + tor
Expand Down
Loading