From 24cebd796464c12a238d16cec1e72f4fba23ac0d Mon Sep 17 00:00:00 2001 From: phala Date: Mon, 17 Jun 2024 13:55:41 +0200 Subject: [PATCH] Use wait_until instead of until_all() - Timeout wont throw exception, but just returns false --- testsuite/gateway/gateway_api/gateway.py | 9 +++------ testsuite/openshift/__init__.py | 8 +++++--- testsuite/openshift/authorino.py | 15 +++++++-------- testsuite/openshift/deployment.py | 7 ++----- testsuite/openshift/ingress.py | 6 ++---- testsuite/openshift/kuadrant.py | 15 +++++++-------- testsuite/policy/__init__.py | 10 ++-------- testsuite/policy/authorization/auth_config.py | 15 ++++++--------- testsuite/policy/rate_limit_policy.py | 11 ++--------- testsuite/policy/tls_policy.py | 10 ++-------- 10 files changed, 38 insertions(+), 68 deletions(-) diff --git a/testsuite/gateway/gateway_api/gateway.py b/testsuite/gateway/gateway_api/gateway.py index 81795c0f..ccb71ce8 100644 --- a/testsuite/gateway/gateway_api/gateway.py +++ b/testsuite/gateway/gateway_api/gateway.py @@ -76,12 +76,9 @@ def is_ready(self): def wait_for_ready(self, timeout: int = 10 * 60): """Waits for the gateway to be ready in the sense of is_ready(self)""" - with oc.timeout(timeout): - success, _, _ = self.self_selector().until_all( - success_func=lambda obj: self.__class__(obj.model).is_ready() - ) - assert success, "Gateway didn't get ready in time" - self.refresh() + success = self.wait_until(lambda obj: self.__class__(obj.model).is_ready(), timelimit=timeout) + assert success, "Gateway didn't get ready in time" + self.refresh() def is_affected_by(self, policy: Policy) -> bool: """Returns True, if affected by status is found within the object for the specific policy""" diff --git a/testsuite/openshift/__init__.py b/testsuite/openshift/__init__.py index f8476e77..f5a3585c 100644 --- a/testsuite/openshift/__init__.py +++ b/testsuite/openshift/__init__.py @@ -34,7 +34,7 @@ def delete(self, ignore_not_found=True, cmd_args=None): self.committed = False return deleted - def wait_until(self, test_function, timelimit=90): + def wait_until(self, test_function, timelimit=60): """Waits until the test function succeeds for this object""" try: with timeout(timelimit): @@ -42,8 +42,10 @@ def wait_until(self, test_function, timelimit=90): success_func=lambda obj: test_function(self.__class__(obj.model)) ) return success - except OpenShiftPythonException: - return False + except OpenShiftPythonException as e: + if "Timeout" in e: + return False + raise e class CustomResource(OpenShiftObject): diff --git a/testsuite/openshift/authorino.py b/testsuite/openshift/authorino.py index 71538837..6810209d 100644 --- a/testsuite/openshift/authorino.py +++ b/testsuite/openshift/authorino.py @@ -4,7 +4,7 @@ from dataclasses import dataclass from typing import Any, Optional, Dict, List -from openshift_client import selector, timeout +from openshift_client import selector from testsuite.lifecycle import LifecycleObject from testsuite.openshift import CustomResource @@ -88,13 +88,12 @@ def create_instance( def wait_for_ready(self): """Waits until Authorino CR reports ready status""" - with timeout(90): - success, _, _ = self.self_selector().until_all( - success_func=lambda obj: len(obj.model.status.conditions) > 0 - and all(x.status == "True" for x in obj.model.status.conditions) - ) - assert success, "Authorino did got get ready in time" - self.refresh() + success = self.wait_until( + lambda obj: len(obj.model.status.conditions) > 0 + and all(x.status == "True" for x in obj.model.status.conditions) + ) + assert success, "Authorino did got get ready in time" + self.refresh() @property def deployment(self): diff --git a/testsuite/openshift/deployment.py b/testsuite/openshift/deployment.py index a60a953b..45fca025 100644 --- a/testsuite/openshift/deployment.py +++ b/testsuite/openshift/deployment.py @@ -3,8 +3,6 @@ from dataclasses import dataclass from typing import Any, Optional -import openshift_client as oc - from testsuite.openshift import OpenShiftObject, Selector, modify from testsuite.utils import asdict @@ -148,9 +146,8 @@ def create_instance( def wait_for_ready(self, timeout=90): """Waits until Deployment is marked as ready""" - with oc.timeout(timeout): - success, _, _ = self.self_selector().until_all(success_func=lambda obj: "readyReplicas" in obj.model.status) - assert success, f"Deployment {self.name()} did not get ready in time" + success = self.wait_until(lambda obj: "readyReplicas" in obj.model.status, timelimit=timeout) + assert success, f"Deployment {self.name()} did not get ready in time" @property def template(self): diff --git a/testsuite/openshift/ingress.py b/testsuite/openshift/ingress.py index f6c708cb..8bda3810 100644 --- a/testsuite/openshift/ingress.py +++ b/testsuite/openshift/ingress.py @@ -66,14 +66,12 @@ def rules(self): """Returns rules defined in the ingress""" return self.model.spec.rules - def wait_for_hosts(self, tolerate_failures: int = 5): + def wait_for_hosts(self): """Waits until all rules within the ingress have host fields filled""" def _all_rules_have_host(obj): return all("host" in r and len(r.get("host")) > 0 for r in obj.model.spec.rules) - success, _, _ = self.self_selector().until_all( - success_func=_all_rules_have_host, tolerate_failures=tolerate_failures - ) + success = self.wait_until(_all_rules_have_host) return success diff --git a/testsuite/openshift/kuadrant.py b/testsuite/openshift/kuadrant.py index 8230e6fc..b91e74c2 100644 --- a/testsuite/openshift/kuadrant.py +++ b/testsuite/openshift/kuadrant.py @@ -2,7 +2,7 @@ import dataclasses -from openshift_client import selector, timeout +from openshift_client import selector from testsuite.openshift import CustomResource from testsuite.openshift.deployment import Deployment @@ -60,10 +60,9 @@ def limitador_deployment(self): def wait_for_ready(self): """Waits until Kuadrant CR reports ready status""" - with timeout(90): - success, _, _ = self.self_selector().until_all( - success_func=lambda obj: len(obj.model.status.conditions) > 0 - and all(x.status == "True" for x in obj.model.status.conditions) - ) - assert success, "Kuadrant did got get ready in time" - self.refresh() + success = self.wait_until( + lambda obj: len(obj.model.status.conditions) > 0 + and all(x.status == "True" for x in obj.model.status.conditions) + ) + assert success, "Kuadrant did got get ready in time" + self.refresh() diff --git a/testsuite/policy/__init__.py b/testsuite/policy/__init__.py index 49786898..cfff3974 100644 --- a/testsuite/policy/__init__.py +++ b/testsuite/policy/__init__.py @@ -1,7 +1,5 @@ """Contains Base class for policies""" -import openshift_client as oc - from testsuite.openshift import OpenShiftObject from testsuite.utils import has_condition @@ -11,9 +9,5 @@ class Policy(OpenShiftObject): def wait_for_ready(self): """Wait for a Policy to be Enforced""" - 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" + success = self.wait_until(has_condition("Enforced", "True")) + assert success, f"{self.kind()} did not get ready in time" diff --git a/testsuite/policy/authorization/auth_config.py b/testsuite/policy/authorization/auth_config.py index f8b67530..bff32dbf 100644 --- a/testsuite/policy/authorization/auth_config.py +++ b/testsuite/policy/authorization/auth_config.py @@ -3,8 +3,6 @@ from functools import cached_property from typing import Dict -import openshift_client as oc - from testsuite.utils import asdict from testsuite.openshift import OpenShiftObject, modify from testsuite.openshift.client import OpenShiftClient @@ -76,13 +74,12 @@ def remove_all_hosts(self): def wait_for_ready(self): """Waits until authorization object reports ready status""" - with oc.timeout(90): - success, _, _ = self.self_selector().until_all( - success_func=lambda obj: len(obj.model.status.conditions) > 0 - and all(x.status == "True" for x in obj.model.status.conditions) - ) - assert success, f"{self.kind()} did not get ready in time" - self.refresh() + success = self.wait_until( + lambda obj: len(obj.model.status.conditions) > 0 + and all(x.status == "True" for x in obj.model.status.conditions) + ) + assert success, f"{self.kind()} did not get ready in time" + self.refresh() @modify def add_rule(self, when: list[Rule]): diff --git a/testsuite/policy/rate_limit_policy.py b/testsuite/policy/rate_limit_policy.py index 37abaa47..99a37e92 100644 --- a/testsuite/policy/rate_limit_policy.py +++ b/testsuite/policy/rate_limit_policy.py @@ -4,14 +4,12 @@ from dataclasses import dataclass from typing import Iterable, Literal, Optional, List -from openshift_client import timeout - from testsuite.gateway import Referencable, RouteMatch from testsuite.openshift import modify from testsuite.openshift.client import OpenShiftClient from testsuite.policy import Policy from testsuite.policy.authorization import Rule -from testsuite.utils import asdict, has_condition +from testsuite.utils import asdict @dataclass @@ -81,11 +79,6 @@ def add_limit( def wait_for_ready(self): """Wait for RLP to be enforced""" - with 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" + super().wait_for_ready() # Even after enforced condition RLP requires a short sleep time.sleep(5) diff --git a/testsuite/policy/tls_policy.py b/testsuite/policy/tls_policy.py index e72b3e41..ba0e5529 100644 --- a/testsuite/policy/tls_policy.py +++ b/testsuite/policy/tls_policy.py @@ -1,7 +1,5 @@ """Module for TLSPolicy related classes""" -import openshift_client as oc - from testsuite.gateway import Referencable from testsuite.openshift.client import OpenShiftClient from testsuite.policy import Policy @@ -55,9 +53,5 @@ def __getitem__(self, key): def wait_for_ready(self): """TLSPolicy does not have Enforced https://github.com/Kuadrant/kuadrant-operator/issues/572""" - with oc.timeout(90): - success, _, _ = self.self_selector().until_all( - success_func=has_condition("Accepted", "True"), - tolerate_failures=5, - ) - assert success, f"{self.kind()} did not get ready in time" + success = self.wait_until(has_condition("Accepted", "True")) + assert success, f"{self.kind()} did not get ready in time"