From 2f17e455be2c475cf6d29d65dfa69e20140ceb2d Mon Sep 17 00:00:00 2001 From: averevki Date: Tue, 18 Jun 2024 15:35:11 +0200 Subject: [PATCH] Add defaults/overrides interface --- testsuite/policy/authorization/auth_policy.py | 1 - testsuite/policy/authorization/sections.py | 12 ++++++++++-- testsuite/policy/rate_limit_policy.py | 13 +++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/testsuite/policy/authorization/auth_policy.py b/testsuite/policy/authorization/auth_policy.py index 33cf7a7e..a5e2adb7 100644 --- a/testsuite/policy/authorization/auth_policy.py +++ b/testsuite/policy/authorization/auth_policy.py @@ -35,7 +35,6 @@ def create_instance( "metadata": {"name": name, "namespace": openshift.project, "labels": labels}, "spec": { "targetRef": target.reference, - "rules": {}, }, } diff --git a/testsuite/policy/authorization/sections.py b/testsuite/policy/authorization/sections.py index 442a0cab..9b42f157 100644 --- a/testsuite/policy/authorization/sections.py +++ b/testsuite/policy/authorization/sections.py @@ -67,10 +67,18 @@ def section(self): """The actual dict section which will be edited""" return self.obj.auth_section.setdefault(self.section_name, {}) - def add_item(self, name: str, value: dict, **common_features): + def add_item(self, name: str, value: dict, *, defaults: bool = False, overrides: bool = False, **common_features): """Adds item to the section""" add_common_features(value, **common_features) - self.section.update({name: value}) + + if defaults: + section = self.obj.model.spec.setdefault("defaults", {}).setdefault("rules", {}) + elif overrides: + section = self.obj.model.spec.setdefault("overrides", {}).setdefault("rules", {}) + else: + section = self.obj.auth_section + + section.setdefault(self.section_name, {}).update({name: value}) @modify def clear_all(self): diff --git a/testsuite/policy/rate_limit_policy.py b/testsuite/policy/rate_limit_policy.py index 37abaa47..6c63a7cf 100644 --- a/testsuite/policy/rate_limit_policy.py +++ b/testsuite/policy/rate_limit_policy.py @@ -52,7 +52,6 @@ def create_instance(cls, openshift: OpenShiftClient, name, target: Referencable, "metadata": {"name": name, "labels": labels}, "spec": { "targetRef": target.reference, - "limits": {}, }, } @@ -66,6 +65,8 @@ def add_limit( when: Iterable[Rule] = None, counters: list[str] = None, route_selectors: Iterable[RouteSelector] = None, + defaults: bool = False, + overrides: bool = False, ): """Add another limit""" limit: dict = { @@ -77,7 +78,15 @@ def add_limit( limit["counters"] = counters if route_selectors: limit["routeSelectors"] = [asdict(rule) for rule in route_selectors] - self.model.spec.limits[name] = limit + + if defaults: + section = self.model.spec.setdefault("defaults", {}) + elif overrides: + section = self.model.spec.setdefault("overrides", {}) + else: + section = self.model.spec + + section.setdefault("limits", {})[name] = limit def wait_for_ready(self): """Wait for RLP to be enforced"""