Skip to content

Commit

Permalink
Merge pull request #443 from pehala/timeout_wait_for_ready
Browse files Browse the repository at this point in the history
Improve wait_for_ready timeout errors
  • Loading branch information
pehala committed Jun 19, 2024
2 parents 4335f11 + b33ef5a commit 12023ab
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 59 deletions.
9 changes: 3 additions & 6 deletions testsuite/gateway/gateway_api/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
20 changes: 10 additions & 10 deletions testsuite/openshift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ 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):
success, _, _ = self.self_selector().until_all(
success_func=lambda obj: test_function(self.__class__(obj.model))
)
return success
except OpenShiftPythonException:
return False
except OpenShiftPythonException as e:
if "Timeout" in e.msg:
return False
raise e


class CustomResource(OpenShiftObject):
Expand All @@ -60,13 +62,11 @@ def safe_apply(self):

def wait_for_ready(self):
"""Waits until 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, f"{self.kind()} 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, f"{self.kind()} did got get ready in time"

def __getitem__(self, name):
return self.model.spec[name]
Expand Down
7 changes: 2 additions & 5 deletions testsuite/openshift/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions testsuite/openshift/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 2 additions & 8 deletions testsuite/policy/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
15 changes: 6 additions & 9 deletions testsuite/policy/authorization/auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]):
Expand Down
11 changes: 2 additions & 9 deletions testsuite/policy/rate_limit_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
10 changes: 2 additions & 8 deletions testsuite/policy/tls_policy.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"

0 comments on commit 12023ab

Please sign in to comment.