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 @@ -35,6 +35,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 @@ -1485,3 +1486,50 @@ def configure_packet_aging(duthost, disabled=True):
duthost.command("docker cp /tmp/packets_aging.py syncd:/")
duthost.command(f"docker exec syncd python /packets_aging.py {action}")
duthost.command("docker exec syncd rm -rf /packets_aging.py")


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
75 changes: 10 additions & 65 deletions tests/ip/test_ip_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

from collections import defaultdict
from tests.common.helpers.assertions import pytest_assert
from tests.common.portstat_utilities import parse_column_positions
from tests.common.portstat_utilities import parse_portstat
from tests.common.helpers.dut_utils import is_mellanox_fanout
from tests.common.utilities import parse_rif_counters


pytestmark = [
Expand Down Expand Up @@ -60,53 +60,6 @@ def parse_interfaces(output_lines, pc_ports_map):

return route_targets, ifaces

@staticmethod
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

@staticmethod
def random_mac():
return "02:00:00:%02x:%02x:%02x" % (random.randint(0, 255),
Expand Down Expand Up @@ -173,8 +126,7 @@ def common_param(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname, tbin

# Some platforms do not support rif counter
try:
rif_counter_out = TestIPPacket.parse_rif_counters(
duthost.command("show interfaces counters rif")["stdout_lines"])
rif_counter_out = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"])
rif_iface = list(rif_counter_out.keys())[0]
rif_support = False if rif_counter_out[rif_iface]['rx_err'] == 'N/A' else True
except Exception as e:
Expand Down Expand Up @@ -239,8 +191,7 @@ def test_forward_ip_packet_with_0x0000_chksum(self, duthosts, enum_rand_one_per_

portstat_out = parse_portstat(duthost.command("portstat")["stdout_lines"])
if rif_support:
rif_counter_out = TestIPPacket.parse_rif_counters(
duthost.command("show interfaces counters rif")["stdout_lines"])
rif_counter_out = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"])

# In different platforms, IP packets with specific checksum will be dropped in different layer
# We use both layer 2 counter and layer 3 counter to check where packet are dropped
Expand Down Expand Up @@ -312,8 +263,7 @@ def test_forward_ip_packet_with_0xffff_chksum_tolerant(self, duthosts, enum_rand

portstat_out = parse_portstat(duthost.command("portstat")["stdout_lines"])
if rif_support:
rif_counter_out = TestIPPacket.parse_rif_counters(
duthost.command("show interfaces counters rif")["stdout_lines"])
rif_counter_out = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"])

# In different platforms, IP packets with specific checksum will be dropped in different layer
# We use both layer 2 counter and layer 3 counter to check where packet are dropped
Expand Down Expand Up @@ -389,8 +339,7 @@ def test_forward_ip_packet_with_0xffff_chksum_drop(self, duthosts, localhost,

portstat_out = parse_portstat(duthost.command("portstat")["stdout_lines"])
if rif_support:
rif_counter_out = TestIPPacket.parse_rif_counters(
duthost.command("show interfaces counters rif")["stdout_lines"])
rif_counter_out = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"])

# In different platforms, IP packets with specific checksum will be dropped in different layer
# We use both layer 2 counter and layer 3 counter to check where packet are dropped
Expand Down Expand Up @@ -471,8 +420,7 @@ def test_forward_ip_packet_recomputed_0xffff_chksum(self, duthosts, enum_rand_on

portstat_out = parse_portstat(duthost.command("portstat")["stdout_lines"])
if rif_support:
rif_counter_out = TestIPPacket.parse_rif_counters(
duthost.command("show interfaces counters rif")["stdout_lines"])
rif_counter_out = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"])

# In different platforms, IP packets with specific checksum will be dropped in different layer
# We use both layer 2 counter and layer 3 counter to check where packet are dropped
Expand Down Expand Up @@ -543,8 +491,7 @@ def test_forward_ip_packet_recomputed_0x0000_chksum(self, duthosts, enum_rand_on

portstat_out = parse_portstat(duthost.command("portstat")["stdout_lines"])
if rif_support:
rif_counter_out = TestIPPacket.parse_rif_counters(
duthost.command("show interfaces counters rif")["stdout_lines"])
rif_counter_out = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"])

# In different platforms, IP packets with specific checksum will be dropped in different layer
# We use both layer 2 counter and layer 3 counter to check where packet are dropped
Expand Down Expand Up @@ -608,8 +555,7 @@ def test_forward_normal_ip_packet(self, duthosts, enum_rand_one_per_hwsku_fronte

portstat_out = parse_portstat(duthost.command("portstat")["stdout_lines"])
if rif_support:
rif_counter_out = TestIPPacket.parse_rif_counters(
duthost.command("show interfaces counters rif")["stdout_lines"])
rif_counter_out = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"])

# In different platforms, IP packets with specific checksum will be dropped in different layer
# We use both layer 2 counter and layer 3 counter to check where packet are dropped
Expand Down Expand Up @@ -665,8 +611,7 @@ def test_drop_ip_packet_with_wrong_0xffff_chksum(self, duthosts, enum_rand_one_p

portstat_out = parse_portstat(duthost.command("portstat")["stdout_lines"])
if rif_support:
rif_counter_out = TestIPPacket.parse_rif_counters(
duthost.command("show interfaces counters rif")["stdout_lines"])
rif_counter_out = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"])

# In different platforms, IP packets with specific checksum will be dropped in different layer
# We use both layer 2 counter and layer 3 counter to check where packet are dropped
Expand Down Expand Up @@ -722,7 +667,7 @@ def test_drop_l3_ip_packet_non_dut_mac(self, duthosts, enum_rand_one_per_hwsku_f

portstat_out = parse_portstat(duthost.command("portstat")["stdout_lines"])
if rif_support:
rif_counter_out = TestIPPacket.parse_rif_counters(
rif_counter_out = parse_rif_counters(
duthost.command("show interfaces counters rif")["stdout_lines"])

# rx_ok counter to increase to show packets are being received correctly at layer 2
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