From 18b74eb4a284fcb15295e82b96d83a1d2ed975c7 Mon Sep 17 00:00:00 2001 From: averevki Date: Thu, 2 Nov 2023 14:59:52 +0100 Subject: [PATCH] Add basic tests for DNSPolicy health checks --- testsuite/tests/mgc/dnspolicy/__init__.py | 0 testsuite/tests/mgc/dnspolicy/conftest.py | 28 +++++++++++ .../mgc/dnspolicy/health_check/__init__.py | 0 .../mgc/dnspolicy/health_check/conftest.py | 47 +++++++++++++++++++ .../health_check/test_healthy_endpoint.py | 23 +++++++++ .../health_check/test_unhealthy_endpoint.py | 23 +++++++++ 6 files changed, 121 insertions(+) create mode 100644 testsuite/tests/mgc/dnspolicy/__init__.py create mode 100644 testsuite/tests/mgc/dnspolicy/conftest.py create mode 100644 testsuite/tests/mgc/dnspolicy/health_check/__init__.py create mode 100644 testsuite/tests/mgc/dnspolicy/health_check/conftest.py create mode 100644 testsuite/tests/mgc/dnspolicy/health_check/test_healthy_endpoint.py create mode 100644 testsuite/tests/mgc/dnspolicy/health_check/test_unhealthy_endpoint.py diff --git a/testsuite/tests/mgc/dnspolicy/__init__.py b/testsuite/tests/mgc/dnspolicy/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/tests/mgc/dnspolicy/conftest.py b/testsuite/tests/mgc/dnspolicy/conftest.py new file mode 100644 index 00000000..8d0540db --- /dev/null +++ b/testsuite/tests/mgc/dnspolicy/conftest.py @@ -0,0 +1,28 @@ +"""Conftest for DNSPolicy tests""" +import pytest + +from testsuite.openshift.objects.gateway_api.gateway import MGCGateway + + +@pytest.fixture(scope="module") +def upstream_gateway(request, openshift, blame, hostname, module_label): + """Creates and returns configured and ready upstream Gateway with disabled tls""" + upstream_gateway = MGCGateway.create_instance( + openshift=openshift, + name=blame("mgc-gateway"), + gateway_class="kuadrant-multi-cluster-gateway-instance-per-cluster", + hostname=f"*.{hostname}", + tls=False, + placement="http-gateway", + labels={"app": module_label}, + ) + request.addfinalizer(upstream_gateway.delete) + upstream_gateway.commit() + + return upstream_gateway + + +@pytest.fixture(scope="module") +def tls_policy(): + """Don't need TLSPolicy in the DNSPolicy only tests""" + return None diff --git a/testsuite/tests/mgc/dnspolicy/health_check/__init__.py b/testsuite/tests/mgc/dnspolicy/health_check/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/tests/mgc/dnspolicy/health_check/conftest.py b/testsuite/tests/mgc/dnspolicy/health_check/conftest.py new file mode 100644 index 00000000..e3b5a04d --- /dev/null +++ b/testsuite/tests/mgc/dnspolicy/health_check/conftest.py @@ -0,0 +1,47 @@ +"""Conftest for DNSPolicy health checks""" +import time +import pytest + +from testsuite.openshift.objects.gateway_api.gateway import MGCGateway +from testsuite.openshift.objects.dnspolicy import DNSPolicy + + +@pytest.fixture(scope="module") +def upstream_gateway(request, openshift, blame, module_label, initial_host): + """ + Creates and returns configured and ready upstream Gateway with FQDN hostname + Health checks available only with Fully Qualified Domain Names in gateway (no wildcards are allowed) + """ + upstream_gateway = MGCGateway.create_instance( + openshift=openshift, + name=blame("mgc-gateway"), + gateway_class="kuadrant-multi-cluster-gateway-instance-per-cluster", + hostname=initial_host, + tls=False, + placement="http-gateway", + labels={"app": module_label}, + ) + request.addfinalizer(upstream_gateway.delete) + upstream_gateway.commit() + + return upstream_gateway + + +@pytest.fixture(scope="module") +def dns_policy(blame, upstream_gateway, module_label, health_check): + """DNSPolicy with health check""" + policy = DNSPolicy.create_instance( + upstream_gateway.openshift, + blame("dns"), + upstream_gateway, + healthCheck=health_check, + labels={"app": module_label}, + ) + return policy + + +@pytest.fixture(scope="module") +def dns_health_probe(dns_policy, route): # pylint: disable=unused-argument + """Wait for health check to start monitoring endpoint and return according DNSHealthCheckProbe object""" + time.sleep(10) + return dns_policy.get_dns_health_probe() diff --git a/testsuite/tests/mgc/dnspolicy/health_check/test_healthy_endpoint.py b/testsuite/tests/mgc/dnspolicy/health_check/test_healthy_endpoint.py new file mode 100644 index 00000000..c8334039 --- /dev/null +++ b/testsuite/tests/mgc/dnspolicy/health_check/test_healthy_endpoint.py @@ -0,0 +1,23 @@ +"""Tests for DNSPolicy health checks - healthy endpoint""" +import pytest + +from testsuite.openshift.objects.dnspolicy import HealthCheck + +pytestmark = [pytest.mark.mgc] + + +@pytest.fixture(scope="module") +def health_check(): + """Returns healthy endpoint specification for DNSPolicy health check""" + return HealthCheck( + allowInsecureCertificates=True, + endpoint="/get", + interval="5s", + port=80, + protocol="http", + ) + + +def test_healthy_endpoint(dns_health_probe): + """Test healthy endpoint check""" + assert dns_health_probe.is_healthy() diff --git a/testsuite/tests/mgc/dnspolicy/health_check/test_unhealthy_endpoint.py b/testsuite/tests/mgc/dnspolicy/health_check/test_unhealthy_endpoint.py new file mode 100644 index 00000000..72554ddd --- /dev/null +++ b/testsuite/tests/mgc/dnspolicy/health_check/test_unhealthy_endpoint.py @@ -0,0 +1,23 @@ +"""Tests for DNSPolicy health checks - unhealthy endpoint""" +import pytest + +from testsuite.openshift.objects.dnspolicy import HealthCheck + +pytestmark = [pytest.mark.mgc] + + +@pytest.fixture(scope="module") +def health_check(): + """Returns unhealthy endpoint specification for DNSPolicy health check""" + return HealthCheck( + allowInsecureCertificates=True, + endpoint="/unknown-endpoint", + interval="5s", + port=80, + protocol="http", + ) + + +def test_unhealthy_endpoint(dns_health_probe): + """Test unhealthy endpoint check""" + assert not dns_health_probe.is_healthy()