-
Notifications
You must be signed in to change notification settings - Fork 819
[GCU] Add Sample Unit Test for RDMA Headroom Pool Size Tuning #2692
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
6 commits
Select commit
Hold shift + click to select a range
752437b
add rdma gcu unit test
isabelmsft f5bd216
fix comment
isabelmsft 11c84b2
clean unused code
isabelmsft fa9f83f
clean format
isabelmsft 240c269
extend to mock patchapplier, in place of changeapplier
isabelmsft 369845a
replace tabs with spaces
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
35 changes: 35 additions & 0 deletions
35
tests/generic_config_updater/files/feature_patch_application_test_failure.json
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,35 @@ | ||
| { | ||
| "RDMA_SHARED_POOL_SIZE_CHANGE__FAILURE": { | ||
| "desc": "For RDMA shared pool size tuning- adjust both shared pool and headroom pool", | ||
| "current_config": { | ||
| "BUFFER_POOL": { | ||
| "ingress_lossless_pool": { | ||
| "xoff": "4194112", | ||
| "type": "ingress", | ||
| "mode": "dynamic", | ||
| "size": "10875072" | ||
| }, | ||
| "egress_lossless_pool": { | ||
| "type": "egress", | ||
| "mode": "static", | ||
| "size": "15982720" | ||
| }, | ||
| "egress_lossy_pool": { | ||
| "type": "egress", | ||
| "mode": "dynamic", | ||
| "size": "9243812" | ||
| } | ||
| } | ||
| }, | ||
| "patch": [ | ||
| { | ||
| "op": "replace", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/xoff", | ||
| "value": "invalid_xoff" | ||
| } | ||
| ], | ||
| "expected_error_substrings": [ | ||
| "Given patch will produce invalid config" | ||
| ] | ||
| } | ||
| } | ||
62 changes: 62 additions & 0 deletions
62
tests/generic_config_updater/files/feature_patch_application_test_success.json
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,62 @@ | ||
| { | ||
| "RDMA_SHARED_POOL_SIZE_CHANGE__SUCCESS": { | ||
| "desc": "For RDMA shared pool size tuning- adjust both shared pool and headroom pool", | ||
| "current_config": { | ||
| "BUFFER_POOL": { | ||
| "ingress_lossless_pool": { | ||
| "xoff": "4194112", | ||
| "type": "ingress", | ||
| "mode": "dynamic", | ||
| "size": "10875072" | ||
| }, | ||
| "egress_lossless_pool": { | ||
| "type": "egress", | ||
| "mode": "static", | ||
| "size": "15982720" | ||
| }, | ||
| "egress_lossy_pool": { | ||
| "type": "egress", | ||
| "mode": "dynamic", | ||
| "size": "9243812" | ||
| } | ||
| } | ||
| }, | ||
| "patch": [ | ||
| { | ||
| "op": "replace", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/xoff", | ||
| "value": "2155712" | ||
| }, | ||
| { | ||
| "op": "replace", | ||
| "path": "/BUFFER_POOL/ingress_lossless_pool/size", | ||
| "value": "12913472" | ||
| }, | ||
| { | ||
| "op": "replace", | ||
| "path": "/BUFFER_POOL/egress_lossy_pool/size", | ||
| "value": "5200000" | ||
| } | ||
| ], | ||
| "expected_config": { | ||
| "BUFFER_POOL": { | ||
| "ingress_lossless_pool": { | ||
| "xoff": "2155712", | ||
| "type": "ingress", | ||
| "mode": "dynamic", | ||
| "size": "12913472" | ||
| }, | ||
| "egress_lossless_pool": { | ||
| "type": "egress", | ||
| "mode": "static", | ||
| "size": "15982720" | ||
| }, | ||
| "egress_lossy_pool": { | ||
| "type": "egress", | ||
| "mode": "dynamic", | ||
| "size": "5200000" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
95 changes: 95 additions & 0 deletions
95
tests/generic_config_updater/gcu_feature_patch_application_test.py
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,95 @@ | ||
| import jsonpatch | ||
| import unittest | ||
| from unittest.mock import MagicMock, Mock | ||
|
|
||
| import generic_config_updater.patch_sorter as ps | ||
| from .gutest_helpers import Files | ||
| from generic_config_updater.gu_common import ConfigWrapper, PatchWrapper | ||
|
|
||
|
|
||
| class TestFeaturePatchApplication(unittest.TestCase): | ||
| def setUp(self): | ||
| self.config_wrapper = ConfigWrapper() | ||
|
|
||
| def test_feature_patch_application_success(self): | ||
| # Format of the JSON file containing the test-cases: | ||
| # | ||
| # { | ||
| # "<unique_name_for_the_test>":{ | ||
| # "desc":"<brief explanation of the test case>", | ||
| # "current_config":<the running config to be modified>, | ||
| # "patch":<the JsonPatch to apply>, | ||
| # "expected_config":<the config after jsonpatch modification> | ||
| # }, | ||
| # . | ||
| # . | ||
| # . | ||
| # } | ||
| data = Files.FEATURE_PATCH_APPLICATION_TEST_SUCCESS | ||
|
|
||
| for test_case_name in data: | ||
| with self.subTest(name=test_case_name): | ||
| self.run_single_success_case(data[test_case_name]) | ||
|
|
||
| def test_feature_patch_application_failure(self): | ||
| # Fromat of the JSON file containing the test-cases: | ||
| # | ||
| # { | ||
| # "<unique_name_for_the_test>":{ | ||
| # "desc":"<brief explanation of the test case>", | ||
| # "current_config":<the running config to be modified>, | ||
| # "patch":<the JsonPatch to apply>, | ||
| # "expected_error_substrings":<error substrings expected in failure output> | ||
| # }, | ||
| # . | ||
| # . | ||
| # . | ||
| # } | ||
| data = Files.FEATURE_PATCH_APPLICATION_TEST_FAILURE | ||
|
|
||
| for test_case_name in data: | ||
| with self.subTest(name=test_case_name): | ||
| self.run_single_failure_case(data[test_case_name]) | ||
|
|
||
| def create_strict_patch_sorter(self, config): | ||
| config_wrapper = self.config_wrapper | ||
| config_wrapper.get_config_db_as_json = MagicMock(return_value=config) | ||
| patch_wrapper = PatchWrapper(config_wrapper) | ||
| return ps.StrictPatchSorter(config_wrapper, patch_wrapper) | ||
|
|
||
| def run_single_success_case(self, data): | ||
| current_config = data["current_config"] | ||
| expected_config = data["expected_config"] | ||
| patch = jsonpatch.JsonPatch(data["patch"]) | ||
| sorter = self.create_strict_patch_sorter(current_config) | ||
| actual_changes = sorter.sort(patch) | ||
| target_config = patch.apply(current_config) | ||
| simulated_config = current_config | ||
|
|
||
| for change in actual_changes: | ||
| simulated_config = change.apply(simulated_config) | ||
| is_valid, error = self.config_wrapper.validate_config_db_config(simulated_config) | ||
| self.assertTrue(is_valid, f"Change will produce invalid config. Error: {error}") | ||
|
|
||
| self.assertEqual(target_config, simulated_config) | ||
| self.assertEqual(simulated_config, expected_config) | ||
|
|
||
| def run_single_failure_case(self, data): | ||
| current_config = data["current_config"] | ||
| patch = jsonpatch.JsonPatch(data["patch"]) | ||
| expected_error_substrings = data["expected_error_substrings"] | ||
|
|
||
| try: | ||
| sorter = self.create_strict_patch_sorter(current_config) | ||
| sorter.sort(patch) | ||
| self.fail("An exception was supposed to be thrown") | ||
| except Exception as ex: | ||
| notfound_substrings = [] | ||
| error = str(ex) | ||
|
|
||
| for substring in expected_error_substrings: | ||
| if substring not in error: | ||
| notfound_substrings.append(substring) | ||
|
|
||
| if notfound_substrings: | ||
| self.fail(f"Did not find the expected substrings {notfound_substrings} in the error: '{error}'") |
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.
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.
You mixed tabs and spaces. Could you stick with 4-space indentation? #Closed