Skip to content

Commit 755b788

Browse files
authored
Merge pull request #129 from ficap/ingress-test
glbc: add simple ingress host field reconciliation test
2 parents b23f817 + dd3d82d commit 755b788

File tree

8 files changed

+92
-2
lines changed

8 files changed

+92
-2
lines changed

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.PHONY: commit-acceptance pylint mypy clean \
2-
test pipenv pipenv-dev container-image \
2+
test glbc pipenv pipenv-dev container-image \
33

44
TB ?= short
55
LOGLEVEL ?= INFO
@@ -45,6 +45,10 @@ test pytest tests: pipenv
4545
performance: pipenv
4646
$(PYTEST) --performance $(flags) testsuite/tests/kuadrant/authorino/performance
4747

48+
glbc: ## Run glbc tests
49+
glbc: pipenv
50+
$(PYTEST) --glbc $(flags) testsuite/tests/glbc
51+
4852
Pipfile.lock: Pipfile
4953
pipenv lock
5054

pytest.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
markers =
33
issue: Reference to covered issue
44
performance: Performance tests have unique needs
5+
glbc: GLBC tests have specific needs
56
filterwarnings =
67
ignore: WARNING the new order is not taken into account:UserWarning
78
ignore::urllib3.exceptions.InsecureRequestWarning

testsuite/openshift/httpbin.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Module for Httpbin backend classes"""
2+
from functools import cached_property
23
from importlib import resources
34

45
from testsuite.objects import LifecycleObject
@@ -32,3 +33,14 @@ def delete(self):
3233
if self.httpbin_objects:
3334
self.httpbin_objects.delete()
3435
self.httpbin_objects = None
36+
37+
@cached_property
38+
def service(self):
39+
"""Service associated with httpbin"""
40+
with self.openshift.context:
41+
return self.httpbin_objects.narrow("service").object()
42+
43+
@cached_property
44+
def port(self):
45+
"""Service port that httpbin listens on"""
46+
return self.service.model.spec.ports[0].get("port")

testsuite/openshift/objects/ingress.py

+10
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ def create_service_ingress(cls, openshift: 'OpenShiftClient', name, service_name
7272
def rules(self):
7373
"""Returns rules defined in the ingress"""
7474
return self.model.spec.rules
75+
76+
def wait_for_hosts(self, tolerate_failures: int = 5):
77+
"""Waits until all rules within the ingress have host fields filled"""
78+
def _all_rules_have_host(obj):
79+
return all("host" in r and len(r.get("host")) > 0 for r in obj.model.spec.rules)
80+
81+
success, _, _ = self.self_selector().until_all(success_func=_all_rules_have_host,
82+
tolerate_failures=tolerate_failures)
83+
84+
return success

testsuite/tests/conftest.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@
1818

1919

2020
def pytest_addoption(parser):
21-
"""Add option to include performance tests in testrun"""
21+
"""Add options to include various kinds of tests in testrun"""
2222
parser.addoption(
2323
"--performance", action="store_true", default=False, help="Run also performance tests (default: False)")
24+
parser.addoption(
25+
"--glbc", action="store_true", default=False, help="Run also glbc tests (default: False)")
2426

2527

2628
def pytest_runtest_setup(item):
2729
"""Exclude performance tests by default, require explicit option"""
2830
marks = [i.name for i in item.iter_markers()]
2931
if "performance" in marks and not item.config.getoption("--performance"):
3032
pytest.skip("Excluding performance tests")
33+
if "glbc" in marks and not item.config.getoption("--glbc"):
34+
pytest.skip("Excluding glbc tests")
3135

3236

3337
@pytest.fixture(scope='session', autouse=True)

testsuite/tests/glbc/__init__.py

Whitespace-only changes.

testsuite/tests/glbc/conftest.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Root conftest for glbc tests"""
2+
import pytest
3+
4+
from testsuite.openshift.httpbin import Httpbin
5+
6+
7+
@pytest.fixture(scope="session")
8+
def backend(request, kcp, blame, label):
9+
"""Deploys Httpbin backend"""
10+
httpbin = Httpbin(kcp, blame("httpbin"), label)
11+
request.addfinalizer(httpbin.delete)
12+
httpbin.commit()
13+
return httpbin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Basic tests for ingress reconciliation"""
2+
import time
3+
4+
import backoff
5+
import httpx
6+
import pytest
7+
8+
from testsuite.openshift.objects.ingress import Ingress
9+
10+
pytestmark = [pytest.mark.glbc]
11+
12+
13+
@pytest.fixture(scope="module")
14+
def backend_ingress(request, backend, blame):
15+
"""Returns created ingress for given backend"""
16+
service = backend.service
17+
service_name = service.name()
18+
port = backend.port
19+
20+
name = blame("backend-ingress")
21+
22+
ingress = Ingress.create_service_ingress(backend.openshift, name, service_name, port)
23+
request.addfinalizer(ingress.delete)
24+
ingress.commit()
25+
26+
return ingress
27+
28+
29+
@backoff.on_exception(backoff.fibo, exception=httpx.ConnectError, max_time=600)
30+
def test_ingress_host_add(backend_ingress):
31+
"""Creates ingress for a backend and checks for host field filled by glbc, checks host points to backend"""
32+
rules = backend_ingress.rules
33+
assert len(rules) == 1
34+
35+
backend_ingress.wait_for_hosts()
36+
host = rules[0].get("host")
37+
38+
assert host
39+
40+
# needed because of negative dns caching
41+
# once https://github.com/kcp-dev/kcp-glbc/issues/354 is implemented this can be removed and reimplemented
42+
time.sleep(20) # wait until dns record is propagated
43+
44+
response = httpx.get(f"http://{host}")
45+
46+
assert response.status_code == 200

0 commit comments

Comments
 (0)