From 543ae33243193e65520a5e01170bfc2309e60598 Mon Sep 17 00:00:00 2001 From: averevki Date: Wed, 6 Dec 2023 19:09:06 +0100 Subject: [PATCH] Add wait-for-ready to kuadrant components --- testsuite/policy/authorization/auth_config.py | 12 ++++++++++++ testsuite/policy/rate_limit_policy.py | 19 ++++++++----------- .../authorino/caching/metadata/conftest.py | 7 ------- .../tests/kuadrant/authorino/conftest.py | 1 + .../operator/clusterwide/conftest.py | 1 + .../kuadrant/authorino/wristband/conftest.py | 1 + testsuite/tests/kuadrant/conftest.py | 1 + .../tests/kuadrant/limitador/conftest.py | 1 + .../tests/kuadrant/reconciliation/conftest.py | 1 + 9 files changed, 26 insertions(+), 18 deletions(-) diff --git a/testsuite/policy/authorization/auth_config.py b/testsuite/policy/authorization/auth_config.py index 2a60a47f..b455ceb6 100644 --- a/testsuite/policy/authorization/auth_config.py +++ b/testsuite/policy/authorization/auth_config.py @@ -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 @@ -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""" diff --git a/testsuite/policy/rate_limit_policy.py b/testsuite/policy/rate_limit_policy.py index c72af1f6..556c9bfb 100644 --- a/testsuite/policy/rate_limit_policy.py +++ b/testsuite/policy/rate_limit_policy.py @@ -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 diff --git a/testsuite/tests/kuadrant/authorino/caching/metadata/conftest.py b/testsuite/tests/kuadrant/authorino/caching/metadata/conftest.py index 52f00651..d4460189 100644 --- a/testsuite/tests/kuadrant/authorino/caching/metadata/conftest.py +++ b/testsuite/tests/kuadrant/authorino/caching/metadata/conftest.py @@ -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() diff --git a/testsuite/tests/kuadrant/authorino/conftest.py b/testsuite/tests/kuadrant/authorino/conftest.py index 2fe8b8ab..c4b3e6d8 100644 --- a/testsuite/tests/kuadrant/authorino/conftest.py +++ b/testsuite/tests/kuadrant/authorino/conftest.py @@ -86,3 +86,4 @@ def commit(request, authorization): """Commits all important stuff before tests""" request.addfinalizer(authorization.delete) authorization.commit() + authorization.wait_for_ready() diff --git a/testsuite/tests/kuadrant/authorino/operator/clusterwide/conftest.py b/testsuite/tests/kuadrant/authorino/operator/clusterwide/conftest.py index b9244fa0..ca13b3bc 100644 --- a/testsuite/tests/kuadrant/authorino/operator/clusterwide/conftest.py +++ b/testsuite/tests/kuadrant/authorino/operator/clusterwide/conftest.py @@ -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() diff --git a/testsuite/tests/kuadrant/authorino/wristband/conftest.py b/testsuite/tests/kuadrant/authorino/wristband/conftest.py index 46aedeeb..83df8e61 100644 --- a/testsuite/tests/kuadrant/authorino/wristband/conftest.py +++ b/testsuite/tests/kuadrant/authorino/wristband/conftest.py @@ -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() diff --git a/testsuite/tests/kuadrant/conftest.py b/testsuite/tests/kuadrant/conftest.py index 0fc07c0e..4310c5dc 100644 --- a/testsuite/tests/kuadrant/conftest.py +++ b/testsuite/tests/kuadrant/conftest.py @@ -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() diff --git a/testsuite/tests/kuadrant/limitador/conftest.py b/testsuite/tests/kuadrant/limitador/conftest.py index b4a71237..0b92f1db 100644 --- a/testsuite/tests/kuadrant/limitador/conftest.py +++ b/testsuite/tests/kuadrant/limitador/conftest.py @@ -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() diff --git a/testsuite/tests/kuadrant/reconciliation/conftest.py b/testsuite/tests/kuadrant/reconciliation/conftest.py index 7d219647..dc0932b9 100644 --- a/testsuite/tests/kuadrant/reconciliation/conftest.py +++ b/testsuite/tests/kuadrant/reconciliation/conftest.py @@ -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")