Skip to content

Commit

Permalink
Replace skips with capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
pehala committed Nov 22, 2023
1 parent 9cbe276 commit 9a6196d
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 71 deletions.
65 changes: 45 additions & 20 deletions testsuite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand All @@ -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")
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions testsuite/tests/kuadrant/authorino/dinosaur/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions testsuite/tests/kuadrant/authorino/metrics/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 5 additions & 3 deletions testsuite/tests/kuadrant/authorino/operator/conftest.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions testsuite/tests/kuadrant/authorino/wristband/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
27 changes: 7 additions & 20 deletions testsuite/tests/kuadrant/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,27 +23,27 @@ 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
return None


@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}
)
return None


@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:
Expand Down
10 changes: 5 additions & 5 deletions testsuite/tests/kuadrant/limitador/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions testsuite/tests/kuadrant/test_rate_limit_authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions testsuite/tests/mgc/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from testsuite.openshift.objects.dnspolicy import HealthCheck

pytestmark = [pytest.mark.mgc]


@pytest.fixture(scope="module")
def health_check():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from testsuite.openshift.objects.dnspolicy import HealthCheck

pytestmark = [pytest.mark.mgc]


@pytest.fixture(scope="module")
def health_check():
Expand Down
3 changes: 0 additions & 3 deletions testsuite/tests/mgc/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions testsuite/tests/mgc/tlspolicy/test_cert_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import pytest
from cryptography import x509

pytestmark = [pytest.mark.mgc]


@pytest.fixture(scope="module")
def dns_policy():
Expand Down

0 comments on commit 9a6196d

Please sign in to comment.