Skip to content

Commit

Permalink
Merge pull request #383 from pehala/policy_status
Browse files Browse the repository at this point in the history
Use Enforced condition for ready check
  • Loading branch information
pehala authored Apr 25, 2024
2 parents 4e326de + 885b0c2 commit 5bc3397
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
14 changes: 13 additions & 1 deletion testsuite/policy/authorization/auth_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from typing import Dict, TYPE_CHECKING

from testsuite.utils import asdict
import openshift_client as oc

from testsuite.utils import asdict, has_condition
from testsuite.gateway import Referencable
from testsuite.openshift.client import OpenShiftClient
from testsuite.openshift import modify
Expand Down Expand Up @@ -45,3 +47,13 @@ def add_rule(self, when: list["Rule"]):
"""Add rule for the skip of entire AuthPolicy"""
self.model.spec.setdefault("when", [])
self.model.spec["when"].extend([asdict(x) for x in when])

def wait_for_ready(self):
"""Waits until AuthPolicy object reports ready status"""
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"
self.refresh()
9 changes: 2 additions & 7 deletions testsuite/policy/rate_limit_policy.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""RateLimitPolicy related objects"""

from dataclasses import dataclass
from time import sleep
from typing import Iterable, Literal, Optional, List

import openshift_client as oc

from testsuite.policy.authorization import Rule
from testsuite.utils import asdict
from testsuite.utils import asdict, has_condition
from testsuite.gateway import Referencable, RouteMatch
from testsuite.openshift.client import OpenShiftClient
from testsuite.openshift import OpenShiftObject, modify
Expand Down Expand Up @@ -82,11 +81,7 @@ 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=lambda obj: "conditions" in obj.model.status
and obj.model.status.conditions[0].status == "True",
success_func=has_condition("Enforced", "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)
12 changes: 12 additions & 0 deletions testsuite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,15 @@ def _asdict_recurse(obj):
else:
result[field.name] = deepcopy(value)
return result


def has_condition(condition_type, value="True"):
"""Returns function, that returns True if the Kubernetes object has a specific value"""

def _check(obj):
for condition in obj.model.status.conditions:
if condition.type == condition_type and condition.status == value:
return True
return False

return _check

0 comments on commit 5bc3397

Please sign in to comment.