Skip to content

Commit

Permalink
Merge pull request #129 from ficap/ingress-test
Browse files Browse the repository at this point in the history
glbc: add simple ingress host field reconciliation test
  • Loading branch information
pehala authored Oct 31, 2022
2 parents b23f817 + dd3d82d commit 755b788
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: commit-acceptance pylint mypy clean \
test pipenv pipenv-dev container-image \
test glbc pipenv pipenv-dev container-image \

TB ?= short
LOGLEVEL ?= INFO
Expand Down Expand Up @@ -45,6 +45,10 @@ test pytest tests: pipenv
performance: pipenv
$(PYTEST) --performance $(flags) testsuite/tests/kuadrant/authorino/performance

glbc: ## Run glbc tests
glbc: pipenv
$(PYTEST) --glbc $(flags) testsuite/tests/glbc

Pipfile.lock: Pipfile
pipenv lock

Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
markers =
issue: Reference to covered issue
performance: Performance tests have unique needs
glbc: GLBC tests have specific needs
filterwarnings =
ignore: WARNING the new order is not taken into account:UserWarning
ignore::urllib3.exceptions.InsecureRequestWarning
Expand Down
12 changes: 12 additions & 0 deletions testsuite/openshift/httpbin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for Httpbin backend classes"""
from functools import cached_property
from importlib import resources

from testsuite.objects import LifecycleObject
Expand Down Expand Up @@ -32,3 +33,14 @@ def delete(self):
if self.httpbin_objects:
self.httpbin_objects.delete()
self.httpbin_objects = None

@cached_property
def service(self):
"""Service associated with httpbin"""
with self.openshift.context:
return self.httpbin_objects.narrow("service").object()

@cached_property
def port(self):
"""Service port that httpbin listens on"""
return self.service.model.spec.ports[0].get("port")
10 changes: 10 additions & 0 deletions testsuite/openshift/objects/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ def create_service_ingress(cls, openshift: 'OpenShiftClient', name, service_name
def rules(self):
"""Returns rules defined in the ingress"""
return self.model.spec.rules

def wait_for_hosts(self, tolerate_failures: int = 5):
"""Waits until all rules within the ingress have host fields filled"""
def _all_rules_have_host(obj):
return all("host" in r and len(r.get("host")) > 0 for r in obj.model.spec.rules)

success, _, _ = self.self_selector().until_all(success_func=_all_rules_have_host,
tolerate_failures=tolerate_failures)

return success
6 changes: 5 additions & 1 deletion testsuite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@


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


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


@pytest.fixture(scope='session', autouse=True)
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions testsuite/tests/glbc/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Root conftest for glbc tests"""
import pytest

from testsuite.openshift.httpbin import Httpbin


@pytest.fixture(scope="session")
def backend(request, kcp, blame, label):
"""Deploys Httpbin backend"""
httpbin = Httpbin(kcp, blame("httpbin"), label)
request.addfinalizer(httpbin.delete)
httpbin.commit()
return httpbin
46 changes: 46 additions & 0 deletions testsuite/tests/glbc/test_ingress_reconciliation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Basic tests for ingress reconciliation"""
import time

import backoff
import httpx
import pytest

from testsuite.openshift.objects.ingress import Ingress

pytestmark = [pytest.mark.glbc]


@pytest.fixture(scope="module")
def backend_ingress(request, backend, blame):
"""Returns created ingress for given backend"""
service = backend.service
service_name = service.name()
port = backend.port

name = blame("backend-ingress")

ingress = Ingress.create_service_ingress(backend.openshift, name, service_name, port)
request.addfinalizer(ingress.delete)
ingress.commit()

return ingress


@backoff.on_exception(backoff.fibo, exception=httpx.ConnectError, max_time=600)
def test_ingress_host_add(backend_ingress):
"""Creates ingress for a backend and checks for host field filled by glbc, checks host points to backend"""
rules = backend_ingress.rules
assert len(rules) == 1

backend_ingress.wait_for_hosts()
host = rules[0].get("host")

assert host

# needed because of negative dns caching
# once https://github.com/kcp-dev/kcp-glbc/issues/354 is implemented this can be removed and reimplemented
time.sleep(20) # wait until dns record is propagated

response = httpx.get(f"http://{host}")

assert response.status_code == 200

0 comments on commit 755b788

Please sign in to comment.