-
Notifications
You must be signed in to change notification settings - Fork 1k
Add incremental QOS config tests #4580
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
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e818872
Add incremental QOS config tests
isabelmsft 8e43c23
remove white space
isabelmsft ef42ca0
remove white space
isabelmsft 8d9aeb9
Add fixture specification to module definition
isabelmsft 03b71ce
Address PR comments
isabelmsft 3b034f2
Move verify orchagent running function to common helpers file
isabelmsft d603660
Use common function for config reload
isabelmsft 426a621
Remove outdated lines
isabelmsft 44b8904
fix outdated comment
isabelmsft c6106d1
Make whitespace consistent
isabelmsft 6003171
Minor update
isabelmsft d23d0ab
fix comment, syntax
isabelmsft 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,277 @@ | ||
| import logging | ||
| import json | ||
| import pytest | ||
|
|
||
| from tests.common.helpers.assertions import pytest_assert | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.topology('t0'), | ||
| pytest.mark.asic("mellanox") | ||
| ] | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| BACKUP_CONFIG_DB_CMD = "sudo cp /etc/sonic/config_db.json /etc/sonic/config_db.json.incremental_qos_orig" | ||
| RESTORE_CONFIG_DB_CMD = "sudo cp /etc/sonic/config_db.json.incremental_qos_orig /etc/sonic/config_db.json" | ||
| DELETE_BACKUP_CONFIG_DB_CMD = "sudo rm /etc/sonic/config_db.json.incremental_qos_orig" | ||
| INCREMENTAL_QOS_TEST_FILE_LIST = [] | ||
|
|
||
|
|
||
| def verifyOrchagentRunningOrAssert(duthost): | ||
isabelmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Verifies that orchagent is running, asserts otherwise | ||
|
|
||
| Args: | ||
| duthost: Device Under Test (DUT) | ||
| """ | ||
| result = duthost.shell(argv=["pgrep", "orchagent"]) | ||
isabelmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| orchagent_pids = result['stdout'].splitlines() | ||
| pytest_assert(len(orchagent_pids) == duthost.num_asics(), "Orchagent is not running") | ||
| for pid in orchagent_pids: | ||
| pytest_assert(int(pid) > 0, "Orchagent is not running") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def ensure_dut_readiness(duthost): | ||
| """ | ||
| Setup/teardown fixture for incremental qos config update tst | ||
|
|
||
| Args: | ||
| duthost: DUT host object | ||
| """ | ||
| logger.info("Backing up config_db.json") | ||
| duthost.shell(BACKUP_CONFIG_DB_CMD) | ||
| verifyOrchagentRunningOrAssert(duthost) | ||
|
|
||
| yield | ||
|
|
||
| verifyOrchagentRunningOrAssert(duthost) | ||
|
||
| logger.info("Restoring config_db.json") | ||
| duthost.shell(RESTORE_CONFIG_DB_CMD) | ||
isabelmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| duthost.shell(DELETE_BACKUP_CONFIG_DB_CMD) | ||
|
|
||
| for temp_file in INCREMENTAL_QOS_TEST_FILE_LIST: | ||
| duthost.shell('rm -rf {}'.format(temp_file)) | ||
isabelmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| logger.info("TEARDOWN COMPLETED") | ||
|
|
||
|
|
||
| def prepare_configdb_field(duthost, key, field, value): | ||
| """ | ||
| Prepares config db by setting BUFFER_POOL key and field to specified value. If value is empty, delete the current entry. | ||
isabelmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Args: | ||
| duthost: DUT host object | ||
| key: BUFFER_POOL table key to configure | ||
| field: BUFFER_POOL table field to configure | ||
| value: BUFFER_POOL table value to be set | ||
| """ | ||
| logger.info("Setting configdb field: {} to value: {}".format(field, value)) | ||
|
|
||
| if value: | ||
| cmd = "redis-cli -n 4 hset \"BUFFER_POOL|{}\" \"{}\" \"{}\" ".format(key, field, value) | ||
isabelmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else: | ||
| cmd = "redis-cli -n 4 del \"BUFFER_POOL|{}\" \"{}\" ".format(key, field) | ||
|
|
||
| verifyOrchagentRunningOrAssert(duthost) | ||
|
|
||
|
|
||
| def ensure_patch_application(duthost, patch_path): | ||
isabelmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Applies patch at specified path, and asserts for successful application | ||
|
|
||
|
|
||
| Args: | ||
| duthost: DUT host object | ||
| patch_path: path of JSON patch to be applied | ||
| """ | ||
| cmds = 'config apply-patch {}'.format(patch_path) | ||
|
|
||
| logger.info("Commands: {}".format(cmds)) | ||
| output = duthost.shell(cmds) | ||
isabelmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| pytest_assert("Patch applied successfully" in output['stdout'], "Please check if json file is validated") | ||
|
|
||
|
|
||
| DUT_ADD_HEADROOM_JSON_FILE='/tmp/add_headroom_pool.json' | ||
| INCREMENTAL_QOS_TEST_FILE_LIST.append(DUT_ADD_HEADROOM_JSON_FILE) | ||
| def test_set_nonexistent_headroom_pool(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("ingress_lossless_pool", "xoff", "") | ||
|
|
||
| add_headroom_pool_json = [ | ||
| { | ||
| "op": "add", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/xoff", | ||
| "value": "567" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(add_headroom_pool_json, indent=4), dest=DUT_ADD_HEADROOM_JSON_FILE) | ||
| ensure_patch_application(DUT_ADD_HEADROOM_JSON_FILE) | ||
|
|
||
|
|
||
| DUT_REPLACE_HEADROOM_JSON_FILE='/tmp/replace_headroom_pool.json' | ||
| INCREMENTAL_QOS_TEST_FILE_LIST.append(DUT_REPLACE_HEADROOM_JSON_FILE) | ||
| def test_replace_existing_headroom_pool(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("ingress_lossless_pool", "xoff", "567") | ||
|
|
||
| set_headroom_pool_json = [ | ||
| { | ||
| "op": "replace", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/xoff", | ||
| "value": "678" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(set_headroom_pool_json, indent=4), dest=DUT_REPLACE_HEADROOM_JSON_FILE) | ||
| ensure_patch_application(DUT_REPLACE_HEADROOM_JSON_FILE) | ||
|
|
||
|
|
||
| DUT_DEL_HEADROOM_JSON_FILE='/tmp/del_headroom_pool.json' | ||
| INCREMENTAL_QOS_TEST_FILE_LIST.append(DUT_DEL_HEADROOM_JSON_FILE) | ||
| def test_del_existing_headroom_pool(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("ingress_lossless_pool", "xoff", "567") | ||
|
|
||
| del_headroom_pool_json = [ | ||
| { | ||
| "op": "remove", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/xoff" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(del_headroom_pool_json, indent=4), dest=DUT_DEL_HEADROOM_JSON_FILE) | ||
| ensure_patch_application(DUT_DEL_HEADROOM_JSON_FILE) | ||
|
|
||
|
|
||
| def test_del_nonexistent_headroom_pool(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("ingress_lossless_pool", "xoff") | ||
|
|
||
| del_headroom_pool_json = [ | ||
| { | ||
| "op": "remove", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/xoff" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(del_headroom_pool_json, indent=4), dest=DUT_DEL_HEADROOM_JSON_FILE) | ||
| ensure_patch_application(DUT_DEL_HEADROOM_JSON_FILE) | ||
|
|
||
|
|
||
| DUT_ADD_POOL_JSON_FILE='/tmp/add_pool.json' | ||
| INCREMENTAL_QOS_TEST_FILE_LIST.append(DUT_ADD_POOL_JSON_FILE) | ||
| def test_set_nonexistent_pool_size_ingress(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("ingress_lossless_pool", "size", "") | ||
|
|
||
| set_pool_size_json = [ | ||
| { | ||
| "op": "add", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/size", | ||
| "value": "567" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(set_pool_size_json, indent=4), dest=DUT_ADD_POOL_JSON_FILE) | ||
| ensure_patch_application(DUT_ADD_POOL_JSON_FILE) | ||
|
|
||
|
|
||
| def test_replace_existing_pool_size_ingress(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("ingress_lossless_pool", "size", "567") | ||
|
|
||
| set_pool_size_json = [ | ||
| { | ||
| "op": "replace", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/size", | ||
| "value": "678" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(set_pool_size_json, indent=4), dest=DUT_ADD_POOL_JSON_FILE) | ||
| ensure_patch_application(DUT_ADD_POOL_JSON_FILE) | ||
|
|
||
|
|
||
| DUT_DEL_POOL_JSON_FILE='/tmp/del_pool.json' | ||
| INCREMENTAL_QOS_TEST_FILE_LIST.append(DUT_DEL_POOL_JSON_FILE) | ||
| def test_del_existing_pool_size_ingress(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("ingress_lossless_pool", "size", "567") | ||
|
|
||
| del_pool_size_json = [ | ||
| { | ||
| "op": "remove", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/size" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(del_pool_size_json, indent=4), dest=DUT_DEL_POOL_JSON_FILE) | ||
| ensure_patch_application(DUT_DEL_POOL_JSON_FILE) | ||
|
|
||
|
|
||
| def test_del_nonexistent_pool_size_ingress(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("ingress_lossless_pool", "size", "") | ||
|
|
||
| del_pool_size_json = [ | ||
| { | ||
| "op": "remove", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/size" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(del_pool_size_json, indent=4), dest=DUT_DEL_POOL_JSON_FILE) | ||
| ensure_patch_application(DUT_DEL_POOL_JSON_FILE) | ||
|
|
||
|
|
||
| def test_set_nonexistent_pool_size_egress(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("egress_lossy_pool", "size", "") | ||
|
|
||
| set_pool_size_json = [ | ||
| { | ||
| "op": "replace", | ||
| "path": "/BUFFER_POOL/egress_lossy_pool/size", | ||
isabelmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "value": "567" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(set_pool_size_json, indent=4), dest=DUT_ADD_POOL_JSON_FILE) | ||
| ensure_patch_application(DUT_ADD_POOL_JSON_FILE) | ||
|
|
||
|
|
||
| def test_replace_existing_pool_size_egress(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("egress_lossy_pool", "size", "567") | ||
|
|
||
| set_pool_size_json = [ | ||
| { | ||
| "op": "replace", | ||
| "path": "/BUFFER_POOL/egress_lossy_pool/size", | ||
| "value": "678" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(set_pool_size_json, indent=4), dest=DUT_ADD_POOL_JSON_FILE) | ||
| ensure_patch_application(DUT_ADD_POOL_JSON_FILE) | ||
|
|
||
|
|
||
| def test_del_nonexistent_pool_size_egress(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("egress_lossy_pool", "size", "") | ||
|
|
||
| del_pool_size_json = [ | ||
| { | ||
| "op": "remove", | ||
| "path": "/BUFFER_POOL/egress_lossy_pool/size" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(del_pool_size_json, indent=4), dest=DUT_DEL_POOL_JSON_FILE) | ||
| ensure_patch_application(DUT_DEL_POOL_JSON_FILE) | ||
|
|
||
|
|
||
| def test_del_existing_pool_size_egress(duthost, ensure_dut_readiness): | ||
| prepare_configdb_field("egress_lossy_pool", "size", "567") | ||
|
|
||
| del_pool_size_json = [ | ||
| { | ||
| "op": "remove", | ||
| "path": "/BUFFER_POOL/egress_lossy_pool/size" | ||
| } | ||
| ] | ||
|
|
||
| duthost.copy(content=json.dumps(del_pool_size_json, indent=4), dest=DUT_DEL_POOL_JSON_FILE) | ||
| ensure_patch_application(DUT_DEL_POOL_JSON_FILE) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.