Skip to content

Commit

Permalink
Introduce Capabilities
Browse files Browse the repository at this point in the history
- Rename gateway_api option to standalone
  • Loading branch information
pehala committed Feb 7, 2024
1 parent efb12b9 commit 7b881f9
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/settings.local.yaml.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#default:
# skip_cleanup: false
# tester: "someuser" # Optional: name of the user, who is running the tests, defaults to whoami/uid
# gateway_api: true # True, if Testsuite should test with Gateway API enabled (e.g. Full Kuadrant) or individual components (e.g. Authorino)
# standalone: false # True, if Testsuite should test only individual components (e.g. Authorino/limitador operators)
# cluster: # Workload cluster where tests should run, will get overriden if run on Multicluster
# project: "kuadrant" # Optional: Default namespace for this cluster
# api_url: "https://api.openshift.com" # Optional: OpenShift API URL, if None it will OpenShift that you are logged in
Expand Down
2 changes: 1 addition & 1 deletion config/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default:
skip_cleanup: false
dynaconf_merge: true
gateway_api: true
standalone: false
cluster: {}
tools:
project: "tools"
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ line-length = 120
markers = [
"issue: Reference to covered issue",
"performance: Performance tests have unique needs",
"mgc: MGC tests have specific needs"
"mgc: Test is using MGC specific features",
"authorino: Test is using Authorino features",
"standalone_only: Test is using features available only in standalone mode, without Kuadrant",
"kuadrant_only: Test is using features available only in Kuadrant mode",
"limitador: Test is using Limitador features",
]
filterwarnings = [
"ignore: WARNING the new order is not taken into account:UserWarning",
Expand Down
56 changes: 56 additions & 0 deletions testsuite/capabilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Contains capability related classes"""

import functools

from weakget import weakget

from testsuite.config import settings


@functools.cache
def has_kuadrant():
"""Returns True, if Kuadrant deployment is present and should be used"""
spokes = weakget(settings)["control_plane"]["spokes"] % {}

if not settings.get("standalone", False):
return False, "Standalone mode is enabled"

for name, openshift in spokes.items():
# Try if Kuadrant is deployed
if not openshift.connected:
return False, f"Spoke {name} is not connected"
project = settings["service_protection"]["system_project"]
kuadrant_openshift = openshift.change_project(project)
kuadrants = kuadrant_openshift.do_action("get", "kuadrant", "-o", "json", parse_output=True)
if len(kuadrants.model["items"]) == 0:
return False, f"Spoke {name} does not have Kuadrant resource in project {project}"

return True, None


@functools.cache
def is_standalone():
"""Return True, if the testsuite is configured to run with envoy in standalone mode, without Gateway API"""
if settings.get("standalone", False):
return False, "Standalone mode is disabled"
return True, None


@functools.cache
def has_mgc():
"""Returns True, if MGC is configured and deployed"""
spokes = weakget(settings)["control_plane"]["spokes"] % {}

if not settings.get("standalone", False):
return False, "Standalone mode is enabled"

if len(spokes) == 0:
return False, "Spokes are not configured"

hub_openshift = settings["control_plane"]["hub"]
if not hub_openshift.connected:
return False, "Control Plane Hub Openshift is not connected"

if "managedzones" not in hub_openshift.do_action("api-resources", "--api-group=kuadrant.io").out():
return False, "MGC custom resources are missing on hub cluster"
return True, None
2 changes: 1 addition & 1 deletion testsuite/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, name, default, **kwargs) -> None:
DefaultValueValidator("rhsso.url", default=fetch_route("no-ssl-sso")),
DefaultValueValidator("rhsso.password", default=fetch_secret("credential-sso", "ADMIN_PASSWORD")),
DefaultValueValidator("mockserver.url", default=fetch_route("mockserver", force_http=True)),
Validator("gateway_api", must_exist=False, eq=False)
Validator("standalone", must_exist=False, eq=True)
| Validator("service_protection.gateway.name", must_exist=True),
],
validate_only=["authorino", "kuadrant"],
Expand Down
20 changes: 16 additions & 4 deletions testsuite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dynaconf import ValidationError
from keycloak import KeycloakAuthenticationError

from testsuite.capabilities import has_kuadrant, has_mgc, is_standalone
from testsuite.certificates import CFSSLClient
from testsuite.config import settings
from testsuite.mockserver import Mockserver
Expand All @@ -28,16 +29,27 @@ def pytest_addoption(parser):
parser.addoption(
"--performance", action="store_true", default=False, help="Run also performance tests (default: False)"
)
parser.addoption("--mgc", action="store_true", default=False, help="Run also mgc tests (default: False)")
parser.addoption("--enforce", action="store_true", default=False, help="Fails tests instead of skip")


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 "mgc" in marks and not item.config.getoption("--mgc"):
pytest.skip("Excluding MGC tests")
skip_func = pytest.fail if item.config.getoption("--enforce") else pytest.skip
if "kuadrant_only" in marks:
kuadrant, error = has_kuadrant()
if not kuadrant:
skip_func(f"Unable to locate Kuadrant installation: {error}")
if "standalone_only" in marks:
status, error = is_standalone()
if not status:
skip_func(f"Unable to run Standalone tests: {error}")
if "mgc" in marks:
mgc, error = has_mgc()
if not mgc:
skip_func(f"Unable to locate MGC installation: {error}")


@pytest.hookimpl(hookwrapper=True)
Expand Down Expand Up @@ -220,7 +232,7 @@ def module_label(label):
@pytest.fixture(scope="module")
def kuadrant(testconfig, openshift):
"""Returns Kuadrant instance if exists, or None"""
if not testconfig.get("gateway_api", True):
if not testconfig.get("standalone", False):
return None

# Try if Kuadrant is deployed
Expand Down

0 comments on commit 7b881f9

Please sign in to comment.