-
Notifications
You must be signed in to change notification settings - Fork 18
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
D&O merged policies / sectionName tests #608
Closed
+860
−77
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
489cc18
added section_name parameter to all policy creation functions.
martinhesko 1eb61c1
Updated RouteSelector tests to use SectionNames
martinhesko 85510e8
Expand D&O tests: sectionName/Multiple policies with one target
martinhesko dcf8668
ADD: strategy to policy
Boomatang 6962e2e
merge strategy tests for D&O
martinhesko a8f9a59
ADD: Defaults and overrides: default merge on same target
Boomatang 0852e07
ADD: Defaults and overrides: override merge on same target
Boomatang 5095ef8
Update doc string
Boomatang 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
ADD: Defaults and overrides: override merge on same target
This adds test that make use of the merge strategy on overrides that are targeting the same resource. Signed-off-by: Jim Fitzpatrick <[email protected]>
commit 0852e073e8760af44b6fcb63ec02c5b09bc2d8d7
There are no files selected for viewing
Empty file.
50 changes: 50 additions & 0 deletions
50
testsuite/tests/singlecluster/overrides/merge/same_target/conftest.py
This file contains 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,50 @@ | ||
import pytest | ||
|
||
from testsuite.gateway import MatchType, PathMatch, RouteMatch | ||
from testsuite.kuadrant.policy import CelPredicate, Strategy | ||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
LIMIT = Limit(8, "5s") | ||
OVERRIDE_LIMIT = Limit(6, "5s") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def route(route, backend): | ||
"""Add two new rules to the route""" | ||
route.remove_all_rules() | ||
route.add_rule( | ||
backend, | ||
RouteMatch(path=PathMatch(value="/get", type=MatchType.PATH_PREFIX)), | ||
) | ||
route.add_rule( | ||
backend, | ||
RouteMatch(path=PathMatch(value="/anything", type=MatchType.PATH_PREFIX)), | ||
) | ||
return route | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, route): | ||
"""Add a RateLimitPolicy targeting the first HTTPRouteRule.""" | ||
rate_limit = RateLimitPolicy.create_instance(cluster, blame("sp"), route, labels={"testRun": module_label}) | ||
basic_when = [ | ||
CelPredicate("request.path == '/get'"), | ||
] | ||
rate_limit.add_limit("basic", [LIMIT], when=basic_when) | ||
return rate_limit | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def override_merge_rate_limit(cluster, blame, module_label, route): | ||
"""Add a RateLimitPolicy targeting the first HTTPRouteRule.""" | ||
policy = RateLimitPolicy.create_instance(cluster, blame("omp"), route, labels={"testRun": module_label}) | ||
basic_when = [ | ||
CelPredicate("request.path == '/get'"), | ||
] | ||
override_when = [ | ||
CelPredicate("request.path == '/anything'"), | ||
] | ||
policy.overrides.add_limit("basic", [OVERRIDE_LIMIT], when=basic_when) | ||
policy.overrides.add_limit("override", [OVERRIDE_LIMIT], when=override_when) | ||
policy.strategy(Strategy.MERGE) | ||
return policy |
28 changes: 28 additions & 0 deletions
28
testsuite/tests/singlecluster/overrides/merge/same_target/test_ab_strategy.py
This file contains 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,28 @@ | ||
"""Test override policies aimed at the same resoure uses oldested policy.""" | ||
|
||
import pytest | ||
|
||
from .conftest import OVERRIDE_LIMIT | ||
|
||
pytestmark = [pytest.mark.kuadrant_only] | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def commit(request, route, rate_limit, override_merge_rate_limit): # pylint: disable=unused-argument | ||
"""Commits RateLimitPolicy after the HTTPRoute is created""" | ||
for policy in [rate_limit, override_merge_rate_limit]: | ||
request.addfinalizer(policy.delete) | ||
policy.commit() | ||
policy.wait_for_accepted() | ||
|
||
|
||
@pytest.mark.parametrize("rate_limit", ["gateway", "route"], indirect=True) | ||
def test_multiple_policies_merge_override_ab(client): | ||
"""Test RateLimitPolicy with merge overrides being ingored due to age""" | ||
responses = client.get_many("/get", OVERRIDE_LIMIT.limit) | ||
responses.assert_all(200) | ||
assert client.get("/get").status_code == 429 | ||
|
||
responses = client.get_many("/anything", OVERRIDE_LIMIT.limit) | ||
responses.assert_all(200) | ||
assert client.get("/anything").status_code == 429 |
28 changes: 28 additions & 0 deletions
28
testsuite/tests/singlecluster/overrides/merge/same_target/test_ba_startegy.py
This file contains 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,28 @@ | ||
"""Test defaults policy aimed at the same resoure uses oldested policy.""" | ||
|
||
import pytest | ||
|
||
from .conftest import OVERRIDE_LIMIT | ||
|
||
pytestmark = [pytest.mark.kuadrant_only] | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def commit(request, route, rate_limit, override_merge_rate_limit): # pylint: disable=unused-argument | ||
"""Commits RateLimitPolicy after the HTTPRoute is created""" | ||
for policy in [override_merge_rate_limit, rate_limit]: | ||
request.addfinalizer(policy.delete) | ||
policy.commit() | ||
policy.wait_for_accepted() | ||
|
||
|
||
@pytest.mark.parametrize("rate_limit", ["gateway", "route"], indirect=True) | ||
def test_multiple_policies_merge_default_ba(client): | ||
"""Test RateLimitPolicy with merge overrides being enforced due to age""" | ||
responses = client.get_many("/get", OVERRIDE_LIMIT.limit) | ||
responses.assert_all(200) | ||
assert client.get("/get").status_code == 429 | ||
|
||
responses = client.get_many("/anything", OVERRIDE_LIMIT.limit) | ||
responses.assert_all(200) | ||
assert client.get("/anything").status_code == 429 |
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.
@Boomatang in this case there is functionally no difference between the two related tests, I would suggest reworking this with 2 normal limits and 1 override in this policy to apply the partial override in one case, similar to how it works in
overrides/merge/test_gateway_override_merge.py