Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve scale gateway listeners test #567

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions testsuite/kuadrant/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ def _check(obj):
return _check


def is_affected_by(policy: "Policy"):
"""Returns function, that returns True if the Kubernetes object has 'affected by policy' condition"""

def _check(obj):
for condition in obj.model.status.conditions:
if check_condition(
condition,
f"kuadrant.io/{policy.kind(lowercase=False)}Affected",
"True",
"Accepted",
f"Object affected by {policy.kind(lowercase=False)} {policy.namespace()}/{policy.name()}",
):
return True
return False

return _check


class Policy(KubernetesObject):
"""Base class with common functionality for all policies"""

Expand Down
23 changes: 11 additions & 12 deletions testsuite/tests/singlecluster/gateway/test_scale_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from testsuite.httpx import KuadrantClient
from testsuite.gateway.gateway_api.route import HTTPRoute
from testsuite.gateway.gateway_api.gateway import KuadrantGateway, GatewayListener
from testsuite.kuadrant.policy import is_affected_by
from testsuite.kuadrant.policy.dns import DNSPolicy

pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy]
Expand All @@ -16,8 +17,7 @@
def gateway(request, cluster, blame, base_domain, module_label):
"""Create first gateway with 64 listeners"""
gw = KuadrantGateway.create_instance(cluster, blame("gw"), {"app": module_label})
gw.add_listener(GatewayListener(hostname=f"gw1-api.{base_domain}"))
for i in range(1, MAX_GATEWAY_LISTENERS):
for i in range(1, MAX_GATEWAY_LISTENERS + 1):
gw.add_listener(GatewayListener(name=f"api{i}", hostname=f"gw1-api{i}.{base_domain}"))
request.addfinalizer(gw.delete)
gw.commit()
Expand All @@ -29,8 +29,7 @@ def gateway(request, cluster, blame, base_domain, module_label):
def gateway2(request, cluster, blame, base_domain, module_label):
"""Create second gateway with 64 listeners"""
gw = KuadrantGateway.create_instance(cluster, blame("gw"), {"app": module_label})
gw.add_listener(GatewayListener(hostname=f"gw2-api.{base_domain}"))
for i in range(1, MAX_GATEWAY_LISTENERS):
for i in range(1, MAX_GATEWAY_LISTENERS + 1):
gw.add_listener(GatewayListener(name=f"api{i}", hostname=f"gw2-api{i}.{base_domain}"))
request.addfinalizer(gw.delete)
gw.commit()
Expand Down Expand Up @@ -68,11 +67,11 @@ def commit(request, routes, dns_policy, dns_policy2): # pylint: disable=unused-

def test_gateway_max_listeners(gateway, gateway2, dns_policy, dns_policy2, base_domain):
"""Verify that both gateways are affected by DNSPolicy and their listeners are reachable"""
assert gateway.refresh().is_affected_by(dns_policy)
assert gateway2.refresh().is_affected_by(dns_policy2)

assert KuadrantClient(base_url=f"http://gw1-api.{base_domain}").get("/get").response.status_code == 200
assert KuadrantClient(base_url=f"http://gw1-api63.{base_domain}").get("/get").response.status_code == 200

assert KuadrantClient(base_url=f"http://gw2-api21.{base_domain}").get("/get").response.status_code == 200
assert KuadrantClient(base_url=f"http://gw2-api53.{base_domain}").get("/get").response.status_code == 200
assert gateway.wait_until(is_affected_by(dns_policy))
assert gateway2.wait_until(is_affected_by(dns_policy2))

for i in [1, 2]:
for j in range(1, MAX_GATEWAY_LISTENERS + 1):
res = KuadrantClient(base_url=f"http://gw{i}-api{j}.{base_domain}").get("/get").response
assert res is not None
assert res.status_code == 200
Loading