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
42 changes: 42 additions & 0 deletions tests/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,45 @@
"public": []
}
KVM_PLATFORM = 'x86_64-kvm_x86_64-r0'


class CounterpollConstants:
COUNTERPOLL_SHOW = 'counterpoll show'
COUNTERPOLL_DISABLE = 'counterpoll {} disable'
COUNTERPOLL_ENABLE = 'counterpoll {} enable'
COUNTERPOLL_RESTORE = 'counterpoll {} {}'
COUNTERPOLL_INTERVAL_STR = 'counterpoll {} interval {}'
COUNTERPOLL_QUEST = 'counterpoll --help'
EXCLUDE_COUNTER_SUB_COMMAND = ['show', 'config-db', "flowcnt-trap", "tunnel"]
INTERVAL = 'interval (in ms)'
TYPE = 'type'
STATUS = 'status'
STDOUT = 'stdout'
PG_DROP = 'pg-drop'
PG_DROP_STAT_TYPE = 'PG_DROP_STAT'
QUEUE_STAT_TYPE = 'QUEUE_STAT'
QUEUE = 'queue'
PORT_STAT_TYPE = 'PORT_STAT'
PORT = 'port'
PORT_BUFFER_DROP_TYPE = 'PORT_BUFFER_DROP'
PORT_BUFFER_DROP = 'port-buffer-drop'
RIF_STAT_TYPE = 'RIF_STAT'
RIF = 'rif'
WATERMARK = 'watermark'
QUEUE_WATERMARK_STAT_TYPE = 'QUEUE_WATERMARK_STAT'
PG_WATERMARK_STAT_TYPE = 'PG_WATERMARK_STAT'
BUFFER_POOL_WATERMARK_STAT_TYPE = 'BUFFER_POOL_WATERMARK_STAT'
ACL = 'acl'
ACL_TYPE = "ACL"
COUNTERPOLL_MAPPING = {PG_DROP_STAT_TYPE: PG_DROP,
QUEUE_STAT_TYPE: QUEUE,
PORT_STAT_TYPE: PORT,
PORT_BUFFER_DROP_TYPE: PORT_BUFFER_DROP,
RIF_STAT_TYPE: RIF,
BUFFER_POOL_WATERMARK_STAT_TYPE: WATERMARK,
QUEUE_WATERMARK_STAT_TYPE: WATERMARK,
PG_WATERMARK_STAT_TYPE: WATERMARK,
ACL_TYPE: ACL}
PORT_BUFFER_DROP_INTERVAL = '10000'
COUNTERPOLL_INTERVAL = {PORT_BUFFER_DROP: 10000}
SX_SDK = 'sx_sdk'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tests.platform_tests.counterpoll.counterpoll_constants import CounterpollConstants
from tests.common.constants import CounterpollConstants


class ConterpollHelper:
Expand Down
48 changes: 48 additions & 0 deletions tests/common/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from tests.common.helpers.constants import UPSTREAM_NEIGHBOR_MAP, UPSTREAM_ALL_NEIGHBOR_MAP
from tests.common.helpers.constants import DOWNSTREAM_NEIGHBOR_MAP, DOWNSTREAM_ALL_NEIGHBOR_MAP
from tests.common.helpers.assertions import pytest_assert
from tests.common.portstat_utilities import parse_column_positions
from netaddr import valid_ipv6

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1549,3 +1550,50 @@ def cleanup_prev_images(duthost):
current_os_version = duthost.shell('sonic_installer list | grep Current | cut -f2 -d " "')['stdout']
duthost.shell("sonic_installer set-next-boot {}".format(current_os_version), module_ignore_errors=True)
duthost.shell("sonic_installer cleanup -y", module_ignore_errors=True)


def parse_rif_counters(output_lines):
"""Parse the output of "show interfaces counters rif" command
Args:
output_lines (list): The output lines of "show interfaces counters rif" command
Returns:
list: A dictionary, key is interface name, value is a dictionary of fields/values
"""

header_line = ''
separation_line = ''
separation_line_number = 0
for idx, line in enumerate(output_lines):
if line.find('----') >= 0:
header_line = output_lines[idx - 1]
separation_line = output_lines[idx]
separation_line_number = idx
break

try:
positions = parse_column_positions(separation_line)
except Exception:
logger.error('Possibly bad command output')
return {}

headers = []
for pos in positions:
header = header_line[pos[0]:pos[1]].strip().lower()
headers.append(header)

if not headers:
return {}

results = {}
for line in output_lines[separation_line_number + 1:]:
portstats = []
for pos in positions:
portstat = line[pos[0]:pos[1]].strip()
portstats.append(portstat)

intf = portstats[0]
results[intf] = {}
for idx in range(1, len(portstats)): # Skip the first column interface name
results[intf][headers[idx]] = portstats[idx].replace(',', '')

return results
48 changes: 0 additions & 48 deletions tests/ip/ip_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import random
import re
import logging
from tests.common.portstat_utilities import parse_column_positions

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -36,53 +35,6 @@ def parse_interfaces(output_lines, pc_ports_map):
return route_targets, ifaces


def parse_rif_counters(output_lines):
"""Parse the output of "show interfaces counters rif" command
Args:
output_lines (list): The output lines of "show interfaces counters rif" command
Returns:
list: A dictionary, key is interface name, value is a dictionary of fields/values
"""

header_line = ''
separation_line = ''
separation_line_number = 0
for idx, line in enumerate(output_lines):
if line.find('----') >= 0:
header_line = output_lines[idx - 1]
separation_line = output_lines[idx]
separation_line_number = idx
break

try:
positions = parse_column_positions(separation_line)
except Exception:
logger.error('Possibly bad command output')
return {}

headers = []
for pos in positions:
header = header_line[pos[0]:pos[1]].strip().lower()
headers.append(header)

if not headers:
return {}

results = {}
for line in output_lines[separation_line_number + 1:]:
portstats = []
for pos in positions:
portstat = line[pos[0]:pos[1]].strip()
portstats.append(portstat)

intf = portstats[0]
results[intf] = {}
for idx in range(1, len(portstats)): # Skip the first column interface name
results[intf][headers[idx]] = portstats[idx].replace(',', '')

return results


def random_mac():
return "02:00:00:%02x:%02x:%02x" % (random.randint(0, 255),
random.randint(0, 255),
Expand Down
3 changes: 2 additions & 1 deletion tests/ip/link_local/test_link_local_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from tests.common import utilities
from tests.common.helpers.assertions import pytest_assert
from tests.common.portstat_utilities import parse_portstat
from tests.ip.ip_util import parse_rif_counters, sum_ifaces_counts
from tests.common.utilities import parse_rif_counters
from tests.ip.ip_util import sum_ifaces_counts

pytestmark = [
pytest.mark.topology('any')
Expand Down
3 changes: 2 additions & 1 deletion tests/ip/test_ip_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from tests.common.helpers.assertions import pytest_assert
from tests.common.portstat_utilities import parse_portstat
from tests.common.helpers.dut_utils import is_mellanox_fanout
from tests.ip.ip_util import parse_interfaces, parse_rif_counters, sum_ifaces_counts, random_mac
from tests.common.utilities import parse_rif_counters
from tests.ip.ip_util import parse_interfaces, sum_ifaces_counts, random_mac


pytestmark = [
Expand Down
41 changes: 0 additions & 41 deletions tests/platform_tests/counterpoll/counterpoll_constants.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/platform_tests/counterpoll/cpu_memory_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from tests.platform_tests.counterpoll.counterpoll_constants import CounterpollConstants
from tests.platform_tests.counterpoll.counterpoll_helper import ConterpollHelper
from tests.common.constants import CounterpollConstants
from tests.common.helpers.counterpoll_helper import ConterpollHelper
from tests.common.utilities import skip_release


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import pytest

from tests.common.config_reload import config_reload
from tests.common.constants import CounterpollConstants
from tests.common.helpers.assertions import pytest_assert
from tests.common.helpers.counterpoll_helper import ConterpollHelper
from tests.common.helpers.sonic_db import SonicDbCli, SonicDbKeyNotFound
from tests.common.utilities import get_inventory_files, get_host_visible_vars
from tests.common.utilities import skip_release, wait_until
from tests.common.reboot import reboot
from .counterpoll_constants import CounterpollConstants
from .counterpoll_helper import ConterpollHelper

pytestmark = [
pytest.mark.sanity_check(skip_sanity=True),
Expand Down
4 changes: 2 additions & 2 deletions tests/platform_tests/test_cpu_memory_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from collections import namedtuple, Counter
from tests.platform_tests.counterpoll.cpu_memory_helper import restore_counter_poll # noqa: F401
from tests.platform_tests.counterpoll.cpu_memory_helper import counterpoll_type # noqa: F401
from tests.platform_tests.counterpoll.counterpoll_helper import ConterpollHelper
from tests.platform_tests.counterpoll.counterpoll_constants import CounterpollConstants
from tests.common.constants import CounterpollConstants
from tests.common.helpers.counterpoll_helper import ConterpollHelper
from tests.common.mellanox_data import is_mellanox_device
from tests.common.utilities import wait_until
from tests.common.helpers.assertions import pytest_assert
Expand Down
Loading
Loading