Skip to content

Commit 55c826c

Browse files
roman_savchukillia-kotvitskyi
authored andcommitted
Implement new TC for SNMP ifErrors/ifDiscard (sonic-net#14916)
* Implement new TC for SNMP ifErrors/ifDiscard * move parse_rif_counters to a common utilities the motivation is to avoid cross-feature dependency * align test_snmp_interfaces_error_discard with recent updates --------- Co-authored-by: Illia Kotvitskyi <ikotvitskyi@nvidia.com> Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
1 parent d826f22 commit 55c826c

File tree

11 files changed

+280
-98
lines changed

11 files changed

+280
-98
lines changed

tests/common/constants.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,45 @@
1717
"public": []
1818
}
1919
KVM_PLATFORM = 'x86_64-kvm_x86_64-r0'
20+
21+
22+
class CounterpollConstants:
23+
COUNTERPOLL_SHOW = 'counterpoll show'
24+
COUNTERPOLL_DISABLE = 'counterpoll {} disable'
25+
COUNTERPOLL_ENABLE = 'counterpoll {} enable'
26+
COUNTERPOLL_RESTORE = 'counterpoll {} {}'
27+
COUNTERPOLL_INTERVAL_STR = 'counterpoll {} interval {}'
28+
COUNTERPOLL_QUEST = 'counterpoll --help'
29+
EXCLUDE_COUNTER_SUB_COMMAND = ['show', 'config-db', "flowcnt-trap", "tunnel"]
30+
INTERVAL = 'interval (in ms)'
31+
TYPE = 'type'
32+
STATUS = 'status'
33+
STDOUT = 'stdout'
34+
PG_DROP = 'pg-drop'
35+
PG_DROP_STAT_TYPE = 'PG_DROP_STAT'
36+
QUEUE_STAT_TYPE = 'QUEUE_STAT'
37+
QUEUE = 'queue'
38+
PORT_STAT_TYPE = 'PORT_STAT'
39+
PORT = 'port'
40+
PORT_BUFFER_DROP_TYPE = 'PORT_BUFFER_DROP'
41+
PORT_BUFFER_DROP = 'port-buffer-drop'
42+
RIF_STAT_TYPE = 'RIF_STAT'
43+
RIF = 'rif'
44+
WATERMARK = 'watermark'
45+
QUEUE_WATERMARK_STAT_TYPE = 'QUEUE_WATERMARK_STAT'
46+
PG_WATERMARK_STAT_TYPE = 'PG_WATERMARK_STAT'
47+
BUFFER_POOL_WATERMARK_STAT_TYPE = 'BUFFER_POOL_WATERMARK_STAT'
48+
ACL = 'acl'
49+
ACL_TYPE = "ACL"
50+
COUNTERPOLL_MAPPING = {PG_DROP_STAT_TYPE: PG_DROP,
51+
QUEUE_STAT_TYPE: QUEUE,
52+
PORT_STAT_TYPE: PORT,
53+
PORT_BUFFER_DROP_TYPE: PORT_BUFFER_DROP,
54+
RIF_STAT_TYPE: RIF,
55+
BUFFER_POOL_WATERMARK_STAT_TYPE: WATERMARK,
56+
QUEUE_WATERMARK_STAT_TYPE: WATERMARK,
57+
PG_WATERMARK_STAT_TYPE: WATERMARK,
58+
ACL_TYPE: ACL}
59+
PORT_BUFFER_DROP_INTERVAL = '10000'
60+
COUNTERPOLL_INTERVAL = {PORT_BUFFER_DROP: 10000}
61+
SX_SDK = 'sx_sdk'

tests/platform_tests/counterpoll/counterpoll_helper.py renamed to tests/common/helpers/counterpoll_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tests.platform_tests.counterpoll.counterpoll_constants import CounterpollConstants
1+
from tests.common.constants import CounterpollConstants
22

33

44
class ConterpollHelper:

tests/common/utilities.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from tests.common.helpers.constants import UPSTREAM_NEIGHBOR_MAP, UPSTREAM_ALL_NEIGHBOR_MAP
3737
from tests.common.helpers.constants import DOWNSTREAM_NEIGHBOR_MAP, DOWNSTREAM_ALL_NEIGHBOR_MAP
3838
from tests.common.helpers.assertions import pytest_assert
39+
from tests.common.portstat_utilities import parse_column_positions
3940
from netaddr import valid_ipv6
4041

4142
logger = logging.getLogger(__name__)
@@ -1550,3 +1551,50 @@ def cleanup_prev_images(duthost):
15501551
current_os_version = duthost.shell('sonic_installer list | grep Current | cut -f2 -d " "')['stdout']
15511552
duthost.shell("sonic_installer set-next-boot {}".format(current_os_version), module_ignore_errors=True)
15521553
duthost.shell("sonic_installer cleanup -y", module_ignore_errors=True)
1554+
1555+
1556+
def parse_rif_counters(output_lines):
1557+
"""Parse the output of "show interfaces counters rif" command
1558+
Args:
1559+
output_lines (list): The output lines of "show interfaces counters rif" command
1560+
Returns:
1561+
list: A dictionary, key is interface name, value is a dictionary of fields/values
1562+
"""
1563+
1564+
header_line = ''
1565+
separation_line = ''
1566+
separation_line_number = 0
1567+
for idx, line in enumerate(output_lines):
1568+
if line.find('----') >= 0:
1569+
header_line = output_lines[idx - 1]
1570+
separation_line = output_lines[idx]
1571+
separation_line_number = idx
1572+
break
1573+
1574+
try:
1575+
positions = parse_column_positions(separation_line)
1576+
except Exception:
1577+
logger.error('Possibly bad command output')
1578+
return {}
1579+
1580+
headers = []
1581+
for pos in positions:
1582+
header = header_line[pos[0]:pos[1]].strip().lower()
1583+
headers.append(header)
1584+
1585+
if not headers:
1586+
return {}
1587+
1588+
results = {}
1589+
for line in output_lines[separation_line_number + 1:]:
1590+
portstats = []
1591+
for pos in positions:
1592+
portstat = line[pos[0]:pos[1]].strip()
1593+
portstats.append(portstat)
1594+
1595+
intf = portstats[0]
1596+
results[intf] = {}
1597+
for idx in range(1, len(portstats)): # Skip the first column interface name
1598+
results[intf][headers[idx]] = portstats[idx].replace(',', '')
1599+
1600+
return results

tests/ip/ip_util.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import random
22
import re
33
import logging
4-
from tests.common.portstat_utilities import parse_column_positions
54

65
logger = logging.getLogger(__name__)
76

@@ -36,53 +35,6 @@ def parse_interfaces(output_lines, pc_ports_map):
3635
return route_targets, ifaces
3736

3837

39-
def parse_rif_counters(output_lines):
40-
"""Parse the output of "show interfaces counters rif" command
41-
Args:
42-
output_lines (list): The output lines of "show interfaces counters rif" command
43-
Returns:
44-
list: A dictionary, key is interface name, value is a dictionary of fields/values
45-
"""
46-
47-
header_line = ''
48-
separation_line = ''
49-
separation_line_number = 0
50-
for idx, line in enumerate(output_lines):
51-
if line.find('----') >= 0:
52-
header_line = output_lines[idx - 1]
53-
separation_line = output_lines[idx]
54-
separation_line_number = idx
55-
break
56-
57-
try:
58-
positions = parse_column_positions(separation_line)
59-
except Exception:
60-
logger.error('Possibly bad command output')
61-
return {}
62-
63-
headers = []
64-
for pos in positions:
65-
header = header_line[pos[0]:pos[1]].strip().lower()
66-
headers.append(header)
67-
68-
if not headers:
69-
return {}
70-
71-
results = {}
72-
for line in output_lines[separation_line_number + 1:]:
73-
portstats = []
74-
for pos in positions:
75-
portstat = line[pos[0]:pos[1]].strip()
76-
portstats.append(portstat)
77-
78-
intf = portstats[0]
79-
results[intf] = {}
80-
for idx in range(1, len(portstats)): # Skip the first column interface name
81-
results[intf][headers[idx]] = portstats[idx].replace(',', '')
82-
83-
return results
84-
85-
8638
def random_mac():
8739
return "02:00:00:%02x:%02x:%02x" % (random.randint(0, 255),
8840
random.randint(0, 255),

tests/ip/link_local/test_link_local_ip.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from tests.common import utilities
1414
from tests.common.helpers.assertions import pytest_assert
1515
from tests.common.portstat_utilities import parse_portstat
16-
from tests.ip.ip_util import parse_rif_counters, sum_ifaces_counts
16+
from tests.common.utilities import parse_rif_counters
17+
from tests.ip.ip_util import sum_ifaces_counts
1718

1819
pytestmark = [
1920
pytest.mark.topology('any')

tests/ip/test_ip_packet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from tests.common.helpers.assertions import pytest_assert
1111
from tests.common.portstat_utilities import parse_portstat
1212
from tests.common.helpers.dut_utils import is_mellanox_fanout
13-
from tests.ip.ip_util import parse_interfaces, parse_rif_counters, sum_ifaces_counts, random_mac
13+
from tests.common.utilities import parse_rif_counters
14+
from tests.ip.ip_util import parse_interfaces, sum_ifaces_counts, random_mac
1415

1516

1617
pytestmark = [

tests/platform_tests/counterpoll/counterpoll_constants.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

tests/platform_tests/counterpoll/cpu_memory_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

3-
from tests.platform_tests.counterpoll.counterpoll_constants import CounterpollConstants
4-
from tests.platform_tests.counterpoll.counterpoll_helper import ConterpollHelper
3+
from tests.common.constants import CounterpollConstants
4+
from tests.common.helpers.counterpoll_helper import ConterpollHelper
55
from tests.common.utilities import skip_release
66

77

tests/platform_tests/counterpoll/test_counterpoll_watermark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import pytest
1010

1111
from tests.common.config_reload import config_reload
12+
from tests.common.constants import CounterpollConstants
1213
from tests.common.helpers.assertions import pytest_assert
14+
from tests.common.helpers.counterpoll_helper import ConterpollHelper
1315
from tests.common.helpers.sonic_db import SonicDbCli, SonicDbKeyNotFound
1416
from tests.common.utilities import get_inventory_files, get_host_visible_vars
1517
from tests.common.utilities import skip_release, wait_until
1618
from tests.common.reboot import reboot
17-
from .counterpoll_constants import CounterpollConstants
18-
from .counterpoll_helper import ConterpollHelper
1919

2020
pytestmark = [
2121
pytest.mark.sanity_check(skip_sanity=True),

tests/platform_tests/test_cpu_memory_usage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from collections import namedtuple, Counter
55
from tests.platform_tests.counterpoll.cpu_memory_helper import restore_counter_poll # noqa: F401
66
from tests.platform_tests.counterpoll.cpu_memory_helper import counterpoll_type # noqa: F401
7-
from tests.platform_tests.counterpoll.counterpoll_helper import ConterpollHelper
8-
from tests.platform_tests.counterpoll.counterpoll_constants import CounterpollConstants
7+
from tests.common.constants import CounterpollConstants
8+
from tests.common.helpers.counterpoll_helper import ConterpollHelper
99
from tests.common.mellanox_data import is_mellanox_device
1010
from tests.common.utilities import wait_until
1111
from tests.common.helpers.assertions import pytest_assert

0 commit comments

Comments
 (0)