-
Notifications
You must be signed in to change notification settings - Fork 1k
[copp tables] validate copp tables during in/cross-branch upgrades #8446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
liat-grozovik
merged 1 commit into
sonic-net:master
from
AntonHryshchuk:upgrade_copp_test
Jul 14, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| import logging | ||
| import time | ||
| import ipaddress | ||
| import json | ||
| import re | ||
| from six.moves.urllib.parse import urlparse | ||
| from tests.common.helpers.assertions import pytest_assert | ||
| from tests.common import reboot | ||
|
|
@@ -117,3 +119,51 @@ def check_reboot_cause(duthost, expected_cause): | |
| reboot_cause = get_reboot_cause(duthost) | ||
| logging.info("Checking cause from dut {} to expected {}".format(reboot_cause, expected_cause)) | ||
| return reboot_cause == expected_cause | ||
|
|
||
|
|
||
| def check_copp_config(duthost): | ||
| logging.info("Comparing CoPP configuration from copp_cfg.json to COPP_TABLE") | ||
| copp_tables = json.loads(duthost.shell("sonic-db-dump -n APPL_DB -k COPP_TABLE* -y")["stdout"]) | ||
| copp_cfg = json.loads(duthost.shell("cat /etc/sonic/copp_cfg.json")["stdout"]) | ||
| feature_status = duthost.shell("show feature status")["stdout"] | ||
| copp_tables_formatted = get_copp_table_formatted_dict(copp_tables) | ||
| copp_cfg_formatted = get_copp_cfg_formatted_dict(copp_cfg, feature_status) | ||
| pytest_assert(copp_tables_formatted == copp_cfg_formatted, | ||
| "There is a difference between CoPP config and CoPP tables. CoPP config: {}\nCoPP tables:" | ||
| " {}".format(copp_tables_formatted, copp_cfg_formatted)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The print sequence is reverted. |
||
|
|
||
|
|
||
| def get_copp_table_formatted_dict(copp_tables): | ||
| """ | ||
| Format the copp tables output to "copp_group":{"values"} only | ||
| """ | ||
| formatted_dict = {} | ||
| for queue_group, queue_group_value in copp_tables.items(): | ||
| new_queue_group = queue_group.replace("COPP_TABLE:", "") | ||
| formatted_dict.update({new_queue_group: queue_group_value["value"]}) | ||
| logging.debug("Formatted copp tables dictionary: {}".format(formatted_dict)) | ||
| return formatted_dict | ||
|
|
||
|
|
||
| def get_copp_cfg_formatted_dict(copp_cfg, feature_status): | ||
| """ | ||
| Format the copp_cfg.json output to compare with copp tables | ||
| """ | ||
| formatted_dict = {} | ||
| for trap_name, trap_value in copp_cfg["COPP_TRAP"].items(): | ||
| pattern = r"{}\s+enabled".format(trap_name) | ||
| trap_enabled = re.search(pattern, feature_status) | ||
| if trap_value.get("always_enabled", "") or trap_enabled: | ||
| trap_group = trap_value["trap_group"] | ||
| if trap_group in formatted_dict: | ||
| exist_trap_ids = formatted_dict[trap_group]["trap_ids"].split(",") | ||
| additional_trap_ids = trap_value["trap_ids"].split(",") | ||
| trap_ids = exist_trap_ids + additional_trap_ids | ||
| trap_ids.sort() | ||
| formatted_dict[trap_group].update({"trap_ids": ",".join(trap_ids)}) | ||
| else: | ||
| formatted_dict.update({trap_group: copp_cfg["COPP_GROUP"][trap_group]}) | ||
| formatted_dict[trap_group].update({"trap_ids": trap_value["trap_ids"]}) | ||
| formatted_dict.update({"default": copp_cfg["COPP_GROUP"]["default"]}) | ||
| logging.debug("Formatted copp_cfg.json dictionary: {}".format(formatted_dict)) | ||
| return formatted_dict | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a check for existence of config prior to this step?