From dc59c6dbcc106e2a5a735d10f7a44a7c481519e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C4=8C=C3=A1p?= Date: Tue, 25 Oct 2022 17:47:29 +0200 Subject: [PATCH 1/4] add service and port properties to httpbin --- testsuite/openshift/httpbin.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/testsuite/openshift/httpbin.py b/testsuite/openshift/httpbin.py index 5fb7a19e..7d39dca8 100644 --- a/testsuite/openshift/httpbin.py +++ b/testsuite/openshift/httpbin.py @@ -1,4 +1,5 @@ """Module for Httpbin backend classes""" +from functools import cached_property from importlib import resources from testsuite.objects import LifecycleObject @@ -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") From 04f8db2286f1a6c2f8128041d7bd1a330fb0887b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C4=8C=C3=A1p?= Date: Tue, 25 Oct 2022 17:44:49 +0200 Subject: [PATCH 2/4] make ingress able to wait for hosts to appear --- testsuite/openshift/objects/ingress.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/testsuite/openshift/objects/ingress.py b/testsuite/openshift/objects/ingress.py index 1907d5e0..a639cb90 100644 --- a/testsuite/openshift/objects/ingress.py +++ b/testsuite/openshift/objects/ingress.py @@ -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 From 1165596c1b5295249980815ac03186cd7166f23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C4=8C=C3=A1p?= Date: Wed, 26 Oct 2022 15:00:17 +0200 Subject: [PATCH 3/4] glbc: add make target for glbc tests --- Makefile | 6 +++++- pytest.ini | 1 + testsuite/tests/conftest.py | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 74c9864e..3d9ceeca 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/pytest.ini b/pytest.ini index 250f2c7a..8c362968 100644 --- a/pytest.ini +++ b/pytest.ini @@ -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 diff --git a/testsuite/tests/conftest.py b/testsuite/tests/conftest.py index 32fab04e..e35a10d9 100644 --- a/testsuite/tests/conftest.py +++ b/testsuite/tests/conftest.py @@ -18,9 +18,11 @@ 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): @@ -28,6 +30,8 @@ def pytest_runtest_setup(item): 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) From dd3d82d7eda06ab79faf1e5d14d1860e01f58721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C4=8C=C3=A1p?= Date: Fri, 7 Oct 2022 12:14:36 +0200 Subject: [PATCH 4/4] glbc: add simple ingress host field reconciliation test --- testsuite/tests/glbc/__init__.py | 0 testsuite/tests/glbc/conftest.py | 13 ++++++ .../tests/glbc/test_ingress_reconciliation.py | 46 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 testsuite/tests/glbc/__init__.py create mode 100644 testsuite/tests/glbc/conftest.py create mode 100644 testsuite/tests/glbc/test_ingress_reconciliation.py diff --git a/testsuite/tests/glbc/__init__.py b/testsuite/tests/glbc/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/tests/glbc/conftest.py b/testsuite/tests/glbc/conftest.py new file mode 100644 index 00000000..b6a089ee --- /dev/null +++ b/testsuite/tests/glbc/conftest.py @@ -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 diff --git a/testsuite/tests/glbc/test_ingress_reconciliation.py b/testsuite/tests/glbc/test_ingress_reconciliation.py new file mode 100644 index 00000000..2209d1bc --- /dev/null +++ b/testsuite/tests/glbc/test_ingress_reconciliation.py @@ -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