Skip to content

Commit 00e1a51

Browse files
[copp tables] validate copp tables during in/cross-branch upgrades (#8446)
- What is the motivation for this PR? Add validation of copp tables after improvement of fast-reboot - How did you do it? Added validation of copp tables after upgrade - How did you verify/test it? executed test test_upgrade_path with base_image=201911, target_image=202205, upgrade_type=fast Signed-off-by: AntonHryshchuk <[email protected]>
1 parent 24bc9b0 commit 00e1a51

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

tests/upgrade_path/test_upgrade_path.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from tests.common import reboot
55
from tests.common.reboot import get_reboot_cause
66
from tests.common.reboot import REBOOT_TYPE_COLD
7-
from tests.upgrade_path.upgrade_helpers import check_services, install_sonic, check_sonic_version, get_reboot_command
7+
from tests.upgrade_path.upgrade_helpers import check_services, install_sonic, check_sonic_version,\
8+
get_reboot_command, check_copp_config
89
from tests.upgrade_path.upgrade_helpers import restore_image # noqa F401
910
from tests.common.fixtures.advanced_reboot import get_advanced_reboot # noqa F401
1011
from tests.platform_tests.verify_dut_health import verify_dut_health # noqa F401
@@ -80,6 +81,7 @@ def test_upgrade_path(localhost, duthosts, ptfhost, rand_one_dut_hostname,
8081
pytest_assert(reboot_cause == upgrade_type,
8182
"Reboot cause {} did not match the trigger - {}".format(reboot_cause, upgrade_type))
8283
check_services(duthost)
84+
check_copp_config(duthost)
8385

8486

8587
@pytest.mark.device_type('vs')

tests/upgrade_path/upgrade_helpers.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import logging
33
import time
44
import ipaddress
5+
import json
6+
import re
57
from six.moves.urllib.parse import urlparse
68
from tests.common.helpers.assertions import pytest_assert
79
from tests.common import reboot
@@ -117,3 +119,51 @@ def check_reboot_cause(duthost, expected_cause):
117119
reboot_cause = get_reboot_cause(duthost)
118120
logging.info("Checking cause from dut {} to expected {}".format(reboot_cause, expected_cause))
119121
return reboot_cause == expected_cause
122+
123+
124+
def check_copp_config(duthost):
125+
logging.info("Comparing CoPP configuration from copp_cfg.json to COPP_TABLE")
126+
copp_tables = json.loads(duthost.shell("sonic-db-dump -n APPL_DB -k COPP_TABLE* -y")["stdout"])
127+
copp_cfg = json.loads(duthost.shell("cat /etc/sonic/copp_cfg.json")["stdout"])
128+
feature_status = duthost.shell("show feature status")["stdout"]
129+
copp_tables_formatted = get_copp_table_formatted_dict(copp_tables)
130+
copp_cfg_formatted = get_copp_cfg_formatted_dict(copp_cfg, feature_status)
131+
pytest_assert(copp_tables_formatted == copp_cfg_formatted,
132+
"There is a difference between CoPP config and CoPP tables. CoPP config: {}\nCoPP tables:"
133+
" {}".format(copp_tables_formatted, copp_cfg_formatted))
134+
135+
136+
def get_copp_table_formatted_dict(copp_tables):
137+
"""
138+
Format the copp tables output to "copp_group":{"values"} only
139+
"""
140+
formatted_dict = {}
141+
for queue_group, queue_group_value in copp_tables.items():
142+
new_queue_group = queue_group.replace("COPP_TABLE:", "")
143+
formatted_dict.update({new_queue_group: queue_group_value["value"]})
144+
logging.debug("Formatted copp tables dictionary: {}".format(formatted_dict))
145+
return formatted_dict
146+
147+
148+
def get_copp_cfg_formatted_dict(copp_cfg, feature_status):
149+
"""
150+
Format the copp_cfg.json output to compare with copp tables
151+
"""
152+
formatted_dict = {}
153+
for trap_name, trap_value in copp_cfg["COPP_TRAP"].items():
154+
pattern = r"{}\s+enabled".format(trap_name)
155+
trap_enabled = re.search(pattern, feature_status)
156+
if trap_value.get("always_enabled", "") or trap_enabled:
157+
trap_group = trap_value["trap_group"]
158+
if trap_group in formatted_dict:
159+
exist_trap_ids = formatted_dict[trap_group]["trap_ids"].split(",")
160+
additional_trap_ids = trap_value["trap_ids"].split(",")
161+
trap_ids = exist_trap_ids + additional_trap_ids
162+
trap_ids.sort()
163+
formatted_dict[trap_group].update({"trap_ids": ",".join(trap_ids)})
164+
else:
165+
formatted_dict.update({trap_group: copp_cfg["COPP_GROUP"][trap_group]})
166+
formatted_dict[trap_group].update({"trap_ids": trap_value["trap_ids"]})
167+
formatted_dict.update({"default": copp_cfg["COPP_GROUP"]["default"]})
168+
logging.debug("Formatted copp_cfg.json dictionary: {}".format(formatted_dict))
169+
return formatted_dict

0 commit comments

Comments
 (0)