Skip to content

Commit

Permalink
Add wait-for-ready to kuadrant components
Browse files Browse the repository at this point in the history
  • Loading branch information
averevki committed Dec 6, 2023
1 parent 42760ce commit 9a7850c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 19 deletions.
12 changes: 12 additions & 0 deletions testsuite/policy/authorization/auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from functools import cached_property
from typing import Dict

import openshift as oc

from testsuite.utils import asdict
from testsuite.openshift import OpenShiftObject, modify
from testsuite.openshift.client import OpenShiftClient
Expand Down Expand Up @@ -70,6 +72,16 @@ def remove_all_hosts(self):
"""Remove all hosts"""
self.model.spec.hosts = []

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()

@modify
def add_rule(self, when: list[Rule]):
"""Add rule for the skip of entire AuthConfig"""
Expand Down
19 changes: 8 additions & 11 deletions testsuite/policy/rate_limit_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,15 @@ def add_limit(self, name, limits: Iterable[Limit], when: Iterable[Rule] = None,
limit["counters"] = counters
self.model.spec.limits[name] = limit

def commit(self):
result = super().commit()

# wait for RLP to be actually applied, conditions itself is not enough, sleep is needed
def _policy_is_ready(obj):
return "conditions" in obj.model.status and obj.model.status.conditions[0].status == "True"

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=_policy_is_ready, tolerate_failures=5)
assert success
success, _, _ = self.self_selector().until_all(
success_func=lambda obj: "conditions" in obj.model.status
and obj.model.status.conditions[0].status == "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)

return result
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,3 @@ def authorization(authorization):
"""Adds `aut.metadata` to the AuthJson"""
authorization.responses.add_simple("auth.metadata")
return authorization


@pytest.fixture(autouse=True)
def commit(request, authorization):
"""Commits all important stuff before tests"""
request.addfinalizer(authorization.delete)
authorization.commit()
1 change: 1 addition & 0 deletions testsuite/tests/kuadrant/authorino/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ def commit(request, authorization):
"""Commits all important stuff before tests"""
request.addfinalizer(authorization.delete)
authorization.commit()
authorization.wait_for_ready()
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ def commit(request, commit, authorization2):
"""Commits all important stuff before tests"""
request.addfinalizer(authorization2.delete)
authorization2.commit()
authorization2.wait_for_ready()
1 change: 1 addition & 0 deletions testsuite/tests/kuadrant/authorino/wristband/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ def commit(request, commit, wristband_authorization):
"""Commits all important stuff before tests"""
request.addfinalizer(wristband_authorization.delete)
wristband_authorization.commit()
wristband_authorization.wait_for_ready()
3 changes: 2 additions & 1 deletion testsuite/tests/kuadrant/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def rate_limit(kuadrant, openshift, blame, request, module_label):

@pytest.fixture(scope="module", autouse=True)
def commit(request, authorization, rate_limit):
"""Commits all important stuff before tests"""
"""Commits all important stuff and wait for the status to be ready before tests"""
for component in [authorization, rate_limit]:
if component is not None:
request.addfinalizer(component.delete)
component.commit()
component.wait_for_ready()
1 change: 1 addition & 0 deletions testsuite/tests/kuadrant/limitador/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ def commit(request, rate_limit):
"""Commits all important stuff before tests"""
request.addfinalizer(rate_limit.delete)
rate_limit.commit()
rate_limit.wait_for_ready()
1 change: 1 addition & 0 deletions testsuite/tests/kuadrant/reconciliation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def commit(request, authorization):
"""Only commit authorization"""
request.addfinalizer(authorization.delete)
authorization.commit()
authorization.wait_for_ready()


@pytest.fixture(scope="module")
Expand Down

0 comments on commit 9a7850c

Please sign in to comment.