Skip to content

Commit

Permalink
Merge pull request Kuadrant#305 from averevki/add-kuadrant-components…
Browse files Browse the repository at this point in the history
…-wait-for-ready

Add kuadrant components wait-for-ready
  • Loading branch information
pehala authored Dec 14, 2023
2 parents b23ef2b + 543ae33 commit c05ddef
Show file tree
Hide file tree
Showing 10 changed files with 28 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 @@ -71,6 +73,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[Pattern] = Non
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()
3 changes: 2 additions & 1 deletion testsuite/tests/kuadrant/authorino/metadata/test_uma.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def auth2(rhsso):


@pytest.fixture(scope="module")
def authorization(authorization, rhsso, client):
def authorization(client_secret, authorization, rhsso, client):
# pylint: disable=unused-argument
"""
Adds UMA resource-level authorization metadata feature and OPA policy that authorize user access to the resource.
Creates two client resources on RHSSO client:
Expand Down
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()
1 change: 1 addition & 0 deletions testsuite/tests/kuadrant/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ def commit(request, 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 c05ddef

Please sign in to comment.