diff --git a/testsuite/tests/conftest.py b/testsuite/tests/conftest.py index 1c2d5b16..818daa14 100644 --- a/testsuite/tests/conftest.py +++ b/testsuite/tests/conftest.py @@ -20,6 +20,7 @@ from testsuite.openshift.objects.gateway_api.gateway import KuadrantGateway from testsuite.openshift.objects.gateway_api.hostname import OpenShiftExposer from testsuite.openshift.objects.gateway_api.route import HTTPRoute +from testsuite.capabilities import Capability, CapabilityRegistry from testsuite.utils import randomize, _whoami @@ -88,6 +89,40 @@ def pytest_collection_modifyitems(session, config, items): item.user_properties.append(("issue", issue)) +@pytest.fixture(scope="module") +def required_capabilities() -> Capability: + """Returns all required Capabilities for said module""" + return Capability.NONE + + +@pytest.fixture(scope="session") +def available_capabilities() -> Capability: + """Returns all available capabilities for this session""" + return CapabilityRegistry().available + + +@pytest.fixture(scope="module", autouse=True) +def check_capabilities(request, available_capabilities, required_capabilities): + """Skips the tests if the required capabilities are not satisfied""" + cli_requires = [Capability[name] for name in request.config.getoption("--require-capability") or []] + for cap in cli_requires: + if cap not in required_capabilities: + pytest.skip(f"Test was filtered out because {cap} is missing") + + if required_capabilities not in available_capabilities: + missing = (required_capabilities ^ available_capabilities) & required_capabilities + reasons = CapabilityRegistry().missing + error = "\n".join(f"{capability}: {reason}" for capability, reason in reasons.items() if capability in missing) + + pytest.skip( + f""" + This test requires capabilities which are not available: {missing} + Missing capabilities: + {error} + """ + ) + + @pytest.fixture(scope="session") def testconfig(): """Testsuite settings""" @@ -217,22 +252,6 @@ def module_label(label): return randomize(label) -@pytest.fixture(scope="module") -def kuadrant(testconfig, openshift): - """Returns Kuadrant instance if exists, or None""" - if not testconfig.get("gateway_api", True): - return None - - # Try if Kuadrant is deployed - kuadrant_openshift = testconfig["service_protection"]["system_project"] - kuadrants = kuadrant_openshift.do_action("get", "kuadrant", "-o", "json", parse_output=True) - if len(kuadrants.model["items"]) == 0: - pytest.fail("Running Kuadrant tests, but Kuadrant resource was not found") - - # TODO: Return actual Kuadrant object - return True - - @pytest.fixture(scope="module") def backend(request, openshift, blame, label): """Deploys Httpbin backend""" @@ -242,10 +261,16 @@ def backend(request, openshift, blame, label): return httpbin +@pytest.fixture(scope="session") +def has_kuadrant(available_capabilities) -> bool: + """True, if Kuadrant is deployed and configured""" + return Capability.KUADRANT_DEPLOYMENT in available_capabilities + + @pytest.fixture(scope="module") -def gateway(request, kuadrant, openshift, blame, backend, module_label, testconfig, wildcard_domain) -> Gateway: +def gateway(request, has_kuadrant, openshift, blame, backend, module_label, testconfig, wildcard_domain) -> Gateway: """Deploys Envoy that wire up the Backend behind the reverse-proxy and Authorino instance""" - if kuadrant: + if has_kuadrant: gw = KuadrantGateway.create_instance(openshift, blame("gw"), wildcard_domain, {"app": module_label}) else: authorino = request.getfixturevalue("authorino") @@ -262,9 +287,9 @@ def gateway(request, kuadrant, openshift, blame, backend, module_label, testconf @pytest.fixture(scope="module") -def route(request, kuadrant, gateway, blame, hostname, backend, module_label) -> GatewayRoute: +def route(request, has_kuadrant, gateway, blame, hostname, backend, module_label) -> GatewayRoute: """Route object""" - if kuadrant: + if has_kuadrant: route = HTTPRoute.create_instance(gateway.openshift, blame("route"), gateway, {"app": module_label}) else: route = EnvoyVirtualRoute.create_instance(gateway.openshift, blame("route"), gateway) diff --git a/testsuite/tests/kuadrant/authorino/dinosaur/conftest.py b/testsuite/tests/kuadrant/authorino/dinosaur/conftest.py index 95b318c8..6fb9d312 100644 --- a/testsuite/tests/kuadrant/authorino/dinosaur/conftest.py +++ b/testsuite/tests/kuadrant/authorino/dinosaur/conftest.py @@ -8,13 +8,14 @@ from testsuite.httpx.auth import HttpxOidcClientAuth from testsuite.oidc.rhsso import RHSSO from testsuite.openshift.objects.auth_config import AuthConfig +from testsuite.capabilities import Capability from testsuite.utils import ContentType @pytest.fixture(scope="module") -def run_on_kuadrant(): - """We did not implement all the features of this AuthConfig in AuthPolicy""" - return False +def required_capabilities(): + """We depend on templates for this test, so AP is not supported yet""" + return Capability.AUTHORINO_STANDALONE @pytest.fixture(scope="session") diff --git a/testsuite/tests/kuadrant/authorino/metrics/conftest.py b/testsuite/tests/kuadrant/authorino/metrics/conftest.py index bec53a95..56248f0c 100644 --- a/testsuite/tests/kuadrant/authorino/metrics/conftest.py +++ b/testsuite/tests/kuadrant/authorino/metrics/conftest.py @@ -6,12 +6,13 @@ from testsuite.openshift.objects.config_map import ConfigMap from testsuite.openshift.objects.metrics import ServiceMonitor, MetricsEndpoint, Prometheus +from testsuite.capabilities import Capability @pytest.fixture(scope="module") -def run_on_kuadrant(): - """Kuadrant doesn't allow customization of Authorino parameters""" - return False +def required_capabilities(): + """Authorino instance is shared in Kuadrant deployment""" + return Capability.AUTHORINO_STANDALONE @pytest.fixture(scope="module") diff --git a/testsuite/tests/kuadrant/authorino/operator/conftest.py b/testsuite/tests/kuadrant/authorino/operator/conftest.py index f6b423e1..6f1dc1c2 100644 --- a/testsuite/tests/kuadrant/authorino/operator/conftest.py +++ b/testsuite/tests/kuadrant/authorino/operator/conftest.py @@ -1,8 +1,10 @@ """Module containing common features of all Operator tests""" import pytest +from testsuite.capabilities import Capability + @pytest.fixture(scope="module") -def run_on_kuadrant(): - """Kuadrant doesn't allow customization of Authorino parameters""" - return False +def required_capabilities(): + """It is not possible to customize Authorino deployment in Kuadrant""" + return Capability.AUTHORINO_STANDALONE diff --git a/testsuite/tests/kuadrant/authorino/wristband/conftest.py b/testsuite/tests/kuadrant/authorino/wristband/conftest.py index 17399442..10d23223 100644 --- a/testsuite/tests/kuadrant/authorino/wristband/conftest.py +++ b/testsuite/tests/kuadrant/authorino/wristband/conftest.py @@ -8,13 +8,14 @@ from testsuite.openshift.objects.envoy.route import EnvoyVirtualRoute from testsuite.openshift.objects.envoy.wristband import WristbandEnvoy from testsuite.openshift.objects.secret import TLSSecret +from testsuite.capabilities import Capability from testsuite.utils import cert_builder @pytest.fixture(scope="module") -def run_on_kuadrant(): - """Kuadrant doesn't allow customization of Authorino parameters""" - return False +def required_capabilities(): + """Wristband requires special Gateway config""" + return Capability.AUTHORINO_STANDALONE @pytest.fixture(scope="session") diff --git a/testsuite/tests/kuadrant/conftest.py b/testsuite/tests/kuadrant/conftest.py index 0eb5622b..2edacb3b 100644 --- a/testsuite/tests/kuadrant/conftest.py +++ b/testsuite/tests/kuadrant/conftest.py @@ -6,24 +6,11 @@ from testsuite.openshift.objects.rate_limit import RateLimitPolicy -@pytest.fixture(scope="session") -def run_on_kuadrant(): - """True, if the tests should pass when running on Kuadrant""" - return True - - -@pytest.fixture(scope="module", autouse=True) -def skip_no_kuadrant(kuadrant, run_on_kuadrant): - """Skips all tests that are not working with Kuadrant""" - if kuadrant and not run_on_kuadrant: - pytest.skip("This test doesn't work with Kuadrant") - - # pylint: disable=unused-argument @pytest.fixture(scope="module") -def authorino(kuadrant, skip_no_kuadrant): +def authorino(has_kuadrant): """Authorino instance when configured through Kuadrant""" - if kuadrant: + if has_kuadrant: # No available modification return True return None @@ -36,9 +23,9 @@ def authorization_name(blame): @pytest.fixture(scope="module") -def authorization(authorino, kuadrant, oidc_provider, route, authorization_name, openshift, module_label): +def authorization(authorino, has_kuadrant, oidc_provider, route, authorization_name, openshift, module_label): """Authorization object (In case of Kuadrant AuthPolicy)""" - if kuadrant: + if has_kuadrant: policy = AuthPolicy.create_instance(openshift, authorization_name, route, labels={"testRun": module_label}) policy.identity.add_oidc("rhsso", oidc_provider.well_known["issuer"]) return policy @@ -46,9 +33,9 @@ def authorization(authorino, kuadrant, oidc_provider, route, authorization_name, @pytest.fixture(scope="module", params=["route", "gateway"]) -def rate_limit(kuadrant, openshift, blame, request, module_label): +def rate_limit(has_kuadrant, openshift, blame, request, module_label): """Rate limit""" - if kuadrant: + if has_kuadrant: return RateLimitPolicy.create_instance( openshift, blame("limit"), request.getfixturevalue(request.param), labels={"testRun": module_label} ) @@ -56,7 +43,7 @@ def rate_limit(kuadrant, openshift, blame, request, module_label): @pytest.fixture(scope="module", autouse=True) -def commit(request, authorization, rate_limit): +def commit(check_capabilities, request, authorization, rate_limit): """Commits all important stuff before tests""" for component in [authorization, rate_limit]: if component is not None: diff --git a/testsuite/tests/kuadrant/limitador/conftest.py b/testsuite/tests/kuadrant/limitador/conftest.py index b4a71237..b857d117 100644 --- a/testsuite/tests/kuadrant/limitador/conftest.py +++ b/testsuite/tests/kuadrant/limitador/conftest.py @@ -2,13 +2,13 @@ import pytest +from testsuite.capabilities import Capability + @pytest.fixture(scope="module") -def kuadrant(kuadrant): - """Skip if not running on Kuadrant""" - if not kuadrant: - pytest.skip("Limitador test can only run on Kuadrant for now") - return kuadrant +def required_capabilities(): + """Limitador tests can only run on Kuadrant deployment""" + return Capability.KUADRANT_DEPLOYMENT @pytest.fixture(scope="module", autouse=True) diff --git a/testsuite/tests/kuadrant/test_rate_limit_authz.py b/testsuite/tests/kuadrant/test_rate_limit_authz.py index d37de536..6f5ccac5 100644 --- a/testsuite/tests/kuadrant/test_rate_limit_authz.py +++ b/testsuite/tests/kuadrant/test_rate_limit_authz.py @@ -5,14 +5,13 @@ from testsuite.httpx.auth import HttpxOidcClientAuth from testsuite.objects import ValueFrom, JsonResponse from testsuite.openshift.objects.rate_limit import Limit +from testsuite.capabilities import Capability @pytest.fixture(scope="module") -def kuadrant(kuadrant): - """Skip if not running on Kuadrant""" - if not kuadrant: - pytest.skip("Limitador tests can only run on Kuadrant for now") - return kuadrant +def required_capabilities(): + """Limitador tests can only run on Kuadrant deployment""" + return Capability.KUADRANT_DEPLOYMENT @pytest.fixture(scope="module") diff --git a/testsuite/tests/mgc/conftest.py b/testsuite/tests/mgc/conftest.py index c04229bd..ead9cddd 100644 --- a/testsuite/tests/mgc/conftest.py +++ b/testsuite/tests/mgc/conftest.py @@ -10,6 +10,13 @@ from testsuite.openshift.objects.gateway_api.hostname import DNSPolicyExposer from testsuite.openshift.objects.gateway_api.route import HTTPRoute from testsuite.openshift.objects.tlspolicy import TLSPolicy +from testsuite.capabilities import Capability + + +@pytest.fixture(scope="module") +def required_capabilities(): + """All tests in MGC directory require MGC installed""" + return Capability.MGC @pytest.fixture(scope="session") diff --git a/testsuite/tests/mgc/dnspolicy/health_check/test_healthy_endpoint.py b/testsuite/tests/mgc/dnspolicy/health_check/test_healthy_endpoint.py index c8334039..ec495cb8 100644 --- a/testsuite/tests/mgc/dnspolicy/health_check/test_healthy_endpoint.py +++ b/testsuite/tests/mgc/dnspolicy/health_check/test_healthy_endpoint.py @@ -3,8 +3,6 @@ from testsuite.openshift.objects.dnspolicy import HealthCheck -pytestmark = [pytest.mark.mgc] - @pytest.fixture(scope="module") def health_check(): diff --git a/testsuite/tests/mgc/dnspolicy/health_check/test_unhealthy_endpoint.py b/testsuite/tests/mgc/dnspolicy/health_check/test_unhealthy_endpoint.py index 72554ddd..ed5cee83 100644 --- a/testsuite/tests/mgc/dnspolicy/health_check/test_unhealthy_endpoint.py +++ b/testsuite/tests/mgc/dnspolicy/health_check/test_unhealthy_endpoint.py @@ -3,8 +3,6 @@ from testsuite.openshift.objects.dnspolicy import HealthCheck -pytestmark = [pytest.mark.mgc] - @pytest.fixture(scope="module") def health_check(): diff --git a/testsuite/tests/mgc/test_basic.py b/testsuite/tests/mgc/test_basic.py index 926d4e05..bb8ffa8d 100644 --- a/testsuite/tests/mgc/test_basic.py +++ b/testsuite/tests/mgc/test_basic.py @@ -7,9 +7,6 @@ * gateway class "kuadrant-multi-cluster-gateway-instance-per-cluster" is created """ -import pytest - -pytestmark = [pytest.mark.mgc] def test_gateway_readiness(gateway): diff --git a/testsuite/tests/mgc/tlspolicy/test_cert_parameters.py b/testsuite/tests/mgc/tlspolicy/test_cert_parameters.py index 0d633ede..539f42f1 100644 --- a/testsuite/tests/mgc/tlspolicy/test_cert_parameters.py +++ b/testsuite/tests/mgc/tlspolicy/test_cert_parameters.py @@ -4,8 +4,6 @@ import pytest from cryptography import x509 -pytestmark = [pytest.mark.mgc] - @pytest.fixture(scope="module") def dns_policy():