Skip to content

Commit c884e64

Browse files
committed
Refactor zync capabilities
1 parent 639b2da commit c884e64

12 files changed

Lines changed: 76 additions & 40 deletions

File tree

doc/GATEWAYS.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* `STANDARD_GATEWAY`: Default gateway deployed by 3scale, which means tests that deploy their own APIcast can run.
88
* `LOGS`: Allows getting APIcast logs through `get_logs()` method
99
* `JAEGER`: Allows configuring the APIcast to send data to Jaeger through `connect_jaeger()` method
10-
* `ZYNC`: Zync is enabled in the 3scale deployment. Determined by the gateway type — absent when `ZyncLessApicast` is used. Tests that rely on zync functionality (route creation, OAuth client sync) require this capability.
11-
* `SSO`: RHSSO/RHBK is configured and zync is enabled (`ZYNC` capability is present and RHSSO password is set in config). Tests using OIDC/OAuth authentication require this capability.
10+
* `ZYNC_ROUTES`: Zync creates OCP routes for APIcast endpoints. Absent when `ZyncLessApicast` is used or `threescale.zync_routes_disabled: true` is set.
11+
* `ZYNC_OIDC_SYNC`: Zync is running and syncs OIDC clients with RHSSO/RHBK. Absent only when `ZyncLessApicast` is used (zync completely disabled).
1212

1313

1414
# Gateway type configuration
@@ -22,19 +22,34 @@ gateway:
2222
kind: "SystemApicast"
2323
```
2424
## ZyncLess APIcast
25-
*Description*: Variant of System APIcast for 3scale deployments where zync is disabled. Since zync is not available
26-
to create OCP routes for APIcast endpoints, this gateway creates and manages them via lifecycle hooks.
27-
Requires `spec/zync/enabled: false` in the APIManager CR — will raise an error at startup if zync is enabled.
25+
*Description*: Variant of System APIcast for 3scale deployments where zync is completely disabled. Since zync is not
26+
available to create OCP routes for APIcast endpoints, this gateway creates and manages them via lifecycle hooks.
27+
Requires `spec/zync/enabled: false` in the APIManager CR — capability provider raises an error if zync is enabled.
2828
Note: when using this gateway, OCP routes for the 3scale admin portal, master, and developer portal must be
2929
created manually as zync is also responsible for those.
3030

3131
*Capabilities*: "APICAST, CUSTOM_ENVIRONMENT, PRODUCTION_GATEWAY, SAME_CLUSTER, LOGS, JAEGER, STANDARD_GATEWAY"
32-
(no `ZYNC` or `SSO` capability — RHSSO/OIDC tests are automatically skipped)
32+
(no `ZYNC_ROUTES` or `ZYNC_OIDC_SYNC` — all zync-dependent tests are automatically skipped)
3333
```
3434
gateway:
3535
default:
3636
kind: "ZyncLessApicast"
3737
```
38+
39+
## System APIcast with zync routes disabled
40+
*Description*: Standard System APIcast for 3scale deployments where zync is running but not creating OCP routes
41+
(e.g. when routes are managed externally). Set `threescale.zync_routes_disabled: true` in config.
42+
Capability provider raises an error at startup if this config does not match the actual gateway type.
43+
44+
*Capabilities*: "APICAST, CUSTOM_ENVIRONMENT, PRODUCTION_GATEWAY, SAME_CLUSTER, LOGS, JAEGER, STANDARD_GATEWAY, ZYNC_OIDC_SYNC"
45+
(no `ZYNC_ROUTES` — route creation tests are automatically skipped)
46+
```
47+
threescale:
48+
zync_routes_disabled: true
49+
gateway:
50+
default:
51+
kind: "SystemApicast"
52+
```
3853
## Container APIcast
3954
*Description*: Similar to Self-managed APIcast (at least for now), used for interop testing.
4055
Expects gateway deployed remotely without any access to it.

testsuite/capabilities/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Capability(enum.Enum):
3232
SCALING = "scaling" # If the current environment supports scaling of components
3333
FIPS = "fips"
3434
NOFIPS = "no-fips"
35-
ZYNC = "zync" # Zync is enabled (gateway is not ZyncLessApicast)
36-
SSO = "sso" # RHSSO/RHBK is configured and zync is enabled
35+
ZYNC_ROUTES = "zync-routes" # Zync creates OCP routes for APIcast endpoints
36+
ZYNC_OIDC_SYNC = "zync-oidc-sync" # Zync syncs OIDC clients with RHSSO/RHBK
3737
# fmt: on
3838

3939

testsuite/capabilities/providers.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""This module is where most of the capability providers should be to not have them scattered around"""
22

3+
from openshift_client import Missing
34
from weakget import weakget
45

56
from testsuite import gateways
@@ -67,25 +68,36 @@ def fips():
6768
CapabilityRegistry().register_provider(fips, {Capability.NOFIPS, Capability.FIPS})
6869

6970

70-
def zync():
71-
"""Zync is available when the gateway is not ZyncLessApicast,
72-
unless zync_routes_disabled is set (zync runs but doesn't create routes)"""
73-
if issubclass(gateways.default, ZyncLessApicast):
74-
if not weakget(settings)["threescale"]["gateway"]["default"]["zync_routes_disabled"] % False:
75-
return {}
76-
return {Capability.ZYNC}
77-
71+
def zync_capabilities():
72+
"""Determines zync capabilities based on gateway type and config.
7873
79-
CapabilityRegistry().register_provider(zync, {Capability.ZYNC})
74+
Case 1 (standard zync): gateway is not ZyncLessApicast and threescale.zync_routes_disabled is not set.
75+
Provides ZYNC_ROUTES + ZYNC_OIDC_SYNC. Fails fast if APIManager has zync disabled.
8076
77+
Case 2 (zync without routes): threescale.zync_routes_disabled: true in config.
78+
Provides only ZYNC_OIDC_SYNC.
8179
82-
def sso():
83-
"""SSO is available when zync is enabled and RHSSO is configured in dynaconf"""
84-
if Capability.ZYNC not in CapabilityRegistry():
85-
return {}
86-
if not weakget(settings)["rhsso"]["password"] % None:
80+
Case 3 (zync disabled): gateway is ZyncLessApicast.
81+
Provides no zync capabilities. Fails fast if APIManager has zync enabled.
82+
"""
83+
if issubclass(gateways.default, ZyncLessApicast):
84+
enabled = openshift().api_manager.get_path("spec/zync/enabled")
85+
if enabled is Missing or enabled:
86+
raise RuntimeError("ZyncLessApicast requires zync to be disabled in APIManager (spec/zync/enabled: false)")
8787
return {}
88-
return {Capability.SSO}
88+
89+
zync_routes_disabled = weakget(settings)["threescale"]["zync_routes_disabled"] % False
90+
91+
if zync_routes_disabled:
92+
return {Capability.ZYNC_OIDC_SYNC}
93+
94+
enabled = openshift().api_manager.get_path("spec/zync/enabled")
95+
if enabled is not Missing and not enabled:
96+
raise RuntimeError(
97+
"Config expects standard zync but APIManager has zync disabled. "
98+
"Use ZyncLessApicast gateway or set threescale.zync_routes_disabled: true."
99+
)
100+
return {Capability.ZYNC_ROUTES, Capability.ZYNC_OIDC_SYNC}
89101

90102

91-
CapabilityRegistry().register_provider(sso, {Capability.SSO})
103+
CapabilityRegistry().register_provider(zync_capabilities, {Capability.ZYNC_ROUTES, Capability.ZYNC_OIDC_SYNC})

testsuite/gateways/apicast/zyncless.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
from typing import TYPE_CHECKING
44
from urllib.parse import urlparse
55

6-
from openshift_client import Missing
76
from threescale_api.resources import Service
87

9-
from testsuite.config import settings
108
from testsuite.gateways.apicast.system import SystemApicast
119
from testsuite.openshift.objects import Routes
1210

@@ -27,13 +25,6 @@ def __init__(self, staging: bool, openshift: "Optional[OpenShiftClient]" = None)
2725
super().__init__(staging, openshift)
2826
self._routes: "List[str]" = []
2927

30-
def create(self):
31-
zync_routes_disabled = settings["threescale"]["gateway"]["default"].get("zync_routes_disabled", False)
32-
if not zync_routes_disabled:
33-
enabled = self.openshift.api_manager.get_path("spec/zync/enabled")
34-
if enabled is Missing or enabled:
35-
raise RuntimeError("ZyncLessApicast requires zync to be disabled in the APIManager spec")
36-
3728
@staticmethod
3829
def _route_name(service: Service, production: bool = False) -> str:
3930
env = "prod" if production else "stage"

testsuite/tests/conftest.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ def pytest_addoption(parser):
9999
parser.addoption("--sso-only", action="store_true", default=False, help="Run only tests that uses RHSSO/RHBK")
100100

101101

102+
def pytest_sessionstart(session: pytest.Session) -> None:
103+
"""Fail fast if zync configuration doesn't match the actual 3scale deployment.
104+
Only runs on the controller process, not on xdist workers."""
105+
if hasattr(session.config, "workerinput"):
106+
return
107+
try:
108+
_ = Capability.ZYNC_ROUTES in CapabilityRegistry()
109+
_ = Capability.ZYNC_OIDC_SYNC in CapabilityRegistry()
110+
except RuntimeError as e:
111+
pytest.exit(f"Zync configuration mismatch: {e}", returncode=3)
112+
113+
102114
def pytest_configure(config: pytest.Config) -> None:
103115
"""Ensure mutually exclusive options"""
104116
fuzz = config.getoption("--fuzz")
@@ -686,8 +698,8 @@ def rhsso_service_info(request, testconfig, tools, rhsso_kind, rhsso_route):
686698
Set up client for zync
687699
:return: dict with all important details
688700
"""
689-
if Capability.SSO not in CapabilityRegistry():
690-
warn_and_skip("SSO capability not available: zync is disabled or RHSSO is not configured")
701+
if Capability.ZYNC_OIDC_SYNC not in CapabilityRegistry():
702+
warn_and_skip("ZYNC_OIDC_SYNC capability not available: zync is disabled or not running")
691703
rhsso = _resolve_rhsso(testconfig, tools, rhsso_route)
692704
if not rhsso:
693705
warn_and_skip("SSO admin password neither discovered not set in config", "fail")

testsuite/tests/custom_tenant/test_custom_tenant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from testsuite.capabilities import Capability
1010
from testsuite.utils import blame
1111

12-
pytestmark = pytest.mark.required_capabilities(Capability.ZYNC)
12+
pytestmark = pytest.mark.required_capabilities(Capability.ZYNC_ROUTES)
1313

1414

1515
@pytest.fixture(scope="session")

testsuite/tests/grafana/test_dashboards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
pytestmark = [
1010
pytest.mark.skipif(TESTED_VERSION < Version("2.9"), reason="TESTED_VERSION < Version('2.9')"),
11-
pytest.mark.required_capabilities(Capability.OCP4, Capability.ZYNC),
11+
pytest.mark.required_capabilities(Capability.OCP4, Capability.ZYNC_OIDC_SYNC),
1212
pytest.mark.issue("https://issues.redhat.com/browse/THREESCALE-7961"),
1313
]
1414

testsuite/tests/system/oidc/test_oidc_rhsso_flows.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
import pytest
1515
from threescale_api.resources import Service
1616

17+
from testsuite.capabilities import Capability
1718
from testsuite.rhsso import OIDCClientAuth
1819
from testsuite.utils import blame_desc
1920

2021
pytestmark = [
2122
pytest.mark.issue("https://issues.jboss.org/browse/THREESCALE-1948"),
2223
pytest.mark.issue("https://issues.jboss.org/browse/THREESCALE-1949"),
2324
pytest.mark.issue("https://issues.jboss.org/browse/THREESCALE-1951"),
25+
pytest.mark.required_capabilities(Capability.ZYNC_OIDC_SYNC),
2426
]
2527

2628

testsuite/tests/system/oidc/test_openid_rhsso_will_delete_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
from keycloak.exceptions import KeycloakGetError
88

99
from testsuite import rawobj
10+
from testsuite.capabilities import Capability
1011
from testsuite.rhsso import OIDCClientAuthHook
1112
from testsuite.utils import randomize
1213

13-
pytestmark = [pytest.mark.nopersistence]
14+
pytestmark = [pytest.mark.nopersistence, pytest.mark.required_capabilities(Capability.ZYNC_OIDC_SYNC)]
1415

1516

1617
@pytest.fixture(scope="module", autouse=True)

testsuite/tests/system/oidc/test_openid_rhsso_zync_sync.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
import pytest
77
from keycloak.exceptions import KeycloakGetError
88

9+
from testsuite.capabilities import Capability
910
from testsuite.rhsso import OIDCClientAuthHook
1011

12+
pytestmark = [pytest.mark.required_capabilities(Capability.ZYNC_OIDC_SYNC)]
13+
1114

1215
@pytest.fixture(scope="module", autouse=True)
1316
def rhsso_setup(lifecycle_hooks, rhsso_service_info):

0 commit comments

Comments
 (0)