diff --git a/testsuite/policy/authorization/auth_policy.py b/testsuite/policy/authorization/auth_policy.py index bcb6ebc1..13c8b5ae 100644 --- a/testsuite/policy/authorization/auth_policy.py +++ b/testsuite/policy/authorization/auth_policy.py @@ -2,7 +2,9 @@ from typing import Dict, TYPE_CHECKING -from testsuite.utils import asdict +import openshift_client as oc + +from testsuite.utils import asdict, has_condition from testsuite.gateway import Referencable from testsuite.openshift.client import OpenShiftClient from testsuite.openshift import modify @@ -45,3 +47,13 @@ def add_rule(self, when: list["Rule"]): """Add rule for the skip of entire AuthPolicy""" self.model.spec.setdefault("when", []) self.model.spec["when"].extend([asdict(x) for x in when]) + + def wait_for_ready(self): + """Waits until AuthPolicy object reports ready status""" + with oc.timeout(90): + success, _, _ = self.self_selector().until_all( + success_func=has_condition("Enforced", "True"), + tolerate_failures=5, + ) + assert success, f"{self.kind()} did not get ready in time" + self.refresh() diff --git a/testsuite/policy/rate_limit_policy.py b/testsuite/policy/rate_limit_policy.py index e3c66f4f..919404ac 100644 --- a/testsuite/policy/rate_limit_policy.py +++ b/testsuite/policy/rate_limit_policy.py @@ -1,13 +1,12 @@ """RateLimitPolicy related objects""" from dataclasses import dataclass -from time import sleep from typing import Iterable, Literal, Optional, List import openshift_client as oc from testsuite.policy.authorization import Rule -from testsuite.utils import asdict +from testsuite.utils import asdict, has_condition from testsuite.gateway import Referencable, RouteMatch from testsuite.openshift.client import OpenShiftClient from testsuite.openshift import OpenShiftObject, modify @@ -82,11 +81,7 @@ def wait_for_ready(self): """Wait for RLP to be actually applied, conditions itself is not enough, sleep is needed""" with oc.timeout(90): success, _, _ = self.self_selector().until_all( - success_func=lambda obj: "conditions" in obj.model.status - and obj.model.status.conditions[0].status == "True", + success_func=has_condition("Enforced", "True"), tolerate_failures=5, ) assert success, f"{self.kind()} did not get ready in time" - - # https://github.com/Kuadrant/kuadrant-operator/issues/140 - sleep(90) diff --git a/testsuite/utils.py b/testsuite/utils.py index 7576d34d..e4ac72e0 100644 --- a/testsuite/utils.py +++ b/testsuite/utils.py @@ -168,3 +168,15 @@ def _asdict_recurse(obj): else: result[field.name] = deepcopy(value) return result + + +def has_condition(condition_type, value="True"): + """Returns function, that returns True if the Kubernetes object has a specific value""" + + def _check(obj): + for condition in obj.model.status.conditions: + if condition.type == condition_type and condition.status == value: + return True + return False + + return _check